java - 修复此appium错误: "A session is either terminated or not started"

标签 java android appium

我收到此错误代码,但找不到任何解决方案:

Exception in thread "main" org.openqa.selenium.NoSuchSessionException: A session is either terminated or not started

我尝试在互联网上查找一些信息,但没有找到符合我问题的信息。

我尝试使用 appium 和一些硬编码变量来自动化游戏《第七史诗》的一小部分。我不知道我的能力是否有任何问题,但我认为没有,因为它在 Inspektor Session 中工作得很好。所以我想一定是我的代码、逻辑或者驱动安装有问题。

我的代码:

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.touch.offset.PointOption;

public class main {
    public static DesiredCapabilities init() {
//        "platformName": "Android",
//        "deviceName": "HUAWEI P10",
//        "appPackage": "com.stove.epic7.google",
//        "appActivity": "kr.supercreative.epic7.AppActivity",
//        "noReset": true,
//        "skipDeviceInitialization": true,
//        "skipServerInstallation": true

        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("deviceName", "HUAWEI P10");
        caps.setCapability("udid", "6PQ0217829002238"); //Give Device ID of your mobile phone
        caps.setCapability("platformName", "Android");
        caps.setCapability("platformVersion", "8.0.0");
        caps.setCapability("appPackage", "com.stove.epic7.google");
        caps.setCapability("appActivity", "kr.supercreative.epic7.AppActivity");
        caps.setCapability("noReset", "true");
        caps.setCapability("skipServerInstallation", true);
        caps.setCapability("clearSystemFiles", false);

        return caps;
    }


    public static void main(String[] args) throws InterruptedException {
        Scanner input = new Scanner(System.in);


        try {
            AppiumDriver<MobileElement> mygame = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), init());
            int x = 1;

            while(x != -1) {
                x = input.nextInt();
                TouchAction touchAction = new TouchAction(mygame);

                for(int i = 0; i < x; i++) {
                    //select team + supp
                    touchAction.tap(new PointOption().withCoordinates(1400, 950)).perform();
                    //start quest
                    touchAction.tap(new PointOption().withCoordinates(1400, 950)).perform();
                    //buy energy
                    touchAction.tap(new PointOption().withCoordinates(1076, 772)).perform();
                    //start quest again if energie empty
                    touchAction.tap(new PointOption().withCoordinates(1400, 950)).perform();
                    //wait for finishing mission
                    for(int j = 0; j < 4;j++) {
                        Thread.sleep(1000 * 30 * 2);
                        touchAction.tap(new PointOption().withCoordinates(1400, 950)).perform();
                    }

                    Thread.sleep(1000 * 60 * 2);
                    //clear stage tap anywhere
                    touchAction.tap(new PointOption().withCoordinates(1400, 950)).perform();
                    //confirm mvp
                    touchAction.tap(new PointOption().withCoordinates(1740, 994)).perform();
                    //play again
                    touchAction.tap(new PointOption().withCoordinates(1740, 994)).perform();                

                }





            }

        } catch (MalformedURLException e) {
            System.out.println(e.getMessage());
        }       

    }

}

这是我在 Eclipse 中的错误日志:

Exception in thread "main" org.openqa.selenium.NoSuchSessionException: A session is either terminated or not started
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'LAPTOPMARTIN', ip: '192.168.178.21', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_211'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {appActivity: kr.supercreative.epic7.AppA..., appPackage: com.stove.epic7.google, clearSystemFiles: false, databaseEnabled: false, desired: {appActivity: kr.supercreative.epic7.AppA..., appPackage: com.stove.epic7.google, clearSystemFiles: false, deviceName: HUAWEI P10, noReset: true, platformName: android, platformVersion: 8.0.0, skipServerInstallation: true, udid: 6PQ0217829002238}, deviceManufacturer: HUAWEI, deviceModel: VTR-L09, deviceName: 6PQ0217829002238, deviceScreenSize: 1080x1920, deviceUDID: 6PQ0217829002238, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, noReset: true, platform: LINUX, platformName: Android, platformVersion: 8.0.0, skipServerInstallation: true, takesScreenshot: true, udid: 6PQ0217829002238, warnings: {}, webStorageEnabled: false}
Session ID: 1341c917-75bc-4988-a5bf-854c9affb81f
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at io.appium.java_client.PerformsTouchActions.performTouchAction(PerformsTouchActions.java:41)
    at io.appium.java_client.TouchAction.perform(TouchAction.java:187)
    at test.main.main(main.java:65)

最佳答案

检查您的方案配置。

只是将其放在这里以防其他人发现它有值(value)。就我而言,方案配置中使用的是 platformname 而不是 platformName(注意大写“N”)。

关于java - 修复此appium错误: "A session is either terminated or not started",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55995876/

相关文章:

android - Windows 和 Android 应用程序是否需要 SSL?

java - 有没有人尝试过为 appium 移动应用程序自动化创建本地设备实验室

java - 对测试失败进行截图

java - Appium/ Selenium : testNG parallel execution not working

java - 计数输出不正确

java - 基本 Java 程序给出错误的输出

android - Twilio 安卓 : Issue in joining a channel : "Member already exists"

java - 如何在myBatis Mapper中调用多表插入?

java - 如何在 openshift tomcat 7(JBoss EWS 2.0) 服务器上获取真实路径

java - 警报对话框样式不更改多选项目文本颜色