如何让 Selenium 2 网络驱动程序与 Nightly (Firefox 64 位) 一起工作



我希望对Nightly浏览器(FireFox 64bit)执行Selenium 2测试。它与Selenium IDE(v1.8.1)一起记录得很好。 而且,使用 IDE 也可以很好地播放。 然后,我将代码导出为 TestNG 格式。 顺便说一下,我已经加载了Webdriver支持的插件,因此它导出Selenium 2版本的WebDriver代码。 我遇到的问题是,当我将代码导出为 TestNG 格式 (Java) 并执行它时,断言永远不会在屏幕上找到文本。 它执行得很好,所以不是代码没有转换。 这似乎只是断言的东西。 如果我从 IDE 插件播放它,它会找到它的文本并断言得很好,但是一旦它在 Java 中执行,它就会失败所有断言。 对可能发生的事情的任何想法。 我的代码如下。 多谢!

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static junit.framework.Assert.*;
import com.thoughtworks.selenium.Selenium;
public class TestWithConfig {
    WebDriver driver;
    Selenium selenium;
    @BeforeMethod
    public void startSelenium() {
        driver = new FirefoxDriver();
        selenium = new WebDriverBackedSelenium(driver,
                "http://en.wikipedia.org/wiki/Main_Page");
    }
    @AfterMethod
    public void stopSelenium() {
        driver.close();
    }
    @Test
    public void testTest() {
        selenium.setSpeed("600");
        selenium.open("/wiki/Main_Page");
        assertTrue("face not found",selenium.isTextPresent("face"));
        selenium.click("link=Contents");
        selenium.waitForPageToLoad("30000");
        assertTrue("Below not found",selenium.isTextPresent("Below"));
        selenium.click("link=Toolbox");
        selenium.click("link=What links here");
        selenium.waitForPageToLoad("30000");
        assertTrue("Pages not found",selenium.isTextPresent("Pages that link to"));
        selenium.click("link=exact:Talk:Wine");
        selenium.waitForPageToLoad("30000");
        assertTrue("Some not found",selenium.isTextPresent("Some"));
    }
}

由于您使用Selenium 2和webdriver,Assert的工作有点不同。我可以看到你使用WebDriverBackedSelenium。但是请记住。那不是硒2。这只是一种轻松进入硒2的方法。我会用这样的东西。

WebElement tooltip = driver.findElement(By.xpath("the xpath of the element"));
assertNotNull("Name:","IP Address:",tooltip);

我在这里做的是。我正在寻找一个工具提示。在该工具提示中,有两个主要标签保持不变:名称和 IP 地址:。所以我正在测试这些词在工具提示中是否存在。输出应为名称:IP 地址:。这告诉我答案是正确的。

最新更新