[英]Howto get new opened tab URL with protractor
Hi I'm trying to get the url from a new tab opened after click on a link, and check if I get the expected value. 嗨,我正在尝试通过单击链接后从打开的新选项卡获取url,并检查是否获得了期望的值。 I can't figure out how to do it because I get this error on the chrome execution: 我不知道该怎么做,因为在chrome执行过程中出现此错误:
Failed: null value in entry: name=null
In Firefox the test passes, but the funny part is that it opens a target=_blank in a new window instead of a new tab... 在Firefox中,测试通过了,但有趣的是,它在新窗口而不是新标签页中打开了target = _blank ...
Here is my code: 这是我的代码:
var scrollBar = require("./lib/scroll_bar");
describe("WAM home blog tests", function() {
var URL = 'http://dev.wam.com.es';
beforeEach(function() {
browser.driver.manage().window().maximize();
browser.get(URL);
});
it("Should find blog section after scrolling", function() {
scrollBar.doScroll(0, 1800);
expect( $("#blog-panel").isPresent() ).toBe(true);
});
it("Should redirect to blog after click on link", function() {
var EC = protractor.ExpectedConditions;
scrollBar.doScroll(0, 1800);
element.all( by.css('div.blog-post > a') ).first().click();
browser.ignoreSynchronization = true;
browser.getAllWindowHandles().then(function (handles) {
console.log(handles);
browser.switchTo().window(handles[1]);
var header = element(by.id("header"));
browser.wait(EC.visibilityOf(header), 15000);
expect(browser.driver.getCurrentUrl())
.toMatch(/^http:\/\/blog.wam.tv\/.*/);
browser.driver.close();
browser.driver.switchTo().window(handles[0]);
});
});
afterEach(function() {
browser.ignoreSynchronization = false;
});
});
What you can do is to open the link in a new browser window by making a SHIFT+click: 您可以做的是通过按SHIFT键并单击来在新的浏览器窗口中打开链接:
var elm = element.all( by.css('div.blog-post > a') ).first();
browser.actions().mouseMove(elm).keyDown(protractor.Key.SHIFT).click().keyUp(protractor.Key.SHIFT).perform();
This helped me before in a similar situation. 这在类似情况下对我有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.