获取FAILED CONFIGURATION:@AfterClass拆解appium中的错误

时间:2015-09-22 18:49:22

标签: java android eclipse automation appium

我在appium中获得 CONFIGURATION:@AfterClass拆解和失败:testCal 错误。如何解决此问题?我使用TestNG运行我的测试。请在下面找到详细信息:

package Appium;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.openqa.selenium.remote.CapabilityType;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileBrowserType;
import java.net.URL;

public class AppiumPOC {


        WebDriver driver;

        @BeforeClass
        public void Appium() throws MalformedURLException{

            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("device", "Android");
            capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
            capabilities.setCapability(CapabilityType.VERSION, "4.2.2");
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("deviceName","4100a9102db72100");
            capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");


            capabilities.setCapability("app", "chrome");
            WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);



          }

        @Test
        public void testCal()
        {
            driver.get("http://google.com");

        }

        @AfterClass
        public void teardown(){
            //close the app
            driver.quit();
        }
    }

请在下面找到控制台消息。我使用TestNg运行方法进行了测试,在不同的平台上尝试过,我仍面临同样的问题。

[TestNG] Running:
  C:\Users\Manoj\AppData\Local\Temp\testng-eclipse-1668712669\testngcustomsuite.xml
FAILED CONFIGURATION: @AfterClass teardown
java.lang.NullPointerException
  at Appium.AppiumPOC.teardown(AppiumPOC.java:55)
  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:84)
  at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
  at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
  at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
  at org.testng.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:225)
  at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:114)
  at org.testng.TestRunner.privateRun(TestRunner.java:767)
  at org.testng.TestRunner.run(TestRunner.java:617)
  at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
  at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
  at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
  at org.testng.SuiteRunner.run(SuiteRunner.java:240)
  at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
  at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
  at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
  at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
  at org.testng.TestNG.run(TestNG.java:1057)
  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)

FAILED: testCal
java.lang.NullPointerException
  at Appium.AppiumPOC.testCal(AppiumPOC.java:48)
  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:84)
  at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
  at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
  at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
  at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
  at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
  at org.testng.TestRunner.privateRun(TestRunner.java:767)
  at org.testng.TestRunner.run(TestRunner.java:617)
  at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
  at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
  at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
  at org.testng.SuiteRunner.run(SuiteRunner.java:240)
  at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
  at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
  at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
  at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
  at org.testng.TestNG.run(TestNG.java:1057)
  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
    Configuration Failures: 1, Skips: 0
===============================================


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

[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@61064425: 18 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@6a6824be: 89 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@77556fd: 119 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 12 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@2f333739: 28 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@6ed3ef1: 19 ms

2 个答案:

答案 0 :(得分:1)

好。它现在在我这边工作。只需删除" WebDriver"从这一行:

 driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

答案 1 :(得分:0)

如果我在创建新的ChromeDriver的对象时删除了“ WebDriver”,则对我有用。

driver=new ChromeDriver();

Code Snippet