简体   繁体   中英

Appium Framework: Can't run test :'remote.ProtocolHandshake createSession' What is that?

I am trying to create an appium test framework with testNG.

I decided I wanted to do a very simple test just to check that everything was working ok before deep diving in into adding tables and page objects.

I ran my testNG test and got

remote.ProtocolHandshake createSession

I have no idea what that is or how to fix it.

So my question is VERY simple:

  1. What does this message mean?
  2. How do I fix it?
  3. Is there something wrong with pom.xml file?
  4. Is this something wrong with my Appium code?

Here is my pom.xml dependencies

<dependencies>

  <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>5.0.4</version>
</dependency>
  <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.11</version>
    <scope>test</scope>
</dependency>

Here is my appium test code

package android;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Driver;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.interactions.touch.TouchActions;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.MobileCapabilityType;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;


public class TestDragnDrop {
    static AndroidDriver<AndroidElement> driver;

    @BeforeTest
    public void DesiredCapabilities() throws MalformedURLException{



        DesiredCapabilities caps =new DesiredCapabilities();
        caps.setCapability("deviceName", "JacquelineNexus5");
        caps.setCapability("platformName", "Android");
        caps.setCapability("platformVersion", "8.0");
        caps.setCapability("appPackage", "com.example.android.apis");
        caps.setCapability("appActivity", "ApiDemos");

        AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),caps);

    }

    @Test 
    //Scenario:  Perform Drag n drop function

    //Given I am on the Home screen 
    //When I  tap Views   
    //Then I will see the View menu 
    //When I am in the 'view menu' I will select 'drag n drop'
    //Then I will see 3 dots in the drag n drop page
    //When  I select a dot and drag it
    //Then I will drop it on the dot below

    public void DragAndDrop(){

        driver.findElementByAccessibilityId("Views").click();


        TouchAction t = new TouchAction (driver);
        t.tap(driver.findElementByAccessibilityId("Drag and Drop")).perform();

        t.longPress(driver.findElementById("io.appium.android.apis:id/drag_dot_1")).
        moveTo(driver.findElementById("io.appium.android.apis:id/drag_dot_3")).release().perform();
    }



}

The Eclipse console

[RemoteTestNG] detected TestNG version 6.11.0
Aug 15, 2018 3:55:05 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
FAILED: DragAndDrop
java.lang.NullPointerException
    at android.TestDragnDrop.DragAndDrop(TestDragnDrop.java:59)
    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:497)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:744)
    at org.testng.TestRunner.run(TestRunner.java:602)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
    at org.testng.SuiteRunner.run(SuiteRunner.java:289)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
    at org.testng.TestNG.runSuites(TestNG.java:1144)
    at org.testng.TestNG.run(TestNG.java:1115)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

Appium Logs

