我是量角器新手,想测试链接是否有效。
我理解尝试获取元素 id 但我应该期望链接等于什么?
还有人有关于量角器测试示例的任何好的文档吗?
我经历过这个http://angular.github.io/protractor/#/tutorial
这很有帮助,但我需要更多我可以做的可能测试的例子。
到目前为止我有这个:
it('should redirect to the correct page', function(){
element(by.id('signmein').click();
expect(browser.driver.getCurrentUrl()).toEqual("http://localhost:8080/web/tfgm_customer/my-account");
});
想测试链接是否有效
这有点宽泛 - 这可能意味着链接有一个适当的href
属性,或者单击链接后应该打开一个新页面。
要检查href
属性、用途getAttribute():
expect(element(by.id('myLink')).getAttribute('href')).toEqual('http://myUrl.com');
要单击链接,请使用click(),要检查当前 URL,请使用getCurrentUrl():
element(by.id('myLink').click();
expect(browser.getCurrentUrl()).toEqual("http://myUrl.com");
请注意,如果单击后打开了非角度页面,则需要尝试一下ignoreSynchronization
标志,参见:
如果链接在新选项卡中打开,您需要切换到该窗口,检查 URL,然后切换回主窗口:
element(by.id('myLink')).click().then(function () {
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[handles.length - 1]).then(function () {
expect(browser.getCurrentUrl()).toEqual("http://myUrl.com");
});
// switch back to the main window
browser.switchTo().window(handles[0]);
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)