Qi Horst
Qi Horst

Reputation: 71

Fix this appium error: "A session is either terminated or not started"

I get a this error code and can't find any solution:

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

I tried to find some infos on the Internet, but I don't find any according to my problem.

I try to automate a little part of the game Epic Seven, using appium, and some hard coded variables. I don't know if there is any problem in my Capabilities but I think not, because it works great in the Inspektor Session. So I thinnk there must be a problem in my code, logic, or the installation of my drivers.

My code:

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());
        }       

    }

}

And here my error log in 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)

Upvotes: 7

Views: 18150

Answers (2)

grandEL-dsouza
grandEL-dsouza

Reputation: 50

This error generally occurs if there are certain commands that try to interact with the driver after the driver instance is closed.

Basically, all the commands are called after the driver.quit() will yield this error.

Upvotes: 0

Joshua Pinter
Joshua Pinter

Reputation: 47581

Check your scheme configuration.

Just putting this here in case someone else finds it valuable. In my case I had platformname instead of platformName (notice the capital "N") in the scheme configuration.

Upvotes: -2

Related Questions