AppiumDriver gives null pointer exception

前端 未结 1 1847
面向向阳花
面向向阳花 2021-01-28 01:06

In my appium + testng app, what I have put is:

package com.tribehr.ios.ios_test;
import java.net.URL;
import io.appium.java_client.AppiumDriver;
import org.junit         


        
相关标签:
1条回答
  • 2021-01-28 01:36

    Surround "driver" with an if statement, to understand whether it == null.

    if(driver!=null){
        System.out.println("driver does not == null");
        driver.findElement(By.xpath("YourXpath"));
    } else {
        System.out.println("driver == null")
    }
    

    Here are my capabilities Working with appium 1.2*

    public WebDriver appiumCapabilities() {
        File appDir = new File(System.getProperty("user.dir"), "/app/");
        File app = new File(appDir, "test.app");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
        capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
        capabilities.setCapability("platformName", "iOS");
        capabilities.setCapability("deviceName", "iPod");
        capabilities.setCapability("platformVersion", "7.1");
        capabilities.setCapability("device", "iphone");
        capabilities.setCapability("udid", "cd827d3778cfdee2fc7210f8f44184821a083c06");
        capabilities.setCapability("app", app);
    
        try {
            driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return driver;
    }
    
    0 讨论(0)
提交回复
热议问题