繁体   English   中英

如何使用量角器获取新的打开的标签URL

[英]Howto get new opened tab URL with protractor

嗨,我正在尝试通过单击链接后从打开的新选项卡获取url,并检查是否获得了期望的值。 我不知道该怎么做,因为在chrome执行过程中出现此错误:

Failed: null value in entry: name=null

在Firefox中,测试通过了,但有趣的是,它在新窗口而不是新标签页中打开了target = _blank ...

这是我的代码:

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;
    });

});

您可以做的是通过按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();

这在类似情况下对我有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM