我的appium的第二个测试不断获得java null点异常

时间:2014-11-25 04:52:02

标签: java junit selenium-webdriver appium

我正在尝试创建一个框架来测试跨平台的移动网络应用程序(非本机)。以下是我的代码设置方式:

测试类:

 public class TestSuite extends MobileLibrary{

    @BeforeClass
    public static void setUpTests() throws Exception {
        setUp();

    }  

    @AfterClass
    public static void cleanUpTests() throws Exception {
        driver.quit();
    }



    @Test
    public void validateSignIn() throws Exception
    {

        String username = "testtest";
        String password = "testtest";
        SignInMobile(driver,username,password);
        assertTrue(true);

    }
    @Test
    public void randomTests() throws Exception

        dbcSelector(driver,"test");
        assertTrue(true);
    }


}

基类

public class SetupBase 
{

    protected static AppiumDriver driver;
    protected static AppiumPlatform appiumPlatform;
    protected static DeviceSize deviceSize;
    protected static DeviceName deviceName;
    protected static String deviceID;
    protected static DesiredCapabilities capabilities;
    protected static enum AppiumPlatform{
        DESKTOP,IOS,ANDROID
    }
    protected static enum DeviceSize{
        SMALL,MEDIUM,LARGE
    }
    protected static enum DeviceName{
        NEXUS7,S5,IPHONE5S
    }
    public static void setUp() throws MalformedURLException /*throws Exception*/ {



    String deviceNameEnv = System.getenv("DEVICENAME");
    switch(deviceNameEnv){
        //sets devicename here
    }
    //sets platform here
    if(deviceName==DeviceName.NEXUS7 || deviceName==DeviceName.S5)
        appiumPlatform = AppiumPlatform.ANDROID;
    else if(deviceName==DeviceName.IPHONE5S)
        appiumPlatform = AppiumPlatform.IOS;
    else
        appiumPlatform = AppiumPlatform.DESKTOP;

    switch(deviceName){     
        //sets size here
    }

    capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName",deviceID);

    if(appiumPlatform==AppiumPlatform.ANDROID){
        capabilities.setCapability("platformName","Android");
        capabilities.setCapability("browserName","Chrome");
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }
    else if(appiumPlatform==AppiumPlatform.IOS){
        capabilities.setCapability("platformName","iOS");
        capabilities.setCapability("browserName","Safari");
        driver  = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }


    }
}

无论我做什么,每当我尝试在第二次测试中使用驱动程序时,我都会得到一个java null指针异常。 MobileLibrary扩展了基类并包含了我的所有WebDriver元素函数。

编辑:如果我在第二次测试中直接执行driver.findelement,我会得到一个未找到元素的异常。在@test结束后看起来有些东西正在重置,我不知道是什么。

1 个答案:

答案 0 :(得分:0)

我发现问题实际上是@test订单执行。我没有意识到junit没有按顺序运行测试,我会调查测试套件。