我目前正在处理针对 IE 的 Protractor 测试的问题。
我正在使用 Protractor + Jasmine + Node.js
我正在测试的页面部分如下:
<h2 collapser="" class="title text-center text-uppercase active">Tech Specs <i class="plus-icon"></i></h2>
我进行了以下测试:
it('User should be able to see module 11 Tech Specs collapsing and uncolapsing', function () {
basePage.techSpecCollapser.click();
browser.sleep(1000);
expect(basePage.techSpecContainer.isDisplayed()).toBeTruthy();
});
这是控制台输出:
Landing page module verification -->
User should be able to see module 11 Tech Specs collapsing and uncollapsing - fail
1) New Landing page module verification --> User should be able to see module 11 Tech Specs collapsing and uncolapsing
at 15.446s [Thu, 28 May 2015 14:23:08 GMT]
Message:
Expected false to be truthy.
Stacktrace:
Error: Failed expectation
at [object Object].<anonymous> (/Users/test/Documents/Dev/test/sandBox/specs/landing_page_spec.js:44:58)
Finished in 15.448 seconds
1 test, 1 assertion, 1 failure
通过观察测试运行,我发现网页的一部分没有显示。我尝试过:
- 强制滚动到页面的该部分:不起作用。
- 聚焦页面的该部分:不起作用。
有人遇到同样的问题吗?可以让它工作,而且测试非常简单!
最佳答案
您可以尝试通过多种方法来解决该问题:
在运行测试之前最大化浏览器窗口。将其添加到
onPrepare()
中:browser.driver.manage().window().maximize();
删除不可靠的
browser.sleep()
并显式等待元素变得可见visibilityOf
expected condition :var EC = protractor.ExpectedConditions; basePage.techSpecCollapser.click(); browser.wait(EC.visibilityOf(basePage.techSpecContainer), 10000);
移动到元素:
browser.executeScript("arguments[0].scrollIntoView();", basePage.techSpecContainer.getWebElement());
关于javascript - Protractor 测试不适用于 IE,但适用于 FF/Chrome/Safari,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30509744/