我收到此错误代码,找不到任何解决方案:
Exception in thread "main" org.openqa.selenium.NoSuchSessionException: A session is either terminated or not started
我试图在Internet上找到一些信息,但是根据我的问题我找不到任何信息。
我尝试使用appium和一些硬编码变量使Epic Seven游戏的一部分自动化。我不知道我的功能是否有任何问题,但我认为没有,因为它在Inspektor会话中效果很好。因此,我认为我的代码,逻辑或驱动程序安装中肯定有问题。
我的代码:
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)
答案 0 :(得分:0)
只要把它放在这里,以防别人发现它有价值。在我的情况下,方案配置中使用的是platformname
而不是platformName
(注意大写的“ N”)。