gpt4 book ai didi

android - 我在使用 Appium 时运行 testNG 时应用程序崩溃

转载 作者:行者123 更新时间:2023-11-30 00:44:47 30 4
gpt4 key购买 nike

我有一个问题,我的代码在这里配置正确:

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

public class Newlook_1 {

AndroidDriver<AndroidElement> driver;

File path = new File(
"/home/emna/Téléchargements/AutomationFiles/app-debug.apk");

@BeforeClass
public void setUp() throws MalformedURLException {

System.out.println("app Dir.--->" + path);

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "SM-G531H");
capabilities.setCapability("version", "5.1.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("device", "Android");
capabilities.setCapability("platformVersion", "platform");
capabilities.setCapability("udid", "***********");
capabilities.setCapability("app", path.getAbsolutePath());
capabilities.setCapability("appPackage", "com.bulldozer.newlook");
capabilities.setCapability("appActivity", "com.bulldozer.newlook.activities.SplashActivity");
capabilities.setCapability("noReset", "false");
driver = new AndroidDriver<AndroidElement>(new URL(
"http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(1500, TimeUnit.SECONDS);


}

@Test
public void Test1() throws InterruptedException {

driver.wait(10000);
System.out.println("newlook-tutoriel");
driver.findElement(By.id("skip")).click();
System.out.println("newlook-welcome");
driver.wait(1000);
driver.findElement(By.id("btn_signin_welcome")).click();
System.out.println("newlook-Me connecter");
driver.findElement(By.id("input_email")).sendKeys("e@e.emmna.com");
driver.findElement(By.id("input_password")).sendKeys("00000000");
}

@AfterClass
public void tearDown() {
driver.quit();

}

}

当我使用 npm 运行 appium 时:

appium -a 127.0.0.1

看起来应用程序在启动一段时间后崩溃了!

这是我的 appium 日志文件,它告诉我在 java 中添加了一个 IllegalMonitorStateException :

[debug] [ADB] Running '/home/emna/Android/Sdk/platform-tools/adb' with args: ["-P",5037,"-s","********","shell","am","force-stop","com.bulldozer.newlook"]
[debug] [ADB] Pressing the HOME button
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/home/emna/Android/Sdk/platform-tools/adb' with args: ["-P",5037,"-s","************","shell","input","keyevent",3]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Closed client connection
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: numtests=1
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=.
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: current=1
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: 0
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=
[debug] [AndroidBootstrap] [UIAUTO STDOUT] Test results for WatcherResultPrinter=.
[debug] [AndroidBootstrap] [UIAUTO STDOUT] Time: 12.803
[debug] [AndroidBootstrap] [UIAUTO STDOUT] OK (1 test)
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: -1
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [UiAutomator] Shutting down UiAutomator
[debug] [UiAutomator] Moving to state 'stopping'
[debug] [UiAutomator] UiAutomator shut down normally
[debug] [UiAutomator] Moving to state 'stopped'
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/home/emna/Android/Sdk/platform-tools/adb' with args: ["-P",5037,"-s","******","shell","ps"]
[ADB] No uiautomator process found to kill, continuing...
[debug] [UiAutomator] Moving to state 'stopped'
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/home/emna/Android/Sdk/platform-tools/adb' with args: ["-P",5037,"-s","4b13731fdfdd824e","shell","am","force-stop","io.appium.unlock"]
[debug] [Logcat] Stopping logcat capture
[debug] [AndroidDriver] Not cleaning generated files. Add `clearSystemFiles` capability if wanted.
[Appium] Removing session 7fe5b58a-8d00-4f8a-9aa8-f61f2d374eb6 from our master session list
[debug] [MJSONWP] Received response: null
[debug] [MJSONWP] But deleting session, so not returning
[debug] [MJSONWP] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /wd/hub/session/7fe5b58a-8d00-4f8a-9aa8-f61f2d374eb6 200 2319 ms - 76

我该如何解决这个问题?我应该重新启动远程 session 吗?预先感谢您提出的任何解决方案:)

最佳答案

我也遇到了同样的问题。但是,并非所有设备都会发生这种情况。

我正在使用的解决方法:

  1. 在开始执行之前关闭 UIAutomator 的所有实例。
  2. 通过AppiumDriverLocalService(非手动)启动appium server;
  3. 增加新命令的超时时间(我们需要在 DesiredCapabilities 中指定)。

你可以试试这个

关于android - 我在使用 Appium 时运行 testNG 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41976782/

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