【发布时间】:2017-10-12 18:10:59
【问题描述】:
config.js
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [
'Login.js',
'FeatureList.js',
'NewApplicationRegistration.js',
'ApplicationRegistrationManagement.js',
'RegistrationStatus.js',
],
baseUrl: 'http://localhost:3000',
multiCapabilities: [{
'browserName': 'chrome'
},
// {
// 'browserName': 'firefox'
// },
// {
// 'browserName': 'internet explorer'
// }
],
jasmineNodeOpts: {
onComplete: null,
isVerbose: false,
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 3000000
},
allScriptsTimeout: 11000,
rootElement: 'html',
onPrepare: function () {
browser.ignoreSynchronization = true;
browser.driver.manage().window();
},
};
第一个规范文件
'use strict'
describe('Application Registration Page', function () {
beforeEach(function () {
browser.waitForAngular();
browser.get('/register');
});
// Login
it('Test for Login', function () {
expect(element(by.xpath('/html/body/admin-app-root/layout/div[1]/div/ng-component/div/form/div/table/tbody/tr[1]/th/label')));
var EC = protractor.ExpectedConditions;
var username = element(by.id('login-username'));
browser.wait(EC.visibilityOf(username), 30000);
username.sendKeys('sss');
expect(element(by.xpath('/html/body/admin-app-root/layout/div[1]/div/ng-component/div/form/div/table/tbody/tr[2]/th/label')));
var EC = protractor.ExpectedConditions;
var password = element(by.id('login-password'));
browser.wait(EC.visibilityOf(password), 30000);
password.sendKeys('sss');
browser.driver.sleep(1000);
element(by.xpath('/html/body/admin-app-root/layout/div[1]/div/ng-component/div/form/div/table/tbody/tr[3]/td/button')).click().then(function (username, password) {
if (username, password) {
browser.navigateTo('http://localhost:3000/register/core/feature-list');
} else {
expect(browser.isElementPresent(element(by.xpath('/html/body/admin-app-root/layout/div[1]/div/ng-component/div/form/div/table/tbody/tr[1]/td/b'))));
}
});
});
});
第二规范
'use strict'
describe('Welcome to feature list', function () {
beforeEach(function () {
browser.waitForAngular();
browser.get('/register/core/feature-list');
});
describe('Header', function () {
// Application Registration text
it('Test for Application Registration text', function () {
var EC = protractor.ExpectedConditions;
var ar = element(by.xpath('/html/body/admin-app-root/layout/div[1]/c-header/nav/div/div[1]/a[2]'));
browser.wait(EC.presenceOf(ar), 2000000);
expect(ar.getAttribute('value')).toEqual('Application Registration');
});
it('Test for user name', function () {
var EC = protractor.ExpectedConditions;
var username = element(by.xpath('//*[@id="cox-navbar"]/ul/li[1]/a'));
browser.wait(EC.visibilityOf(username), 2000);
expect(username.isPresent()).toBe(true);
});
});
第一个规范脚本运行良好,但在运行第二个规范时出现错误:
2000000 毫秒后等待超时
即使脚本超时非常大,它也会出错。它无法在给定的时间从浏览器中找到元素。
帮我找到解决办法。
【问题讨论】:
-
您是否尝试过为该元素使用其他选择器?使用那种 xpath 有点糟糕,也许尝试使用 css 类、名称或 id ?
-
@Hikaryu,你我已经尝试了所有的期望,但我得到了同样的错误。但是我看到一件事,在运行第二规范时它只显示第一规范页面,我不确定它是否正在加载第二规范 browser.get 页面。
标签: protractor