【问题标题】:TestNG not running @Test for Firefox Driver -- Chrome workingTestNG 没有为 Firefox 驱动程序运行 @Test -- Chrome 工作
【发布时间】:2021-10-12 17:20:55
【问题描述】:

我正在使用 TestNG 在 Eclipse 中为 Chrome 和 Firefox 构建 Selenium WebDriver 测试。当我将 testng.xml 文件作为 TestNG 套件运行时,它会打开 Firefox 浏览器,但不会在类文件中输入 @Test 方法。 @BeforeClass 方法做得很好。

但是,当我有几乎相同的代码但对于 Chrome 时,它​​工作正常 - 它进入 @Test 方法,一切都很好。

知道为什么它会进入 Chrome 的 @Test 方法,而不是 Firefox 吗?

这是我班级的代码:

public class TestFireFox {

    private WebDriver driver;

    @BeforeClass
    public void beforeClass() {
        System.out.println("Running TestFireFox Class");
        driver = new FirefoxDriver();
        System.setProperty("webdriver.gecko.driver", "geckodriver");
    }

    @AfterClass
    public void afterClass() {
        driver.quit();
    }

    @Test
    public void verifySearchButton() {

        System.out.println("Inside Verify Method");
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        driver.get("http://www.google.com");

        String search_text = "Google Search";
        WebElement search_button = driver.findElement(By.name("btnK"));

        String text = search_button.getAttribute("value");

        Assert.assertEquals(text, search_text, "Text not found!");
    }
}

【问题讨论】:

    标签: selenium-chromedriver testng selenium-firefoxdriver


    【解决方案1】:

    问题可能是语句的顺序。在实例化Firefox 之前,您需要setProperty

    System.setProperty("webdriver.gecko.driver", "path\\to\\geckodriver.exe");
    driver = new FirefoxDriver();
    

    【讨论】:

      猜你喜欢
      • 2018-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-27
      • 2017-03-20
      • 2016-07-15
      • 2019-11-22
      • 1970-01-01
      相关资源
      最近更新 更多