1
votes
    private WebDriver driver;

    @BeforeMethod
    public void setUp() throws Exception {

        // set up appium
        BasicConfigurator.configure();
        File appDir = new File("This PC\\GT-I9100\\Phone\\360");
        File app = new File(appDir, "app-release.apk"); //my case “demo1.apk”
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("device","Android");
        capabilities.setCapability(CapabilityType.BROWSER_NAME,  "");
        capabilities.setCapability(CapabilityType.VERSION, "4.2");
        capabilities.setCapability(CapabilityType.PLATFORM, "WINDOW");
        capabilities.setCapability("app", app.getAbsolutePath());
        capabilities.setCapability("app-package", "app-release.apk");  //my case com.gorillalogic.monkeytalk.demo1
        capabilities.setCapability("app-activity", "Login");  //my case RootActivity
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

    }

    @AfterMethod
    public void tearDown() throws Exception {
        driver.quit();
    }

    @Test
    public void loginTest() throws Throwable
    {    
     System.out.println("Hello");
     System.out.println(driver);
     setUp();
    }

    @Test
    public void formTest() throws InterruptedException
    {    
        System.out.println("Hello");
         System.out.println(driver);

/*Getting driver value as null in selenium web driver for appium mobile automation testing

Getting driver value as null. Used device name then also i am getting null value I have connected my real device.*/

1

1 Answers

1
votes

Add a try/catch block when instantiating the AndroidDriver() ...

Maybe there is something wrong there. Try this code

    new DesiredCapabilities();
    DesiredCapabilities capabilities = DesiredCapabilities.android();

    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
    capabilities.setCapability(MobileCapabilityType.BROWSER_NAME,"Chrome"); 
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"0123456789ABCDEF");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION,"4.4");

    try 
    {
        linker = new URL("http://127.0.0.1:4723/wd/hub");
        driver = new AndroidDriver(linker, capabilities);
        driver.manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
    }
    catch (MalformedURLException e) 
    {
        System.out.println("URL init error");
    }

Cheers