无法使用TestNG和WinAppDriver启动新的远程会话

时间:2019-07-09 14:26:35

标签: java appium winappdriver

当尝试将WinAppDriver计算器Java示例从使用JUnit更改为TestNG时,出现org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话。请检查服务器日志以获取更多详细信息。原始错误:无法解析远程响应:错误和Windows应用程序驱动程序日志中找不到http:1.1 404。

我尝试更改Appium和Selenium的版本,但没有任何运气

import io.appium.java_client.windows.WindowsDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.net.URL;
import java.util.concurrent.TimeUnit;

public class CalculatorTest {

 private static WindowsDriver CalculatorSession = null;
 private static WebElement CalculatorResult = null;

 @BeforeClass
 public static void setup() {
  try {
   DesiredCapabilities capabilities = new DesiredCapabilities();
   //            capabilities.setCapability("platformName", "Windows");
   //            capabilities.setCapability("deviceName", "WindowsPC");
   capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
   CalculatorSession = new WindowsDriver(new URL("http://127.0.0.1:4723/"), capabilities);
   CalculatorSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

   CalculatorResult = CalculatorSession.findElementByAccessibilityId("CalculatorResults");
   AssertJUnit.assertNotNull(CalculatorResult);

  } catch (Exception e) {
   e.printStackTrace();
  } finally {}
 }

 @BeforeMethod()
 public void Clear() {
  CalculatorSession.findElementByName("Clear").click();
  AssertJUnit.assertEquals("0", _GetCalculatorResultText());
 }

 @AfterClass
 public static void TearDown() {
  CalculatorResult = null;
  if (CalculatorSession != null) {
   CalculatorSession.quit();
  }
  CalculatorSession = null;
 }

 @Test
 public void Addition() {
  CalculatorSession.findElementByName("One").click();
  CalculatorSession.findElementByName("Plus").click();
  CalculatorSession.findElementByName("Seven").click();
  CalculatorSession.findElementByName("Equals").click();
  AssertJUnit.assertEquals("8", _GetCalculatorResultText());
 }

 @Test
 public void Combination() {
  CalculatorSession.findElementByName("Seven").click();
  CalculatorSession.findElementByName("Multiply by").click();
  CalculatorSession.findElementByName("Nine").click();
  CalculatorSession.findElementByName("Plus").click();
  CalculatorSession.findElementByName("One").click();
  CalculatorSession.findElementByName("Equals").click();
  CalculatorSession.findElementByName("Divide by").click();
  CalculatorSession.findElementByName("Eight").click();
  CalculatorSession.findElementByName("Equals").click();
  AssertJUnit.assertEquals("8", _GetCalculatorResultText());
 }

 @Test
 public void Division() {
  CalculatorSession.findElementByName("Eight").click();
  CalculatorSession.findElementByName("Eight").click();
  CalculatorSession.findElementByName("Divide by").click();
  CalculatorSession.findElementByName("One").click();
  CalculatorSession.findElementByName("One").click();
  CalculatorSession.findElementByName("Equals").click();
  AssertJUnit.assertEquals("8", _GetCalculatorResultText());
 }

 @Test
 public void Multiplication() {
  CalculatorSession.findElementByName("Nine").click();
  CalculatorSession.findElementByName("Multiply by").click();
  CalculatorSession.findElementByName("Nine").click();
  CalculatorSession.findElementByName("Equals").click();
  AssertJUnit.assertEquals("81", _GetCalculatorResultText());
 }

 @Test
 public void Subtraction() {
  CalculatorSession.findElementByName("Nine").click();
  CalculatorSession.findElementByName("Minus").click();
  CalculatorSession.findElementByName("One").click();
  CalculatorSession.findElementByName("Equals").click();
  AssertJUnit.assertEquals("8", _GetCalculatorResultText());
 }

 protected String _GetCalculatorResultText() {
  // trim extra text and whitespace off of the display value
  return CalculatorResult.getText().replace("Display is", "").trim();
 }

}

    ```

这是我的Testng.xml文件

<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
<suite name="Test Suit">
    <test name="testing">
        <classes>
            <class name="CalculatorTest" >
            </class>
        </classes>
    </test>
</suite>

这是我的POM文件

<?xml version="1.0" encoding="UTF-8"?>
    <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>CalculatorTest</groupId>
        <artifactId>CalculatorTest</artifactId>
        <version>1.0-SNAPSHOT</version>

        <dependencies>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>4.0.0-alpha-1</version>
            </dependency>
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.14.3</version>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>io.appium</groupId>
                <artifactId>java-client</artifactId>
                <version>7.1.0</version>
            </dependency>
            <dependency>
                <groupId>io.appium</groupId>
                <artifactId>java-client</artifactId>
                <version>7.1.0</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </project>

异常堆栈跟踪如下所示

org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: Unable to parse remote response: 
Build info: version: '4.0.0-alpha-1', revision: 'd1d3728cae', time: '2019-04-24T13:42:21'
System info: host: 'GB5CG924478L', ip: '10.240.199.116', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_212'
Driver info: driver.version: WindowsDriver
    at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:208)
    at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:217)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:577)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:211)
    at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:323)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:37)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:86)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:96)
    at io.appium.java_client.windows.WindowsDriver.<init>(WindowsDriver.java:42)
    at CalculatorTest.setup(CalculatorTest.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:458)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:168)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:186)
    ... 36 more
Caused by: org.openqa.selenium.WebDriverException: Unable to parse remote response: 
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:115)
    ... 41 more
Caused by: org.openqa.selenium.json.JsonException: Expected to read a START_MAP but instead have: END. Last 0 characters read: 
Build info: version: '4.0.0-alpha-1', revision: 'd1d3728cae', time: '2019-04-24T13:42:21'
System info: host: 'GB5CG924478L', ip: '10.240.199.116', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_212'
Driver info: driver.version: WindowsDriver
    at org.openqa.selenium.json.JsonInput.expect(JsonInput.java:293)
    at org.openqa.selenium.json.JsonInput.beginObject(JsonInput.java:223)
    at org.openqa.selenium.json.MapCoercer.lambda$apply$1(MapCoercer.java:64)
    at org.openqa.selenium.json.JsonTypeCoercer.lambda$null$6(JsonTypeCoercer.java:145)
    at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:126)
    at org.openqa.selenium.json.Json.toType(Json.java:69)
    at org.openqa.selenium.json.Json.toType(Json.java:55)
    at org.openqa.selenium.json.Json.toType(Json.java:50)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:112)
    ... 41 more

java.lang.NullPointerException
    at CalculatorTest.Clear(CalculatorTest.java:54)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:458)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:523)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)


Test ignored.

Test ignored.

Test ignored.

Test ignored.

Test ignored.

===============================================
Test Suit
Total tests run: 5, Failures: 0, Skips: 5
Configuration Failures: 1, Skips: 5
===============================================


Process finished with exit code 0

POST输出

POST /wd/hub/session HTTP/1.1
Accept-Encoding: gzip
Connection: Keep-Alive
Content-Length: 296
Content-Type: application/json; charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/4.0.0-alpha-1 (java windows)

{
  "desiredCapabilities": {
    "app": "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App",
    "platformName": "Windows"
  },
  "capabilities": {
    "firstMatch": [
      {
        "appium:app": "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App",
        "platformName": "windows"
      }
    ]
  }
}
HTTP/1.1 404 Not Found

0 个答案:

没有答案