错误对于MyDriver类型,未定义RemoteWebDriver(URL,DesiredCapabilities)方法

时间:2017-10-04 16:24:58

标签: java eclipse selenium

我在ecplipse中使用java进行selenium自动化的示例,当我运行程序时,我收到此错误RemoteDDverver(URL,DesiredCapabilities)方法未定义MyDriver类型

driver = RemoteWebDriver(new 
URL("http://localhost:4444/wd/hub"),DesiredCapabilities.firefox());

完整代码

package automation;
import java.net.MalformedURLException;
import java.util.logging.Level;
import java.net.URL;
import org.xml.sax.SAXException;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Platform;    
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;

public class MyDriver {

private WebDriver driver;

public MyDriver(String browser) {
    switch (browser) {
    case "remoteFirefox":
    try
    {
         driver = RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),DesiredCapabilities.firefox());
    } catch (MalformedURLException e) {
        e.printStackTrace();

    }
    case "firefox":
        driver = new FirefoxDriver();
        break;

    case "Chrome":
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\Lenovo\\Downloads\\chromedriver_win32");
        driver = new ChromeDriver();
        break;
        defautl:
            break;
        }

}

public WebDriver getDriver() {
    return this.driver;
}

}

1 个答案:

答案 0 :(得分:0)

你错过了创建新的RemoteDriver,请添加新的,它应该工作

    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),DesiredCapabilities.firefox());
} catch (MalformedURLException e) {