[英]AngularJS e2e Testing with Protractor and remote api
I would like to test my Angular app that is heavily dependent on an API. 我想测试严重依赖于API的Angular应用程序。 The API is being tested separately with phpunit and we are creating fixtures so ideally I was hoping to not have to create another set of mocked fixtures in Angular.
该API正在与phpunit分开进行测试,我们正在创建固定装置,因此理想情况下,我希望不必在Angular中创建另一组模拟固定装置。 I am using Protractor with the chrome driver only right now.
我现在仅在Chrome驱动程序中使用量角器。
First I have to login through a page that is NOT an Angular app. 首先,我必须通过不是Angular应用程序的页面登录。
I then go to a page that shows a loader with ng-if='loadingCards'
and hides a table with ng-if='!loadingCards'
and then when the API call to retrieve cards is finished, the value of loadingCards
is flipped. 然后,我转到一个页面,该页面显示带有
ng-if='loadingCards'
的加载器,并隐藏带有ng-if='!loadingCards'
,然后在API检索卡的调用完成时, loadingCards
的值翻转。
Below is the beginning of the test spec which gets you through the non angular login and then takes you to the card listing page. 以下是测试规格的开始,它可以帮助您完成非角度登录,然后转到卡列表页面。 All I would like to do is to see the contents of the
cards
$scope variable to see that the API has indeed returned something but I always get an empty array. 我要做的就是看
cards
$ scope变量的内容,以查看API确实返回了一些东西,但是我总是得到一个空数组。
describe('User cards page', function() {
var driver;
var ptor;
beforeEach(function() {
ptor = protractor.getInstance();
ptor.ignoreSynchronization = true;
browser.ignoreSynchronization = true;
driver = ptor.driver;
});
it('should login', function() {
driver.get('http://local.local.com/login');
driver.findElement(protractor.By.name('_username')).sendKeys('admin');
driver.findElement(protractor.By.name('_password')).sendKeys('admin');
driver.findElement(protractor.By.css('input[type="submit"]')).click();
});
it('should list cards', function() {
browser.get('http://local.local.com/cms/cards');
var ucards = element.all(by.repeater('card in cards')).then(function(cards) {
console.log(cards);
});
//expect(ucards.count()).toEqual(3);
});
});
Perhaps it() where the login takes place, follows the it() where you do the check of the card count. 可能在进行登录的it()后面跟随进行卡计数检查的it()。 I would recommend moving the login part to the beforeEach.
我建议将登录部分移至beforeEach。
And if that doesn't work, perhaps a ptor.sleep(300) could help. 如果这不起作用,也许ptor.sleep(300)可能会有所帮助。 Place that just below the browser.get() of the page.
将其放在页面的browser.get()下方。 The api may not have returned a value.
api可能没有返回值。
i think you are mixing up two things. 我认为您正在混淆两件事。 You can either write:
您可以写:
element.all(by.repeater('card in cards')).then(function(cards) {
console.log(cards);
});
or: 要么:
var ucards = element.all(by.repeater('card in cards'));
ucards.then(function(cards) {
console.log(cards);
});
but you are making kind of ... both. 但是你们两者都在做。
Do you get any errors? 你有什么错误吗? Could you check for your current url?
您可以检查当前的网址吗?
expect(browser.getCurrentUrl()).toEqual('http://local.local.com/cms/cards');
Greetings! 问候!
Walter helped me debug this by using the sleep command to keep the chromedriver iwndow open longer so I could see that the URL I was using was incorrect. Walter通过使用sleep命令帮助我延长了chromedriver iwndow的打开时间,从而帮助我进行了调试,因此我可以看到所使用的URL不正确。 One more test to create.
再创建一个测试。 Closing this.
关闭这个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.