【问题标题】:Using Protractor 'Expect'使用量角器“期望”
【发布时间】:2019-04-30 21:29:06
【问题描述】:

我有一些按顺序运行的简单规范。第一个具有网页标题的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$ 

【问题讨论】:

  • 您的所有操作都需要在 it 块内。这样browser.get 和您的click 方法不在正确的位置。将它们移动到块内,就在 expect 之前
  • 嗨 - 试过这个但得到异步错误。我可以确认订单吗? 1。描述............ 2。行动....3。 4. 期待

标签: protractor jasmine2.0


【解决方案1】:

您需要将所有操作包装在有效的 Jasmine 块中。

找到an introduction of Jasmine with examples herelatest API description here

作为补充: browser.get() 总是有点难以处理,因为 Protractor 无法知道要加载的页面是否包含 Angular。因此,在页面完全加载之前,测试执行可以继续。

为防止执行过快,请使用ExpectedConditionsbrowser.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');
    });
});

【讨论】:

  • 你永远不应该使用“browser.waitForAngular();”特别是在一个例子中,对于量角器。这具有内置并为每个调用运行的功能。这就是 Protractor 的全部原理。
  • @EdLinac :通常是正确的,但总有一个例外......而browser.get()-trouble 就是这个例外。 Browser.get() 仍然会造成很多麻烦,所以到目前为止最稳定的解决方案是等待新的 URL,然后显式执行browser.watiForAngular()(读取即hereherehere
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-08
  • 1970-01-01
  • 2016-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-25
相关资源
最近更新 更多