2016-06-22 5 views
0

테스트를 작성하기 위해 Appium 및 IntelliJ를 사용하여 테스트를 수행하려는 app komoot가 포함 된 Android Phone 에뮬레이터를 설정했습니다. 나는 맥북 에어에서 일하고있다. 데 후 : 내 안드로이드 에뮬레이터를 시작, Appium 서버를 시작하고 IntelliJ에 내 테스트 (자바에서) 작성, 내 테스트를 실행하고 첨부 된 그림에 표시된 오류가 발생합니다. 나는 또한 내 간단한 테스트 스크립트와 내 테스트 "komootTest"를 실행하여 발생하는 오류 로그 메시지를 복사/붙여 넣기했습니다.IntelliJ (OSX)에서 Android 테스트를 실행하면 java.lang.NullPointerException이 발생합니다.

나는 던져지고있는 과실에 관하여 혼동한다. 44 번째 줄에 나와 있듯이 올바른 id를 가진 komoot (로그인 버튼)의 요소 인 변수를 인스턴스화합니다. 이 경우 왜 null 예외가 발생합니까? 필요에 따라 더 자세한 정보를 제공 할 수 있습니다. 감사합니다. 내가 komootTest.java을 실행할 때


다음
import io.appium.java_client.AppiumDriver; 
import io.appium.java_client.android.AndroidDriver; 
import org.junit.After; 
import org.junit.Before; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.remote.DesiredCapabilities; 
import org.testng.annotations.Test; 
import java.net.URL; 

public class komootTest 
{ 
    AppiumDriver driver; 

    @Before 
    public void setUp() throws Exception 
    { 
     //set desired capabilities and specify device name 
     DesiredCapabilities capabilities = new DesiredCapabilities(); 
     capabilities.setCapability("deviceName", "BigBrother Emulator"); 

     //capabilities.setCapability("appPackage", "de.komoot.android"); 
     //capabilities.setCapability("appActivity", "com.google.android.gms.auth.api.signin.internal.SignInHubActivity"); 

     //establish a connection with the server 
     driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 
    } 

    @After 
    public void end() throws Exception 
    { 
     //kill connection with server after test has been executed 
     driver.quit(); 
    } 

    @Test 
    public void logInHereButton() 
    { 
     //reference UI element by ID and click it 
     WebElement logInHere = driver.findElement(By.id("de.komoot.android:id/textview_login")); 
     logInHere.click(); 
    } 
} 

오류 메시지입니다 : 여기

komootTest.java code image

error log image

내 테스트 komootTest.java 코드입니다 :

,
[TestNG] Running: 
    /Users/coracoleman/Library/Caches/IdeaIC2016.1/temp-testng-customsuite.xml 

java.lang.NullPointerException 
    at komootTest.logInHereButton(komootTest.java:44) 
    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:497) 
    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:816) 
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124) 
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) 
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) 
    at org.testng.TestRunner.privateRun(TestRunner.java:774) 
    at org.testng.TestRunner.run(TestRunner.java:624) 
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359) 
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354) 
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312) 
    at org.testng.SuiteRunner.run(SuiteRunner.java:261) 
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) 
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215) 
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140) 
    at org.testng.TestNG.run(TestNG.java:1048) 
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:74) 
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:121) 
    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:497) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) 


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


Process finished with exit code 0 

+0

이미지 대신, 질문에 코드를 넣어야합니다. –

+0

코드가 질문의 범위를 벗어났습니다 –

+0

모든 라이브러리/드라이버를 올바르게 설치 했습니까? –

답변

0

과제를 해결한다! 필자는 IntelliJ에서 Maven과 Java를 선택하는 대신 새로운 프로젝트를 시작하여 프로젝트를 다시 작성했습니다. 필자는 아래에 포함 된 것처럼 pom.xml 파일에 종속성을 가져 왔습니다. 내 능력을 완전히 지정하지 않았고 pom.xml 파일에 내 의존성을 포함시키지 않았습니다. 프로젝트 구조/프로젝트 설정/라이브러리에 java-client-4.0.0.jar 및 selenium 독립 실행 형 서버 .jar 파일을 포함 시켰습니다.

다음
package scenarios; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.remote.DesiredCapabilities; 
import org.openqa.selenium.remote.RemoteWebDriver; 
import org.testng.annotations.Test; 
import java.net.URL; 
import java.util.concurrent.TimeUnit; 


public class AndroidSetup 
{ 
    WebDriver driver; 

    @Test 
    public void setUp() throws Exception 
    { 
     //create object of DesiredCapabilities class 
     DesiredCapabilities capabilities = new DesiredCapabilities(); 

     //set android deviceName desired capability 
     capabilities.setCapability("deviceName", "BigBrother Emulator"); 

     //set browserName desired capability 
     capabilities.setCapability("browserName", "Android"); 

     //set android platformVersion desired capability 
     capabilities.setCapability("platformVersion", "5.1"); 

     //set android platformName desired capability 
     capabilities.setCapability("platformName", "Android"); 

     //set android appPackage desired capability 
     capabilities.setCapability("appPackage", "de.komoot.android"); 

     //set android appActivity desired capability 
     capabilities.setCapability("appActivity", "de.komoot.android.app.InspirationActivity"); 

     //set appium server address and port number in URL string 
     //this will launch app in emulator 
     driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 
     driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); 

     //click on LogIn button 
     driver.findElement(By.id("de.komoot.android:id/textview_login")).click(); 
     driver.quit(); 
    } 
} 

이 결과 실행 로그입니다 : 여기

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.example</groupId> 
    <artifactId>AppiumTest2</artifactId> 
    <version>1.0-SNAPSHOT</version> 

    <dependencies> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-java</artifactId> 
      <version>2.53.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.testng</groupId> 
      <artifactId>testng</artifactId> 
      <version>6.1.1</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>io.appium</groupId> 
      <artifactId>java-client</artifactId> 
      <version>4.0.0</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

</project> 

내가 성공적으로 실행 할 수 있었다 간단한 코드입니다 : 여기

내 pom.xml 파일의 내용입니다

[TestNG] Running: 
    /Users/coracoleman/Library/Caches/IdeaIC2016.1/temp-testng-customsuite.xml 

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


Process finished with exit code 0 
+0

또한 Appium 서버가 테스트 실행 사이에 새로 실행되고 있는지 확인해야했습니다. 필자는 매번 새로운 서버 세션을 시작하기 전에 서버가 실행되고 있지 않은지 (adb kill-server 입력) 터미널을 점검하고 새로운 Appium을 시작하여 테스트를 실행했습니다. –

관련 문제