[Appium] Welcome to Appium v1.8.1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[HTTP] --> POST /wd/hub/session
[HTTP] {"desiredCapabilities":{"appActivity":"ApiDemos","appPackage":"com.example.android.apis","deviceName":"JacquelineNexus5","platformName":"Android","platformVersion":"8.0"},"capabilities":{"desiredCapabilities":{"appActivity":"ApiDemos","appPackage":"com.example.android.apis","deviceName":"JacquelineNexus5","platformName":"Android","platformVersion":"8.0"},"firstMatch":[{"platformName":"android"}]}}
[MJSONWP] Calling AppiumDriver.createSession() with args: [{"appActivity":"ApiDemos","appPackage":"com.example.android.apis","deviceName":"JacquelineNexus5","platformName":"Android","platformVersion":"8.0"},null,{"desiredCapabilities":{"appActivity":"ApiDemos","appPackage":"com.example.android.apis","deviceName":"JacquelineNexus5","platformName":"Android","platformVersion":"8.0"},"firstMatch":[{"platformName":"android"}]}]
[BaseDriver] Event 'newSessionRequested' logged at 1534415639087 (11:33:59 GMT+0100 (BST))
[Appium] Could not parse W3C capabilities: 'deviceName' can't be blank. Falling back to JSONWP protocol.
[Appium] The following capabilities were provided in the JSONWP desired capabilities that are missing in W3C capabilities: ["appActivity","appPackage","deviceName","platformName","platformVersion"]. Falling back to JSONWP protocol.
[Appium] Consider setting 'automationName' capability to 'uiautomator2' on Android >= 6, since UIAutomator framework is not maintained anymore by the OS vendor.
[Appium] Creating new AndroidDriver (v2.7.0) session
[Appium] Capabilities:
[Appium]   appActivity: ApiDemos
[Appium]   appPackage: com.example.android.apis
[Appium]   deviceName: JacquelineNexus5
[Appium]   platformName: Android
[Appium]   platformVersion: 8.0
[BaseDriver] Creating session with MJSONWP desired capabilities: {"appActivity":"ApiDemos","...
[BaseDriver] Session created with session id: acc411f6-ac7c-4fad-9e36-8ab77bc8861b
[AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.8.0_71
[AndroidDriver] Retrieving device list
[ADB] Trying to find a connected android device
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[AndroidDriver] Looking for a device with Android '8.0'
[ADB] Setting device id to emulator-5554
[ADB] Getting device platform version
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.build.version.release'
[ADB] Current device property 'ro.build.version.release': 8.0.0
[AndroidDriver] Using device: emulator-5554
[ADB] Setting device id to emulator-5554
[AndroidDriver] App file was not listed, instead we're going to run com.example.android.apis directly on the device
[AndroidDriver] Checking whether package is present on the device
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pm list packages com.example.android.apis'
[AndroidDriver] Starting Android session
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 wait-for-device'
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell echo ping'
[AndroidDriver] Pushing settings apk to device...
[ADB] Getting install status for io.appium.settings
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pm list packages io.appium.settings'
[ADB] App is installed
[ADB] Getting package info for 'io.appium.settings'
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.settings'
[ADB] The installed 'io.appium.settings' package does not require upgrade ('2.3.0' >= '2.3.0')
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell ps'
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.build.version.sdk'
[ADB] Current device property 'ro.build.version.sdk': 26
[ADB] Device API level: 26
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am start -W -n io.appium.settings/.Settings -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000'
[ADB] Device API level: 26
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell appops set io.appium.settings android\:mock_location allow'
[AndroidDriver] setDeviceLanguageCountry requires language or country.
[AndroidDriver] Got language: 'undefined' and country: 'undefined'
[Logcat] Starting logcat capture
[AndroidDriver] Pushing unlock helper app to device...
[ADB] Getting install status for io.appium.unlock
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pm list packages io.appium.unlock'
[ADB] App is installed
[ADB] Getting package info for 'io.appium.unlock'
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.unlock'
[ADB] The installed 'io.appium.unlock' package does not require upgrade ('2.0.0' >= '2.0.0')
[ADB] Getting device platform version
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.build.version.release'
[ADB] Current device property 'ro.build.version.release': 8.0.0
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell wm size'
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.product.model'
[ADB] Current device property 'ro.product.model': Android SDK built for x86
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.product.manufacturer'
[ADB] Current device property 'ro.product.manufacturer': Google
[AndroidDriver] No app sent in, not parsing package/activity
[AndroidDriver] No app capability. Assuming it is already on the device
[ADB] Getting install status for com.example.android.apis
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pm list packages com.example.android.apis'
[ADB] App is installed
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am force-stop com.example.android.apis'
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pm clear com.example.android.apis'
[AndroidDriver] Performed fast reset on the installed 'com.example.android.apis' application (stop and clear)
[AndroidBootstrap] Watching for bootstrap disconnect
[ADB] Forwarding system: 4724 to device: 4724
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 forward tcp\:4724 tcp\:4724'
[UiAutomator] Starting UiAutomator
[UiAutomator] Moving to state 'starting'
[UiAutomator] Parsing uiautomator jar
[UiAutomator] Found jar name: 'AppiumBootstrap.jar'
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 push /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar /data/local/tmp/'
[ADB] Attempting to kill all uiautomator processes
[ADB] Getting all processes with uiautomator
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell ps'
[ADB] No uiautomator process found to kill, continuing...
[UiAutomator] Starting UIAutomator
[ADB] Creating ADB subprocess with args: ["-P",5037,"-s","emulator-5554","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","com.example.android.apis","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false]
[UiAutomator] Moving to state 'online'
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Loading json...
[AndroidBootstrap] Android bootstrap socket is now connected
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys window'
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] json loading complete.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected
[AndroidDriver] Screen already unlocked, doing nothing
[ADB] Device API level: 26
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am start -W -n com.example.android.apis/ApiDemos -S'
[ADB] We tried to start an activity that doesn't exist, retrying with '.ApiDemos' activity name
[ADB] Device API level: 26
[ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am start -W -n com.example.android.apis/.ApiDemos -S'
[Appium] New AndroidDriver session created successfully, session acc411f6-ac7c-4fad-9e36-8ab77bc8861b added to master session list
[BaseDriver] Event 'newSessionStarted' logged at 1534415653615 (11:34:13 GMT+0100 (BST))
[MJSONWP] Responding to client with driver.createSession() result: {"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"appActivity":"ApiDemos","appPackage":"com.example.android.apis","deviceName":"JacquelineNexus5","platformName":"Android","platformVersion":"8.0"},"appActivity":"ApiDemos","appPackage":"com.example.android.apis","deviceName":"emulator-5554","platformName":"Android","platformVersion":"8.0.0","deviceUDID":"emulator-5554","deviceScreenSize":"1080x1920","deviceModel":"Android SDK built for x86","deviceManufacturer":"Google"}
[HTTP] <-- POST /wd/hub/session 200 14548 ms - 702
[HTTP] 

here

<dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>5.0.4</version>
</dependency>

as per the java-client documentation this version supports selenium 3.6.0 . So either change your selenium-java version to the same or upgrade you java-client to newer version. Please update if you still face this issue.

I was able to get to the root cause of this problem with all your help, a few headaches and a lot of research!

Basically I originally structured my desired capabilities like:

public class TestDragnDrop {
    static AndroidDriver<AndroidElement> driver;

@BeforeTest
public void DesiredCapabilities() throws MalformedURLException{



    DesiredCapabilities caps =new DesiredCapabilities();
    caps.setCapability("deviceName", "JacquelineNexus5");
    caps.setCapability("platformName", "Android");
    caps.setCapability("platformVersion", "8.0");
    caps.setCapability("appPackage", "com.example.android.apis");
    caps.setCapability("appActivity", "ApiDemos");

    AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),caps);

}

What I SHOULD have done and the correct way was to structured my desired capabilities for a Maven/TestNG automation framework test as:

public class DragnDropTest {
static AndroidDriver<MobileElement> driver;

    @BeforeTest
    public AndroidDriver<MobileElement> initDriver() throws MalformedURLException{



        DesiredCapabilities caps =new DesiredCapabilities();
        caps.setCapability("deviceName", "JacquelineNexus5");
        caps.setCapability("platformName", "Android");
        caps.setCapability("platformVersion", "8.0");
        caps.setCapability("automationName", "UiAutomator2");
        caps.setCapability("appPackage", "com.example.android.apis");
        caps.setCapability("appActivity", "ApiDemos");

        driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
        return driver;
    }




    @Test 
    //Scenario:  Perform Drag n drop function
  1. You can create a Test scenario as normal.

  2. You can find elements and run tests as normal.

I hope this help anyone else in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM