【问题标题】:Application crash at the moment i run my testNG while using Appium我在使用 Appium 时运行我的 testNG 时应用程序崩溃
【发布时间】:2017-06-18 00:33:16
【问题描述】:

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

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 

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

【问题讨论】:

    标签: android automation appium


    【解决方案1】:

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

    我正在使用的解决方法:

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

    你可以试试这个

    【讨论】:

    • 我已删除 driver.wait(10000);一切都很好 !感谢任何方式
    • @Emna 为什么要使用wait(10000)?您可以使用 flexiWait,无需每次等待 10000。如果是具体要求,那很好。
    • 因为启动画面需要太多时间,但现在即使我将它们全部删除也很好。一开始我添加它们是因为闪屏
    • @Emna 我可以再给你推荐一件事吗?
    • @Emna 正如我在您的代码中看到的,您正在使用“app”功能,其中您提到了 apk 文件的路径。如果您提到这一点,appium 将在您每次实例化 appium 驱动程序时将文件复制到设备并安装。这通常需要大约 30 秒到 1 分钟,具体取决于 apk 大小。您可以通过在设备上仅安装一次应用并删除“应用”功能来避免这种情况。
    【解决方案2】:

    我只是通过删除来解决它:driver.wait(10000);

    【讨论】:

      猜你喜欢
      • 2016-12-30
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-29
      • 1970-01-01
      相关资源
      最近更新 更多