在角JS单页应用程序中,ui路由器被配置为根据应用程序的状态更改视图内容(<ui-view></ui-view>)。
如何测试量角器中更改的视图内容(页面)?在执行页源视图时,不会显示视图内容。页被正确加载,但是量角器找不到页面元素。
<head>
<title> Test Application</title>
</head>
<body>
<div class="wrapper">
<div class="container">
<ui-view></ui-view>
</div>
<div>
<body>在<ui-view></ui-view>中运行的代码片段
<div class="form-group">
<label for="firstName" class="ng-scope">First Name</label>
<input type="text" id="firstName" name="firstName" ng-model="customer.firstName">
</div>量角器找不到元素by.model。
describe('Protractor Demo App', function() {
browser.get('http://example.com');//url
it("Test..", function() {
element(by.model('customer.firstName')).sendKeys('FIRSTNAME');
element(by.model('customer.lastName')).sendKeys('LASTNAME');
});
});发布于 2017-07-05 11:45:51
可能是因为它在加载元素之前就在寻找它们,因此缺少它们。尝试使用protractor.ExpectedConditions。例如:
describe('Protractor Demo App', function() {
browser.get('http://example.com');
it("Test..", function() {
var el = element(by.css('.form-group'));
var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(el), 10000).then(function(){
element(by.model('customer.firstName')).sendKeys('FIRSTNAME');
element(by.model('customer.lastName')).sendKeys('LASTNAME');
});
});
});在这里,它将等待最多10秒的.form-group div出现在页面上,然后尝试填写输入。
https://stackoverflow.com/questions/44896107
复制相似问题