Selenium 2例子不起作用

时间:2013-01-29 23:05:53

标签: selenium-webdriver

我跟着这个例子      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工作示例,我将非常感谢您的链接。日Thnx

1 个答案:

答案 0 :(得分:0)

如果您希望开始使用Selenium webdriver,我建议您阅读seleniumhq.org上的文档,或者尝试下一页上的示例,它会更加简化。

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

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