使用量角器 'Expect'
Using Protractor 'Expect'
我有一些简单的规格 运行 按顺序排列。第一个对网页标题有一个 expect
断言 - 第二个也是如此。
然而,当我 运行 序列时,第一个断言通过但第二个断言失败并且 console.log 表明第一个规范的 expect
的部分已与第二个规范合并规格 expect
.
我觉得这与 promise 有关...请有人确认这一点(或否认它!!)并建议关闭承诺的方法?
谢谢
第一规格
describe('JL Homepage', function() {
//browser.waitForAngularEnabled(false);
browser.get('https://mwac-johnlewis-dev.digitalbridge.eu/landing');
browser.sleep(10000);
it('should have a title', function(){
expect (browser.getTitle()).toBe('John Lewis Wallpaper Visualiser:
Welcome');
});
});
第二规格
describe('Demo photo', function() {
browser.waitForAngularEnabled(false);
browser.sleep(3000);
element(by.xpath('html/body/webapp-app/div/div/webapp-johnlewis-landing/div/div/ul/li[2]/a/span')).click();
it('should load a demo room', function(){
expect (browser.getTitle()).toEqual('John Lewis Wallpaper Visualiser: Design your room');
browser.sleep(3000);
});
});
控制台
2 specs, 1 failure
Finished in 19.409 seconds
**************************************************
* Failures *
**************************************************
1) Demo photo should load a demo room
- Expected 'John Lewis Wallpaper Visualiser: Welcome' to equal 'John
Lewis Wallpaper Visualiser: Design your room'.
Executed 2 of 2 specs (1 FAILED) in 19 secs.
[12:08:21] I/launcher - 0 instance(s) of WebDriver still running
[12:08:21] I/launcher - chrome #01 failed 1 test(s)
[12:08:21] I/launcher - overall: 1 failed spec(s)
[12:08:21] E/launcher - Process exited with error code 1
Admins-MacBook:jl_autotests davidredmayne$
您需要将所有操作包装在一个有效的 Jasmine 块中。
找到an introduction of Jasmine with examples here and the latest API description here.
另外: browser.get()
总是有点难以处理,因为 Protractor 无法知道要加载的页面是否包含 Angular。因此,在页面完全加载之前,测试执行可以继续。
为防止执行速度过快,请使用ExpectedConditions
and browser.wait()
在这里,我建议第一个规范是:
describe('JL Homepage', function() {
//possibility for beforeAll(), beforeEach(), afterAll(), afterEach()
it('should load the page and have a title', function(){
var EC = protractor.ExpectedConditions;
browser.get('https://mwac-johnlewis-dev.digitalbridge.eu/landing');
//wait until URL has changed
browser.wait(EC.urlIs('https://mwac-johnlewis-dev.digitalbridge.eu/landing'),5000);
//wait until page has finished loading
browser.waitForAngular();
expect (browser.getTitle()).toBe('John Lewis Wallpaper Visualiser: Welcome');
});
});
我有一些简单的规格 运行 按顺序排列。第一个对网页标题有一个 expect
断言 - 第二个也是如此。
然而,当我 运行 序列时,第一个断言通过但第二个断言失败并且 console.log 表明第一个规范的 expect
的部分已与第二个规范合并规格 expect
.
我觉得这与 promise 有关...请有人确认这一点(或否认它!!)并建议关闭承诺的方法?
谢谢
第一规格
describe('JL Homepage', function() {
//browser.waitForAngularEnabled(false);
browser.get('https://mwac-johnlewis-dev.digitalbridge.eu/landing');
browser.sleep(10000);
it('should have a title', function(){
expect (browser.getTitle()).toBe('John Lewis Wallpaper Visualiser:
Welcome');
});
});
第二规格
describe('Demo photo', function() {
browser.waitForAngularEnabled(false);
browser.sleep(3000);
element(by.xpath('html/body/webapp-app/div/div/webapp-johnlewis-landing/div/div/ul/li[2]/a/span')).click();
it('should load a demo room', function(){
expect (browser.getTitle()).toEqual('John Lewis Wallpaper Visualiser: Design your room');
browser.sleep(3000);
});
});
控制台
2 specs, 1 failure
Finished in 19.409 seconds
**************************************************
* Failures *
**************************************************
1) Demo photo should load a demo room
- Expected 'John Lewis Wallpaper Visualiser: Welcome' to equal 'John
Lewis Wallpaper Visualiser: Design your room'.
Executed 2 of 2 specs (1 FAILED) in 19 secs.
[12:08:21] I/launcher - 0 instance(s) of WebDriver still running
[12:08:21] I/launcher - chrome #01 failed 1 test(s)
[12:08:21] I/launcher - overall: 1 failed spec(s)
[12:08:21] E/launcher - Process exited with error code 1
Admins-MacBook:jl_autotests davidredmayne$
您需要将所有操作包装在一个有效的 Jasmine 块中。
找到an introduction of Jasmine with examples here and the latest API description here.
另外: browser.get()
总是有点难以处理,因为 Protractor 无法知道要加载的页面是否包含 Angular。因此,在页面完全加载之前,测试执行可以继续。
为防止执行速度过快,请使用ExpectedConditions
and browser.wait()
在这里,我建议第一个规范是:
describe('JL Homepage', function() {
//possibility for beforeAll(), beforeEach(), afterAll(), afterEach()
it('should load the page and have a title', function(){
var EC = protractor.ExpectedConditions;
browser.get('https://mwac-johnlewis-dev.digitalbridge.eu/landing');
//wait until URL has changed
browser.wait(EC.urlIs('https://mwac-johnlewis-dev.digitalbridge.eu/landing'),5000);
//wait until page has finished loading
browser.waitForAngular();
expect (browser.getTitle()).toBe('John Lewis Wallpaper Visualiser: Welcome');
});
});