java.lang.NoSuchMethodError:javax.ws.rs.core.MultivaluedMap.addAll(Ljava / lang / Object; [Ljava / lang / Object;)

时间:2016-05-03 16:33:21

标签: selenium selenium-webdriver

我试图通过使用方法“ eyes.testResponseTime(driver,appName,testName,action,deadline,timeout,viewportSize); ”来测试页面的“加载时间”下面的脚本,我得到了上面提到的错误。该方法来自“Applitools”(用于Visual Validation)。请帮助我,并给我一个解决方案如何有效地使用这种方法,请给我一个简单的工作代码。提前谢谢......

代码:

import java.net.URI;  
import java.net.URISyntaxException;  
import org.openqa.selenium.By;  
import org.openqa.selenium.WebDriver;  
import org.openqa.selenium.firefox.FirefoxDriver;  
import com.applitools.eyes.Eyes;  
import com.applitools.eyes.StdoutLogHandler;

public class LoadTime {

    public static void main(String[] args)  {

        Eyes eyes =null;
        WebDriver driver =null;
        try {
        driver = new FirefoxDriver();

        eyes = new Eyes(new URI("https://applitools.com"));

        eyes.setApiKey("Type_Applitools_Key_Here");

        eyes.setLogHandler(new StdoutLogHandler(true));

        // Load the applitools login page.
        driver.get("https://applitools.com/login/");

        // Enter the username and password. But don't click on "Login" just yet.
        driver.findElement(By.id("user_login")).sendKeys("Enter User Name");

        driver.findElement(By.id("user_pass")).sendKeys("Enter Password");
        Thread.sleep(4000);

            try {
                eyes.testResponseTime(driver, "Applitools Website", "Login performance test 1",
                        // We want time to be measured from when we click on the
                        // "Login" button.
                        new Eyes.WebDriverAction() {
                            public void drive(WebDriver driver) {
                                driver.findElement(By.id("wp-submit")).click();
                            }
                        }, 20,new RectangleSize(1024, 600));                
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } finally {
            eyes.abortIfNotClosed();
            driver.quit();
        }
    }
}

方法中出现错误:     eyes.testResponseTime()请参考上面的代码。

Pom.xml:

<project 

xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

 <modelVersion>4.0.0</modelVersion>
    <groupId> T_TestSuite</groupId>
    <artifactId>T_TestSuite</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name></name>
    <description>AutomateT</description>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jdk.version>1.7</jdk.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                    <compilerArgument></compilerArgument>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.14</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <systemPropertyVariables>
                        <buildnumber>${build.number}</buildnumber>
                        <jobname>${job.name}</jobname>
                    </systemPropertyVariables>
                    <properties>
                        <property>
                            <name>usedefaultlisteners</name>
                            <value>false</value>
                        </property>
                        <property>
                            <name>listener</name>
                            <value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter,com.automateon.TestProgressListener</value>
                        </property>
                    </properties>
                    <reportsDirectory>${project.basedir}/target/</reportsDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <build.number>${BUILD_NUMBER}</build.number>
                <job.name>${JOB_NAME}</job.name>
            </properties>
        </profile>
    </profiles>
    <dependencies>
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.uncommons</groupId>
            <artifactId>reportng</artifactId>
            <version>1.1.2</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.testng</groupId>
                    <artifactId>testng</artifactId>

                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.8</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.52.0</version>
        </dependency>
        <dependency>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
            <version>LATEST</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>

        <dependency>
            <groupId>com.squareup.okhttp</groupId>
            <artifactId>okhttp</artifactId>
            <version>2.7.5</version>
        </dependency>
        <dependency>

            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20090211</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>

        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.3</version>
            <type>jar</type>
            <classifier>jdk15</classifier>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>xom</groupId>
            <artifactId>xom</artifactId>
            <version>1.1</version>
        </dependency>

        <dependency>
            <groupId>com.squareup.okhttp</groupId>
            <artifactId>okhttp</artifactId>
            <version>2.7.5</version>
        </dependency>


        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.9</version>
        </dependency>

        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.6.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.8</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.19</version>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>1.19</version>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.19</version>
        </dependency>

        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.7.2</version>
        </dependency>

        <dependency>
            <groupId>net.sourceforge.jexcelapi</groupId>
            <artifactId>jxl</artifactId>
            <version>2.6.12</version>
            <type>jar</type>
            <scope>compile</scope>
            <optional>false</optional>
        </dependency>

        <dependency>
            <groupId>RealTimeReports</groupId>
            <artifactId>RealTimeReports</artifactId>
            <version>1.0</version>
            <classifier>jar-with-dependencies</classifier>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/RealTimeReports.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.4</version>
        </dependency>

        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>com.applitools</groupId>
            <artifactId>eyes-selenium-java</artifactId>
            <version>2.32</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.5</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-6.0</artifactId>
            <version>1.0.0.Final</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0.1</version>
            <scope>provided</scope>

        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>2.22.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>2.22.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>1.8.7</version>
        </dependency>
    </dependencies>
</project>

控制台日志:

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
2016-05-03T16:12:17Z Eyes: openBase():Agent = eyes.selenium.java/2.31
2016-05-03T16:12:17Z Eyes: openBase():openBase('AppTest', 'Login Test', 'null')
2016-05-03T16:12:17Z Eyes: openBase():Eyes server URL is 'https://applitools.com'
2016-05-03T16:12:17Z Eyes: openBase():Timeout = '300000'
2016-05-03T16:12:17Z Eyes: openBase():matchTimeout = '2' 
2016-05-03T16:12:17Z Eyes: openBase():Default match settings = 'Match level: STRICT, Exact match settings: null' 
2016-05-03T16:12:17Z Eyes: openBase():FailureReports = 'ON_CLOSE' 
2016-05-03T16:12:17Z Eyes: <init>():Driver session is 7XXXXXXXXXXXXXXXXXXXXX2
2016-05-03T16:12:17Z Eyes: testResponseTimeBase():testResponseTimeBase(regionProvider, 10, 30, 5000)
2016-05-03T16:12:17Z Eyes: testResponseTimeBase():No running session, calling start session..
2016-05-03T16:12:17Z Eyes: startSession():startSession()
2016-05-03T16:12:17Z Eyes: getDefaultContentViewportSize():getDefaultContentViewportSize()
2016-05-03T16:12:17Z Eyes: <init>():Frame chain copy constructor (size 0)
2016-05-03T16:12:17Z Eyes: <init>():Done!
2016-05-03T16:12:17Z Eyes: getDefaultContentViewportSize():Extracting viewport size...
2016-05-03T16:12:17Z Eyes: extractViewportSize():extractViewportSize()
2016-05-03T16:12:17Z Eyes: executeScript():Execute script...
2016-05-03T16:12:17Z Eyes: executeScript():Done!
2016-05-03T16:12:17Z Eyes: getDefaultContentViewportSize():Done! Viewport size: 1010x452
2016-05-03T16:12:17Z Eyes: startSession():No batch set
2016-05-03T16:12:17Z Eyes: getUserAgent():user agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0
2016-05-03T16:12:17Z Eyes: getAppEnvironment():No OS set, checking for mobile OS...
2016-05-03T16:12:17Z Eyes: getAppEnvironment():No mobile OS detected.
2016-05-03T16:12:17Z Eyes: getAppEnvironment():Done!
2016-05-03T16:12:17Z Eyes: startSession():Application environment is [os = ? hostingApp = ? displaySize = 1010x452]
2016-05-03T16:12:17Z Eyes: startSession():Starting server session...
2016-05-03T16:12:17Z Eyes: abortIfNotClosed():Closed
Exception in thread "main" java.lang.NoSuchMethodError: javax.ws.rs.core.MultivaluedMap.addAll(Ljava/lang/Object;[Ljava/lang/Object;)V
    at org.glassfish.jersey.client.ClientRequest.accept(ClientRequest.java:336)
    at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:221)
    at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:59)
    at com.applitools.eyes.Jersey2xServerConnector.startSession(Jersey2xServerConnector.java:145)
    at com.applitools.eyes.EyesBase.startSession(EyesBase.java:1348)
    at com.applitools.eyes.EyesBase.testResponseTimeBase(EyesBase.java:1017)
    at com.applitools.eyes.Eyes.testResponseTime(Eyes.java:452)
    at com.applitools.eyes.Eyes.testResponseTime(Eyes.java:532)
    at com.TL.Test.TDB.LoadTime.main(LoadTime.java:49)

使用的参考资料:

1. http://support.applitools.com/customer/en/portal/articles/2167207-testing-your-page-s-loading-time?t=372225    
2. https://eyes.applitools.com/app/tutorial.html

2 个答案:

答案 0 :(得分:0)

解决方案: 我得到了输出,它的工作正常。刚刚在新工作区上创建了一个新项目,并添加了以下maven依赖项;

<强> POM:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>VisualValidation</groupId>
      <artifactId>VisualValidation</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5</version>
            <configuration>
              <source>1.3</source>
              <target>1.2</target>
            </configuration>
          </plugin>
        </plugins>
      </build>

  <dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.52.0</version>
    </dependency>

    <dependency>
        <groupId>com.applitools</groupId>
        <artifactId>eyes-common-java</artifactId>
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>com.applitools</groupId>
        <artifactId>eyes-sdk-java</artifactId>
        <version>2.24</version>
    </dependency>

    <dependency>
        <groupId>com.applitools</groupId>
        <artifactId>eyes-selenium-java</artifactId>
        <version>2.28</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.18.1</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.8</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.8</version>
    </dependency>

    <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.7.2</version>
    </dependency>

  </dependencies>
</project>

答案 1 :(得分:0)

我遇到了同样的问题,我能够解决它 解决方案:

Eyes默认情况下使用Jersey2.x。如果您使用的是Jersey1.x,请执行以下操作: 1.从Eyes-selenium依赖性中排除eyes-connectivity-java3-jersey2x 2.添加对eyes-connectivity-java3-jersey1x的依赖

请注意,眼睛连接的版本号应与Eyes-selenium相同。