gpt4 book ai didi

java - 执行Java程序appium出错及其他异常

转载 作者:行者123 更新时间:2023-12-02 01:00:01 25 4
gpt4 key购买 nike

我正在尝试执行以下代码

public static void main(String[] args) throws MalformedURLException {

AndroidDriver<AndroidElement>  driver=Capabilities();
       
      //xPath id className, androidUIautomator  //tagname[@attribute='value']

//Registration of the device
//driver.findElementByXPath("//android.widget.EditText[@resource-id='iMSSO_Alert1_Continue_button']").click();

//driver.findElementByXPath("//android.widget.EditText[@resource-id='btnAgree']").click();


driver.findElementByXPath("//android.widget.EditText[@resource-id='USER']").sendKeys("aris");
driver.findElementByXPath("//android.widget.EditText[@resource-id='PASSWORD']").sendKeys("kKL2WBU7ggCeMh4izUY4Kg==");
driver.findElementByXPath("//android.widget.EditText[@resource-id='btnLogin']").click();

}}




package appiumsample1;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
 
public class base1 {

public static AndroidDriver<AndroidElement> Capabilities() throws MalformedURLException {


DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "My tab");
caps.setCapability("udid", "ce12182cabcaaa27017e"); //Give Device ID of your mobile phone/name of the device
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "8.1.0");
caps.setCapability("appPackage", "com.verizon.launcher.sdnasit");
caps.setCapability("appActivity", "com.verizon.launcher.webview.WebActivity");
caps.setCapability("noReset", "true");


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



/*public static void main(String[] args) {

//Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "My Phone");
caps.setCapability("udid", "ce12182cabcaaa27017e"); //Give Device ID of your mobile phone/name of the device
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "8.1.0");
caps.setCapability("appPackage", "com.verizon.launcher.sdnasit");
caps.setCapability("appActivity", "com.verizon.launcher.webview.WebActivity");
caps.setCapability("noReset", "true");





//Instantiate Appium Driver
try {
AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);

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


// UI Automator tool

}

异常

remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Cannot start the 'com.verizon.launcher.sdnasit' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Error executing adbExec. Original error: 'Command 'C:\Users\SINGTO2\AppData\Local\android\sdk\platform-tools\adb.exe -P 5037 -s ce12182cabcaaa27017e shell am start -W -n com.verizon.launcher.sdnasit/com.verizon.launcher.webview.WebActivity -S' timed out after 20000ms'. Try to increase the 20000ms adb execution timeout represented by 'adbExecTimeout' capability Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48' System info: host: 'TFL0074ALKVTMLM', ip: '10.69.131.113', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181' Driver info: driver.version: AndroidDriver remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Cannot start the 'com.verizon.launcher.sdnasit' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Error executing adbExec. Original error: 'Command 'C:\Users\SINGTO2\AppData\Local\android\sdk\platform-tools\adb.exe -P 5037 -s ce12182cabcaaa27017e shell am start -W -n com.verizon.launcher.sdnasit/com.verizon.launcher.webview.WebActivity -S' timed out after 20000ms'. Try to increase the 20000ms adb execution timeout represented by 'adbExecTimeout' capability     at getResponseForW3CError (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:826:9)     at asyncHandler (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:447:37)     at process._tickCallback (internal/process/next_tick.js:68:7) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48' System info: host: 'TFL0074ALKVTMLM', ip: '10.69.131.113', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181' Driver info: driver.version: AndroidDriver 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:552) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213) at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:323) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131) at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:37) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:86) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:96) at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:94) at appiumsample1.base1.Capabilities(base1.java:25) at appiumsample1.base2.main(base2.java:13) 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) ... 15 more Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Cannot start the 'com.verizon.launcher.sdnasit' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Error executing adbExec. Original error: 'Command 'C:\Users\SINGTO2\AppData\Local\android\sdk\platform-tools\adb.exe -P 5037 -s ce12182cabcaaa27017e shell am start -W -n com.verizon.launcher.sdnasit/com.verizon.launcher.webview.WebActivity -S' timed out after 20000ms'. Try to increase the 20000ms adb execution timeout represented by 'adbExecTimeout' capability Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48' System info: host: 'TFL0074ALKVTMLM', ip: '10.69.131.113', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181' Driver info: driver.version: AndroidDriver remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Cannot start the 'com.verizon.launcher.sdnasit' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Error executing adbExec. Original error: 'Command 'C:\Users\SINGTO2\AppData\Local\android\sdk\platform-tools\adb.exe -P 5037 -s ce12182cabcaaa27017e shell am start -W -n com.verizon.launcher.sdnasit/com.verizon.launcher.webview.WebActivity -S' timed out after 20000ms'. Try to increase the 20000ms adb execution timeout represented by 'adbExecTimeout' capability     at getResponseForW3CError (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:826:9)     at asyncHandler (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:447:37)     at process._tickCallback (internal/process/next_tick.js:68:7) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62) at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30) at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958) at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126) at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)

根据答案添加代码

public class base1 {

public AndroidDriver<MobileElement> driver;
        public WebDriverWait wait;
        public Dimension size;
        public String destDir;
public DateFormat dateFormat;

public (swipe) {
};


public (takeScreenShot) {
};

@BeforeMethod

public void setup () throws MalformedURLException {

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "My tab");
caps.setCapability("udid", "ce12182cabcaaa27017e"); //Give Device ID of your mobile phone/name of the device
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "8.1.0");
caps.setCapability("skipUnlock","true");
caps.setCapability("appPackage", "com.verizon.launcher.sdnasit");
caps.setCapability("appActivity", "com.verizon.launcher.webview.WebActivity");
caps.setCapability("noReset", "true");
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"),caps);
wait = new WebDriverWait(driver, 10);

}

@Test
     public void test () throws Exception {

    //Test commands
    }

@AfterMethod

    public void teardown(){
        driver.quit();
    }

/*public AndroidDriver<AndroidElement> Capabilities() throws MalformedURLException {


DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "My tab");
caps.setCapability("udid", "ce12182cabcaaa27017e"); //Give Device ID of your mobile phone/name of the device
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "8.1.0");
caps.setCapability("skipUnlock","true");
caps.setCapability("appPackage", "com.verizon.launcher.sdnasit");
caps.setCapability("appActivity", "com.verizon.launcher.webview.WebActivity");
caps.setCapability("noReset", "true");


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

wait = new WebDriverWait(driver, 10);*/




}

