尝试在Sauce Labs中运行Eclipse JAVA程序。但是在构造函数和远程Webdriver上遇到了问题。

时间:2018-09-09 01:45:10

标签: selenium selenium-webdriver saucelabs remotewebdriver

下面编写的代码在Sauce Labs中运行一个Eclipse程序。工作流显示一个问题“构造函数远程WebDriver(String,DesiredCapabilities)未定义”。

仍然尝试运行该程序,然后出现以下问题。

线程“主”中的异常java.lang.Error:未解决的编译问题:     构造函数RemoteWebDriver(URL,DesiredCapabilities)未定义     构造函数URL(String)在sauceprog.main(sauceprog.java:40)中未定义

代码:

    import java.net.MalformedURLException;
    import org.openqa.selenium.By;
    import org.openqa.selenium.Keys;
    import org.openqa.selenium.remote.CommandExecutor;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;

    import com.gargoylesoftware.htmlunit.javascript.host.URL;
    public class sauceprog
    {

    public static void main(String[] args) throws InterruptedException, MalformedURLException
    {
        String browser = "safari-saucelabs";
        String URL = "https://rpautomation4:27763475-7193-4984-8074-a4fe2f9982f7@ondemand.saucelabs.com:443/wd/hub";
        DesiredCapabilities caps = null;

    switch(browser.toLowerCase())
    {
    case "internetexplorer-win-saucelabs":
    caps = DesiredCapabilities.internetExplorer();
    caps.setCapability("platform", "Windows 10");
    caps.setCapability("version", "11.103");
    caps.setCapability("recordVideo", "false");
    caps.setCapability("screenResolution", "1024x768");
    break;
    case "chrome-win-saucelabs":
    caps = DesiredCapabilities.chrome();
    caps.setCapability("platform", "Windows 8");
    caps.setCapability("version", "69.0");
    caps.setCapability("recordVideo", "false");
    break;
    case "firefox-win-saucelabs":
    caps = DesiredCapabilities.firefox();
    caps.setCapability("platform", "Windows 8");
    caps.setCapability("version", "62.0");
    caps.setCapability("recordVideo", "false");
    default: 
        System.out.println("you passed incorrect values. Please check next time");
    }
    RemoteWebDriver driver = new RemoteWebDriver(URL,caps);
    driver.get("https://www.google.com");
    driver.findElement(By.name("q")).sendKeys("selenium");
    Thread.sleep(2000);
    driver.findElement(By.name("q")).sendKeys(Keys.ENTER);
    Thread.sleep(5000);
    driver.quit();
    }
    }

0 个答案:

没有答案