java - testng 测试通过 selenium 网格返回 ie 驱动程序路径错误,但测试适用于 Firefox

标签 java firefox selenium grid testng

我正在尝试通过 selenium 网格使用 testng 运行测试。

这些测试以前有效,但今天,我收到此错误:

The path to the driver executable must be set by the webdriver.ie.driver system property

该错误没有意义,因为我的测试应该在 Firefox 上运行。

这是一些内容......

测试

 <test name="Run using Firefox 25 on Windows 7">
  <parameter name="GridBrowser"  value="firefox25win7"/>
    <classes>
      <class name="com.coursestrand_courseoverviewpanel.CourseOverviewPanelTest"/>
    </classes>
 </test> 

以上值的代码片段

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.openqa.selenium.remote.DesiredCapabilities;

     public class Configuration {

        public static DesiredCapabilities setCap; 
        public static final String GRID_HUB_URL = "http://192.168.53.67:4444/wd/hub";

        public static String SeleniumGridSetup(String gridBrowser) {

        String newGridBrowser = gridBrowser;

        switch (newGridBrowser) {


        case "firefox25win7": 
            System.out.println("Firefox Version 25.0 on Windows 7");
            setCap= DesiredCapabilities.firefox();
            setCap.setBrowserName("firefox25win7"); 
            setCap.setPlatform(org.openqa.selenium.Platform.WINDOWS);
            break;
        }

    return newGridBrowser;
}

这是我的测试

import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.*;
import com.environments.Configuration;
import com.thoughtworks.twist.core.execution.TwistScenarioDataStore;
import org.openqa.selenium.firefox.*;

import org.testng.Assert;

   public class CourseOverviewPanelTest {

    public WebDriver browser;
    public static String url; 

    @Autowired
    private TwistScenarioDataStore scenarioStore;

    @Parameters({"GridBrowser"})
    public CourseOverviewPanelTest(String GridBrowser) throws Exception {           

    Configuration.SeleniumGridSetup(GridBrowser);
    browser = new RemoteWebDriver(new URL(Configuration.GRID_HUB_URL), Configuration.setCap);

    url = Configuration.getUrl();
    browser.manage().window().maximize();
    browser.navigate().to(url + "/course-list.html");
}

public CourseOverviewPanelTest() throws Exception {

    browser = new FirefoxDriver(); 
    browser.manage().window().maximize();

    url = Configuration.getUrl();
    browser.navigate().to(url + "/course-list.html");

}

// Test methods start from here for Landing page carousel

@Test
public void displayCourseTitleAndDescription() throws Exception {

    final String courseTitle = browser.findElement(By.xpath("/html/body/section/section/article/ul/li[1]/h4")).getText();
    Assert.assertEquals("Maths", courseTitle);
}

Selenium 网格节点

java -jar selenium-server-standalone-2.39.0.jar -role webdriver -hub  http://192.168.53.67:4444/grid/register -browser browserName="firefox25win7",platform=WINDOWS -port 5585

这是运行 Firefox 节点时在网格中创建的配置

role:webdriver

remoteHost:http://192.168.53.70:5585

hubHost:192.168.53.67

hubPort:4444

prioritizer:null

timeout:300000

throwOnCapabilityNotPresent:true

nodePolling:5000

url:http://192.168.53.70:5585

newSessionWaitTimeout:-1

proxy:org.openqa.grid.selenium.proxy.DefaultRemoteProxy

cleanUpCycle:5000

hub:http://192.168.53.67:4444/grid/register

port:5585

browser:browserName=firefox25win7,platform=WINDOWS

browserTimeout:0

host:192.168.53.70

servlets:[]

maxSession:5

registerCycle:5000

capabilityMatcher:org.openqa.grid.internal.utils.DefaultCapabilityMatcher

register:true

当我执行 testng 测试时,控制台中返回错误。

注意: 如果我确实设置了可执行驱动程序的路径(在节点中),那么测试将在 IE 中运行!

进一步说明: 当我运行 chrome 节点时也会出现此问题,如下所示:

java -Dwebdriver.chrome.driver=C:/selenium-server/chromedriver.exe -jar selenium-server-standalone-2.39.0.jar -role webdriver -hub http://192.168.53.67:4444/grid/register -port 5566 -browser browserName="chromeLatestWindows7",platform=WINDOWS

疯狂的是,如果我将上述节点中的 -Dwebdriver.chrome.driver=C:/selenium-server/chromedriver.exe 更改为 -Dwebdriver.ie.driver=C:/selenium-server/chromedriver.exe 然后我的测试在 chrome 中运行良好!

最佳答案

问题似乎与浏览器名称有关。根据documentation允许的值为“-browser允许的参数:browserName = {android,chrome,firefox,htmlunit,internet explorer,iphone,opera}”。将firefox25win7的名称更改为firefox就可以了。

关于java - testng 测试通过 selenium 网格返回 ie 驱动程序路径错误,但测试适用于 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24653178/

相关文章:

java - 匹配 Java 正则表达式中可选组包围的内容

java - 在 Hibernate 中使用实体作为 DTO

javascript - 为什么此 jQuery 代码在 Firefox 中有效,但在 Chrome 或 Safari 中无效?

http - 如何在 Firefox 中忽略 "Content-Disposition: attachment"

android - 目标 Firefox 桌面 CSS

java - 使用相同的 Firefox 窗口在 Selenium WebDriver (Java) 中运行多个测试

ios - Swift/iOS 中的 Selenium 等效项

java - 如何用java写一个小数

java - 如何在 java 中使用 contains 断言两个列表值,但不是完全相等的比较

java - 当另一个应用程序移动文件时正在写入文件