1

有什么方法可以实现本地实例的类型 转换WebDriver到??? 我的代码是这样的ThreadLocal<WebDriver>MarionetteDriver

    public class Base_Class 
   {
    protected ThreadLocal<WebDriver> Driver = null;
    @BeforeMethod
    @Parameters("BrowserName")
    public void setUp(@Optional("Firefox") String BrowserName) throws MalformedURLException
    {

        Driver = new ThreadLocal<WebDriver>();
        if(BrowserName.equalsIgnoreCase("FireFox"))
        { 

            System.setProperty("webdriver.gecko.driver", "..//BrowserDrivers//wires");
            DesiredCapabilities capabilities = DesiredCapabilities.firefox();
            capabilities.setCapability("marionette", true);
             Driver = new <ThreadLocal<WebDriver>> MarionetteDriver(capabilities);


       }
        else  if(BrowserName.equalsIgnoreCase("Chrome"))
        {
            System.setProperty("webdriver.chrome.driver", "..//BrowserDrivers//chromedriver");
            Driver = new <ThreadLocal<WebDriver>>ChromeDriver();
        }
    }

    public WebDriver getDriver()
    {
        return Driver.get();
    }

    @AfterMethod
    public void closeBrowser()
    {
        getDriver().quit();

    }
    }

并且所有测试用例都定义在单独的类中,这些类扩展了 Base_Class。

得到错误@ Driver = new <ThreadLocal<WebDriver>> MarionetteDriver(capabilities); and Driver = new <ThreadLocal<WebDriver>>ChromeDriver(); lines as Type mismatch: cannot convert from MarionetteDriver to ThreadLocal<WebDriver>

我在操作系统上使用Chrome Version 52.0.2743.116 (64-bit)FireFox Version 48.0版本浏览Ubuntu 14.04Selenium version selenium-server-standalone-2.53.0

想通过testng.xml文件实现并行测试执行..

任何帮助将不胜感激..

4

1 回答 1

1

您需要在代码中进行以下更改以使其编译。

  1. DesiredCapabilities使用您的和创建 MarionetteDriver 对象
  2. ThreadLocal使用它的 set 方法在对象内部设置这个 Driver 对象。

如下所示:

if(BrowserName.equalsIgnoreCase("FireFox")) { 
  System.setProperty("webdriver.gecko.driver", "..//BrowserDrivers//wires");
  DesiredCapabilities capabilities = DesiredCapabilities.firefox();
  capabilities.setCapability("marionette", true);

  // Commented out below line from your code
  //Driver = new <ThreadLocal<WebDriver>> MarionetteDriver(capabilities);
  Driver.set(new MarionetteDriver(capabilities));
}

试试这个,让我知道

于 2016-08-25T15:39:02.437 回答