package zy.com.Public;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
public class TestBase {
public static void init(Mydriver driver) {
System.out.println("ggggg");
try {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "apps");
File app = new File(appDir, "Androidtest.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "75UBBKP22AGS");
capabilities.setCapability("app", app.getAbsolutePath());
// capabilities.setCapability(CapabilityType.PLATFORM, "ANDROID");
capabilities.setCapability("app-package", "com.android.test");
capabilities.setCapability("app-activity", "com.android.test.ui.splash.SplashActivity");
driver = new Mydriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class AppTest
extends TestCase
{
public static Mydriver driver = null;
ParseXml xml = new ParseXml();
HashMap<String, String> id = xml.readXml();
@BeforeClass
public void setUp(){
TestBase.init(driver);
}
@AfterClass
public void tearDown() throws Exception {
driver.quit();
}
public void testBegin()throws Exception{
Thread.sleep(5000);
for(int i=0;i<=6;i++){
publicMethod.scrollTo(driver);
Thread.sleep(3000);
}
WebElement el = driver.findElement(By.id(id.get("Slpash_begin")));
Thread.sleep(1000);
el.click();
Thread.sleep(4000);
}
报错信息:
FAILED CONFIGURATION: @AfterClass tearDown
java.lang.NullPointerException
at zy.com.test_mave.AppTest.tearDown(AppTest.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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)