【问题标题】:First test fails on IntelliJ IDEA + AppiumIntelliJ IDEA + Appium 的第一次测试失败
【发布时间】:2016-11-20 08:12:47
【问题描述】:

我是自动化的新手。我已经为测试自动化设置了一个环境,但是我无法运行我的第一个测试,每次运行都会出现错误。不知道它是什么,请帮助我 这是我的代码:

import io.appium.java_client.android.AndroidDriver;
import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;

public class FirstTest {

    AndroidDriver androidDriver;

    @Before
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("devicename", "Testdevice");
        androidDriver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

    }

    @Test
    public void logInCheck() throws Exception {
        androidDriver.findElement(By.id("com.example.mariia.testing:id/button")).click();
    }

    @After
    public void tearDown() throws Exception {
        androidDriver.quit();
    }
}

这是我收到的错误:

java.lang.NullPointerException
at FirstTest.logInCheck(FirstTest.java:34)
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:498)
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:124)
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:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

【问题讨论】:

    标签: java intellij-idea automation testng appium


    【解决方案1】:

    您尚未设置功能platformNameplatformVersionappdeviceName。您正在测试 Android 应用,因此您需要提供额外的功能 appActivityappPackage

    【讨论】:

      【解决方案2】:
      DesiredCapabilities caps = new DesiredCapabilities();
      caps.SetCapability("app-package", "com.myapp.test");
      caps.SetCapability("browserName", "");
      caps.SetCapability("device", "Android");
      caps.SetCapability("app-activity", "com.myapp.SplashActivity");
      caps.SetCapability("version", "4.1.2");
      caps.SetCapability("device ID", "uniquedeviceid");
      caps.SetCapability("app", "apk-path");
      

      要缩小您的问题范围,请提供您的 testng.xml 文件。

      【讨论】:

        猜你喜欢
        • 2012-08-14
        • 1970-01-01
        • 2020-03-15
        • 2016-04-26
        • 1970-01-01
        • 2021-07-03
        • 1970-01-01
        • 1970-01-01
        • 2015-07-29
        相关资源
        最近更新 更多