2

intellij で HtmlUnitDriver を使用してテストを作成しました。コードは次のとおりです。

import junit.framework.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class HtmlUnitDemo {
    WebDriver driver;

    public static void main(String args[]){
        HtmlUnitDemo obj = new HtmlUnitDemo();
        obj.setup();
        obj.openURL();
    }

    public void openURL() {

        driver.get("https://mail.google.com");
        driver.findElement(By.id("username")).sendKeys("xyz");
        driver.findElement(By.id("password")).sendKeys("pqr");
        driver.findElement(By.className("btn-submit")).click();
        Assert.assertEquals(driver.getTitle(), "CAS – Central Authentication Service");
    }

    public void setup(){
        driver = new HtmlUnitDriver();
    }
}

このコードは、gradle を使用するとビルドされます。しかし、IDE で実行すると、

*java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.<init>(Ljava/lang/String;ILorg/apache/http/conn/scheme/SchemeSocketFactory;)

スタック トレース全体は次のとおりです。

at com.gargoylesoftware.htmlunit.HttpWebConnection.createHttpClient(HttpWebConnection.java:504)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getHttpClient(HttpWebConnection.java:470)
at com.gargoylesoftware.htmlunit.HttpWebConnection.setUseInsecureSSL(HttpWebConnection.java:659)
at com.gargoylesoftware.htmlunit.WebClient.setUseInsecureSSL(WebClient.java:1085)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.createWebClient(HtmlUnitDriver.java:263)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:129)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:172)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:168)
at smoke.com.thoughtworks.twu.HtmlUnitDemo.setup(HtmlUnitDemo.java:30)
at smoke.com.thoughtworks.twu.HtmlUnitDemo.main(HtmlUnitDemo.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

このエラーをグーグルで検索したところ、クラスパスに関連する何かが表示されました。しかし、私は正確に何をすべきかわかりません。私はこの分野に非常に慣れていません。そのため、どんな助けでも大歓迎です。前もって感謝します。

4

3 に答える 3

1

NoSuchMethodErrorクラスが存在するライブラリのorg.apache.http.conn.scheme.Schemeバージョンが、予想とは異なることを示している可能性があります。

使用している Selenium ライブラリで使用されている依存関係を確認してください。それがmavenからのものである場合、それは簡単な作業になる可能性があります。それ以外の場合は、彼らのWebサイトを確認してください。

于 2012-10-29T11:34:18.917 に答える