我找到了为AngularJS Web应用程序制作的Protractor框架.
如何在不使用AngularJS的网站上使用Protractor?
我写了第一个测试,Protractor触发了这条消息:
Error: Angular could not be found on the page https://www.stratexapp.com/ : retries looking for angular exceeded
Run Code Online (Sandbox Code Playgroud) 我有一些使用protractor for angular.js应用程序编写的测试.我正在使用Page Objects设计模式,我有一些方法可以通过单击链接和按钮导航到其他页面.不久之后我就打电话了browser.waitForAngular().
页面对象
module.exports = function () {
this.companyNameLink = element(by.id('viewCompany'));
this.newMeetingButton = element(by.id('newMeetingButton'));
this.createNewGeneralMeeting = function () {
this.newMeetingButton.click();
browser.waitForAngular();
};
this.goToCompanyPage = function () {
this.companyNameLink.click();
browser.waitForAngular();
};
};
Run Code Online (Sandbox Code Playgroud)
在一些spec文件中,我使用这样的页面对象..
var DashboardPage = require('../dashboardPageObject.js');
dashboardPage = new DashboardPage();
...
dashboardPage.goToCompanyPage();
Run Code Online (Sandbox Code Playgroud)
但问题是有时我得到angular could not be found on the window错误,我的测试失败了.大多数时候测试运行.这个问题是随机的.我的问题是,我应该browser.waitForAngular()从页面对象方法中删除并在我进行方法调用后调用它...
修改了页面对象
...
this.goToCompanyPage = function () {
this.companyNameLink.click();
};
...
Run Code Online (Sandbox Code Playgroud)
规格文件
dashboardPage.goToCompanyPage();
browser.waitForAngular();
Run Code Online (Sandbox Code Playgroud)
呼叫browser.waitForAngular()导致问题?我应该在哪里打电话waitForAngular有关于如何使用它的最佳做法?
我的量角器e2e测试不一致传递和失败.
这似乎可能是由于异步javascript,如下所述: 量角器:如何在单击按钮后等待页面完成?.
但是,这里提到了Protractor测试自动顺序/同步执行:https: //github.com/angular/protractor/issues/909
我的测试脚本:
describe('Login', function() {
var ptor;
beforeEach(function() {
browser.get('https://127.0.0.1:8443');
ptor = protractor.getInstance();
element(by.id('splash')).click();
browser.ignoreSynchronization = true; // <-- to proceed beyond splash screen
});
describe('with correct email and password', function() {
beforeEach(function() {
element(by.id('email')).sendKeys('admin@email.com');
element(by.id('password')).sendKeys('adminpassword');
element(by.id('loginButton')).click();
});
afterEach(function() {
ptor.findElement(by.id('logout')).then(function(elem) {
elem.click();
});
});
it('does not show alert', function() { // <-- sometimes passes, sometimes fails
expect(browser.isElementPresent(by.css('.alert-danger'))).toBe(false);
});
it('changes route to /admin', function() { // <-- sometimes passes, sometimes fails
expect(browser.getCurrentUrl()).toMatch(/\/admin/);
}); …Run Code Online (Sandbox Code Playgroud) 我第一次参加E2E考试.我正在尝试消化别人的量角器测试.
问题:有很多,browser.driver.sleep这似乎很脆弱.
目标:不要使用browser.driver.sleep
问题: 什么是更好的方法browser.driver.sleep?一个不那么脆弱的东西,比如承诺或我不知道的事情大声笑?
var config = require('../../protractor.conf.js').config;
describe('this Homepage Body Tests', function(){
browser.driver.get(config.homepageUrl);
it("should open find a clinic page", function(){
// page loads :: want to fix this random wait interval
browser.driver.sleep(2000);
browser.ignoreSynchronization = true;
var string = 'clinic';
var main = '.search-large-text';
var link = element(by.cssContainingText('.submenu li a', string));
link.click().then(function() {
// page reloads :: want to fix this random wait interval
browser.driver.sleep(3000);
var title = element(by.cssContainingText(main, string));
expect(title.getText()).toBe(string);
}); …Run Code Online (Sandbox Code Playgroud) 测试应用遇到另一个问题.我需要通过精确文本单击元素,所以我找到了一个解决方案,我使用cssContainingText和每个,然后如果声明comapre文本并选择某个元素,但我认为可能是一个更好的解决方案的那个紫色?
第二个问题:在stackoverflow的某个地方,我读到了
element.click().then(){
dosomething;
});
Run Code Online (Sandbox Code Playgroud)
将导致'dosomething;' 将点击后执行,我尝试这个,它不起作用,如何使'dosomething;' 点击后会执行;
由于什么原因,此代码会失败(未找到元素)...
element(by.id('loginButton')).click(); // triggers route change
browser.wait(element(by.tagName('myComponent')).isPresent(), 10000, 'timeout');
element(by.tagName('myComponent')).click();
Run Code Online (Sandbox Code Playgroud)
...虽然这段代码有效?
element(by.id('loginButton')).click(); // triggers route change
const eC = protractor.ExpectedConditions;
browser.wait(eC.visibilityOf(element(by.tagName('myComponent'))), 10000, 'timeout');
element(by.tagName('myComponent')).click();
Run Code Online (Sandbox Code Playgroud)
我正在使用 Angular 5.2.5、Protractor 5.3.0 和 Jasmine 2.8.0。
可能是相关的:我也可以问为什么我需要添加一段browser.wait()时间element(by())应该由量角器自动添加到 ControlFlow 中,但是已经有很多相关问题(这里,这里,那里,那里,...),不幸的是没有明确的答案。
protractor ×6
javascript ×5
angularjs ×3
testing ×2
angular ×1
asp.net ×1
asynchronous ×1
selenium ×1
webdriver ×1