-1

我遵循了 http://www.qaautomation.net/?p=263上的示例

package net.qaautomation.examples;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
 * Search Google example.
 *
 * @author Rahul
 */
public class GoogleSearch {
 static WebDriver driver;
 static Wait<WebDriver> wait;

public static void main(String[] args) {
    driver = new FirefoxDriver();
    wait = new WebDriverWait(driver, 30);
    driver.get("http://www.google.com/");

    boolean result;
    try {
        result = firstPageContainsQAANet();
    } catch(Exception e) {
        e.printStackTrace();
        result = false;
    } finally {
        driver.close();
    }

    System.out.println("Test " + (result? "passed." : "failed."));
    if (!result) {
        System.exit(1);
    }
}

private static boolean firstPageContainsQAANet() {
    //type search query
    driver.findElement(By.name("q")).sendKeys("qa automation\n");

    // click search
    driver.findElement(By.name("btnG")).click();

    // Wait for search to complete
    wait.until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver webDriver) {
            System.out.println("Searching ...");
            return webDriver.findElement(By.id("resultStats")) != null;
        }
    });

    // Look for QAAutomation.net in the results
    return driver.findElement(By.tagName("body")).getText().contains("qaautomation.net");
}

}

信,但是当我运行它时,我得到了错误

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.<init>(Ljava/lang/String;ILorg/apache/http/conn/scheme/SchemeSocketFactory;)V
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:59)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:48)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:120)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:81)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
at com.google.gwt.sample.contacts.test.GoogleSearch.main(GoogleSearch.java:20)

关于什么可能是错的任何想法?实际上,我尝试过的其他几个示例都给了我类似的 NoSuchMethod 错误。EG http://thomassundberg.wordpress.com/2011/10/18/testing-a-web-application-with-selenium-2/ 如果您有任何简单的 Selenium2 示例,我将不胜感激链接。谢谢

4

1 回答 1

0

如果您想开始使用 Selenium webdriver,我建议您通读 seleniumhq.org 上的文档,也许可以尝试下一页上的示例,它会稍微简化一些。

http://seleniumhq.org/docs/03_webdriver.jsp

我还建议使用 eclipse 并远离 maven 和 ant,直到你很好地掌握了 webdriver,假设你是这些应用程序的新手。

于 2013-01-30T04:45:45.223 回答