4

我是硒的新手。

这就是我所做的:我在 cmd 提示符下启动了一个独立的 selenium 服务器。

我运行下面的代码,对于 webDriverWay() 和 seleniumWay() 我得到如下错误。在这两种情况下,我都得到

我的测试代码:

static String baseUrl= "http:\\google.com" ;

public static void main(String[] args) throws MalformedURLException {

    //webDriverWay();
    seleniumWay();

}

private static void webDriverWay() throws MalformedURLException {
    URL url = new URL("http://127.0.0.1:4444/wd/hub"); //Could be your remote VM where you to run your tests

    DesiredCapabilities capabilities;
    capabilities = DesiredCapabilities.firefox();

    //You can test multiple type of browser
    //capabilities = DesiredCapabilities.internetExplorer();
    WebDriver driver = new RemoteWebDriver(url, capabilities);

    //Open the web site
    driver.get(baseUrl);

    //Type Search Term
    (driver.findElement(By.name("q"))).sendKeys("Test Search Query");

    //Click submit button
    (driver.findElement(By.name("btnG"))).click();
}


static void seleniumWay()
{
    Selenium sel = new DefaultSelenium("localhost", 4444, "*firefox", baseUrl);
    CommandExecutor executor = new SeleneseCommandExecutor(sel);
    DesiredCapabilities dc = new DesiredCapabilities();
    WebDriver browser = new RemoteWebDriver(executor, dc);

    browser.get(baseUrl);
    WebElement input = browser.findElement(By.name("q"));
    input.sendKeys("Selenium");
}

控制台中的异常:

Exception in thread "main" org.openqa.selenium.WebDriverException: Could not start Selenium session: org.openqa.grid.common.exception.GridException: Error forwarding the new session Empty pool of VM for setup {browserName=*safari}
Command duration or timeout: 61 milliseconds
Build info: version: '2.26.0', revision: '18040', time: '2012-11-02 09:44:45'
System info: os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_09'
Driver info: driver.version: RemoteWebDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:188)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:531)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:215)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)

如果我遗漏了什么,请告诉我。

4

1 回答 1

2

指南包含配置测试所需的所有信息。当我自己第一次开始使用 Selenium 时,我遇到了一个非常相似的问题。

于 2013-05-21T18:45:05.447 回答