Robot Framework验证是否打开了新的浏览器选项卡 [英] Robot Framework verify a new browser tab was opened

查看:279
本文介绍了Robot Framework验证是否打开了新的浏览器选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我们页面上的某些Web链接,有一些外部链接可以指导用户说Facebook和Twitter.这些链接使用HMTL标签target="_blank",以便为我们的Twitter页面打开一个新的浏览器选项卡.

For some of the web links on our page, there are external links which direct the user to say Facebook and Twitter. The links use the HMTL tag target="_blank" so that a new browser tab is opened for our Twitter page.

我想验证1.新的浏览器选项卡已打开,2.对其设置了焦点,并且3.验证了新浏览器选项卡中的页面元素.一旦我专注于#3部分,就很容易了.但是,我无法弄清楚任务1和任务2,也找不到任何人在谈论这个.

I would like to verify 1. the new browser tab is open, 2. set focus to it and 3. validate page elements in the new browser tab. The #3 part would be easy enough, once I get focus on it. Tasks #1 and #2 though, I can't figure out, nor can I find anyone talking about this.

使用Selenium2Library(WebDriver)

Using Selenium2Library (WebDriver)

推荐答案

Selenium不支持选项卡(截至2013年6月,Selenium 2.33.0),而是始终打开新窗口.如果您的测试打开了一个新标签,请祝您好运.

Selenium does not support tabs (as of June 2013, Selenium 2.33.0) and always opens new windows instead. If your test opens a new tab, good luck to you.

也就是说,如果正确打开了一个新窗口,请使用 Select Window .

That said, if it correctly opens a new window, use Select Window.

Select Window | url=https://twitter.com/expectedPage



My working WebDriver (2.33.0) code in Java, hopefully it will help a little. The problems you are describing are where my Robot knowledge begins to fall off.

@Test
public void targetBlankLinkTest() {
    // load the website and make sure only one window is opened
    driver.get(file("TargetBlankLinkTest.html"));
    assertEquals(1, driver.getWindowHandles().size());

    // click the link and assert that a new window has been opened      
    driver.findElement(By.linkText("Follow us on Twitter!")).click();
    Set<String> windowHandles = driver.getWindowHandles();
    assertEquals(2, windowHandles.size());

    // switch to the new window and do whatever you like
    // (Java doesn't have Switch Window functionality that can select by URL.
    // I could write it, but have been using this trick instead)
    for (String handle : windowHandles) {
        if (handle != driver.getWindowHandle()) {
            driver.switchTo().window(handle);
        }
    }
    assertThat(driver.getCurrentUrl(), containsString("twitter.com"));
}

这篇关于Robot Framework验证是否打开了新的浏览器选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