Protractor 量角器:在登录页中找不到元素
我是量角器的新手,尝试将其用于angularjs应用程序, 配置文件片段:Protractor 量角器:在登录页中找不到元素,protractor,Protractor,我是量角器的新手,尝试将其用于angularjs应用程序, 配置文件片段: exports.config = { directConnect: true, capabilities: { 'browserName': 'chrome' }, framework: 'jasmine', specs: ['plugins/./test_spec.js'], allScriptsTimeout: 60000, getPageT
exports.config = {
directConnect: true,
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine',
specs: ['plugins/./test_spec.js'],
allScriptsTimeout: 60000,
getPageTimeout: 30000,
jasmineNodeOpts: {
defaultTimeoutInterval: 1240000
}
};
工作测试用例(规范文件):
失败的测试用例(规范文件):
尝试将sendKeys用于登录页面失败,但如果没有sendKeys测试用例通过,我将遇到以下错误:
Failed: script timeout: result was not received in 60 seconds
(Session info: chrome = 72.0.3626.109)
(Driver info: chromedriver = 2.46.628402(536cd7adbad73a3783fdc2cab92ab2ba7ec361e1), platform = Windows NT 10.0.17134 x86_64)
我怀疑找不到元素。
请引导我通过这个
提前感谢我强烈建议将
SELENIUM\u PROMISE\u MANAGER:false,
添加到您的dragrator.config
文件中,如果很快通知它-最好不要使用控制流。那么,您的配置文件的外观如何:
exports.config = {
directConnect: true,
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine',
specs: ['plugins/./test_spec.js'],
allScriptsTimeout: 60000,
getPageTimeout: 30000,
jasmineNodeOpts: {
defaultTimeoutInterval: 1240000
},
SELENIUM_PROMISE_MANAGER: false,
};
之后,您应该更新您的测试(所有返回promise
的操作都应该解决它,我更喜欢async…wait
style)。另外,你的expect
true是无用的,让我们摆脱它,添加一些明确的服务员
describe('Login', () => {
it('Login Page' async () => {
await browser.get('http://localhost:9000/apps/admin/');
const name = element(by.model('ctrl.user.name'));
await browser.wait(ExpectedConditions.elementToBeClickable(name), 10000);
await name.sendKeys("test1");
const password = element(by.model('ctrl.user.password'));
await browser.wait(ExpectedConditions.elementToBeClickable(password), 10000);
await password.sendKeys("test1");
element(by.css('[type="submit"]')).click();
expect(true).toBe(true)
});
});
另外,最好使用CSS查找定位器。更新您的问题,说明此测试将失败的错误。我强烈建议将
SELENIUM\u PROMISE\u MANAGER:false,
添加到您的gravor.config
文件中,如果很快通知它-最好不要使用控制流。那么,您的配置文件的外观如何:
exports.config = {
directConnect: true,
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine',
specs: ['plugins/./test_spec.js'],
allScriptsTimeout: 60000,
getPageTimeout: 30000,
jasmineNodeOpts: {
defaultTimeoutInterval: 1240000
},
SELENIUM_PROMISE_MANAGER: false,
};
之后,您应该更新您的测试(所有返回promise
的操作都应该解决它,我更喜欢async…wait
style)。另外,你的expect
true是无用的,让我们摆脱它,添加一些明确的服务员
describe('Login', () => {
it('Login Page' async () => {
await browser.get('http://localhost:9000/apps/admin/');
const name = element(by.model('ctrl.user.name'));
await browser.wait(ExpectedConditions.elementToBeClickable(name), 10000);
await name.sendKeys("test1");
const password = element(by.model('ctrl.user.password'));
await browser.wait(ExpectedConditions.elementToBeClickable(password), 10000);
await password.sendKeys("test1");
element(by.css('[type="submit"]')).click();
expect(true).toBe(true)
});
});
另外,最好使用CSS查找定位器。更新您的问题,说明此测试将失败的错误。量角器是selenium上的包装器,因此,当您抱怨使用Wait/async方法时,只需将selenium\u PROMISE\u管理器设置为false即可禁用,以便量角器可以与async/Wait方法很好地配合使用 我还建议使用pagemodel设计模式,这将使代码更具可读性
enter code here
export class loginPageObject{
public emailTextBox: ElementFinder;
public passwordTextBox: ElementFinder;
public signInButton: ElementFinder;
public errorMessage: ElementFinder;
constructor(){ //this.emailTextBox = $("input[type='email']");
//this.emailTextBox = element(by.css("body > app-root > div > app-login > div > div > form > div > input"));
this.emailTextBox = $("input[type='email']");
this.passwordTextBox = $("input[type='password']");
this.signInButton = $("button[type='submit']");
this.errorMessage = $("span");
}
}
上面就是这样一个例子。。稍后,您可以像下面这样使用它量角器是selenium上的包装器,因此,当您抱怨使用等待/异步方法时,只需将selenium\u PROMISE\u管理器设置为false即可禁用,这样量角器就可以很好地与异步/等待方法配合使用 我还建议使用pagemodel设计模式,这将使代码更具可读性
enter code here
export class loginPageObject{
public emailTextBox: ElementFinder;
public passwordTextBox: ElementFinder;
public signInButton: ElementFinder;
public errorMessage: ElementFinder;
constructor(){ //this.emailTextBox = $("input[type='email']");
//this.emailTextBox = element(by.css("body > app-root > div > app-login > div > div > form > div > input"));
this.emailTextBox = $("input[type='email']");
this.passwordTextBox = $("input[type='password']");
this.signInButton = $("button[type='submit']");
this.errorMessage = $("span");
}
}
上面就是这样一个例子。。以后你可以像下面这样使用它