最佳答案

1- 首先检查appium是否正在运行。

2- 如果是,您应该知道有时 Node.js 无法与 127.0.0.1:4723 通信,因此请使用 0.0.0.0:4723 代替。请记住在代码 (DesiredCapability) 和 appium 设置中更改此设置。

3- 您应该保持如下所示的代码结构。还需要使用这 3 个符号:(@BeforeMethod , @Test, @AfterMethod)

类似这样的事情:

 import <...>
.
.

public class sample { //this is the main class. You shouldn't define it as static or void so you must not have main methode
//define variables you will be use during the test
public AndroidDriver<MobileElement> driver;
public WebDriverWait wait;
public Dimension size;
public String destDir;
public DateFormat dateFormat;
.
.
.
//define the methodes you will be use during the test
public (swipe) {
... };
public (takeScreenShot) {
...};

@BeforeMethod

public void setup () throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Galaxy S7 API 26");
caps.setCapability("udid", "ce0217124184c72505"); //DeviceId from "adb devices" command
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "8.0");
caps.setCapability("skipUnlock","true");
caps.setCapability("appPackage", "app_packageName"); // Your app packageName
caps.setCapability("appActivity","app_first_activity"); // The first activity of app. You can use "Apk Info2" application to find this
caps.setCapability("noReset","false");
driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"),caps);
wait = new WebDriverWait(driver, 10);
}

@Test
public void test () throws Exception {

//Test commands
}

@AfterMethod

public void teardown(){
driver.quit();
}

我希望这有帮助。

关于java - 执行Java程序appium出错及其他异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57777186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com