2016-01-16 76 views
0

我想了解一個測試Android應用程序的工具。經過一番Google搜索,我來到了這個叫做Appium的奇妙工具,它用於測試Android應用程序,也是一個開源軟件。我想了解它。所以我繼續創建了一個簡單的android應用程序,只需點擊幾下按鈕即可開始測試。在Eclipse中測試Android應用程序失敗使用Appium

我已經做了所有的以下內容:

  1. 在所有必要的jar的插入了的Eclipse IDE
  2. 下載並安裝Appium服務器。
  3. 插入MavenTestNG對於Eclipse
  4. 成功將SampleApp.apk安裝到仿真器中。

接下來我創建了一個TestNG類來測試SampleApp.apk。代碼粘貼在下面。然而,在運行我收到的應用程序java.lang.NullPointerException。已經兩天了。我嘗試了一切,構建,清理,重新啓動eclipse,創建一個新的應用程序,重新安裝所有依賴項。但是我仍然收到同樣的例外。我已經通過Execute Automation轉介了視頻,並做了完全相同的減去在我的情況不同的應用程序。

package com.example.appium; 

import java.net.MalformedURLException; 
import java.net.URL; 
import io.appium.java_client.AppiumDriver; 
import io.appium.java_client.android.AndroidDriver; 
import io.appium.java_client.remote.MobileCapabilityType; 
import org.junit.BeforeClass; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.remote.DesiredCapabilities; 
import org.testng.Assert; 
import org.testng.annotations.Test; 

public class TestJavaAppium { 

    AppiumDriver<WebElement> driver; 

    @BeforeClass 
    public void Setup() throws MalformedURLException{ 

     DesiredCapabilities capability = new DesiredCapabilities(); 
     capability.setCapability(MobileCapabilityType.DEVICE_NAME, "Emulator"); 
     capability.setCapability(MobileCapabilityType.APP_PACKAGE, "com.example.sampleapp"); 
     capability.setCapability("avd", "Emulator4.2");   
     driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4273/wd/hub"), capability); 
    } 

    @Test 
    public void simpleTest() { 

     Assert.assertNotNull(driver.getContext()); 
    } 
} 

我的Appium配置如下,以確保我所有的信息都正確。 enter image description here

理想情況下,應該運行代碼併成功啓動應用程序(至少在視頻中)。但我收到的卻是下面的例外情況:

[TestNG] Running: 
    C:\Users\KC\AppData\Local\Temp\testng-eclipse-518994855\testng-customsuite.xml 

FAILED: simpleTest 
java.lang.NullPointerException 
    at com.example.appium.TestJavaAppium.simpleTest(TestJavaAppium.java:37) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85) 
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639) 
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821) 
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131) 
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124) 
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) 
    at org.testng.TestRunner.privateRun(TestRunner.java:773) 
    at org.testng.TestRunner.run(TestRunner.java:623) 
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:357) 
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352) 
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310) 
    at org.testng.SuiteRunner.run(SuiteRunner.java:259) 
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) 
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185) 
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1110) 
    at org.testng.TestNG.run(TestNG.java:1018) 
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111) 
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204) 
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175) 


=============================================== 
    Default test 
    Tests run: 1, Failures: 1, Skips: 0 
=============================================== 


=============================================== 
Default suite 
Total tests run: 1, Failures: 1, Skips: 0 
=============================================== 

[TestNG] Time taken by [email protected]: 225 ms 
[TestNG] Time taken by [email protected]: 230 ms 
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 26 ms 
[TestNG] Time taken by [email protected]: 14 ms 
[TestNG] Time taken by [email protected]: 14 ms 
[TestNG] Time taken by [email protected]: 12 ms 

在哪裏我可能會錯誤地憤怒我的Eclipse?

+0

你的代碼看起來不錯,可你把一些迫不及待地推出應用程序 –

+0

你能否提供一些更多的功能,到Appium服務器,如app的activityName。 'capa.setCapability(「appActivity」,「.LauncherActivity」);'根據你的應用改變活動名稱。你可以看看示例程序@ http://mylearningdiaree.blogspot.in/2015/06/appium-sample -demo-program-of-android_11.html – workspace

+0

需要爲通過Appium啓動的Android應用提供appPackage和appActivity。 – Smriti

回答

0

代碼看起來不錯。提供應用程序活動。

0

相反的APP_PACKAGE,您可以使用您的PC .apk文件完整路徑設置Appium:

capability.setCapability(MobileCapabilityType.APP, "/full/path/to/app.apk"); 
相關問題