在使用Appium的同时运行我的testNG时应用程序崩溃

时间:2017-02-01 09:59:51

标签: android automation appium

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

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 

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

2 个答案:

答案 0 :(得分:1)

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

我正在使用的解决方法:

  1. 在开始执行之前关闭所有UIAutomator实例。
  2. 通过AppiumDriverLocalService启动appium服务器(非手动);
  3. 增加新命令的超时(我们需要在DesiredCapabilities中指定)。
  4. 你可以试试这个

答案 1 :(得分:0)

我只需删除driver.wait(10000);

即可解决问题