Is it possible to automate hybrid apps using appium driver?

in my app, first page is a native page and the second is a web page. So I tried to switch contexts using, adriver.context(“WEBVIEW_0”); or adriver.context(“WEBVIEW”); methods. But the console throws an error saying the context cannot be found. Any idea?

@NDL,

I know this may sound like a silly question, but have you tried calling the getContextHandles() method as soon as you land on your web page?

I had similar issues with switching contexts, that were ultimately due to the WEBVIEW context being displayed only 50% of the time.

You may also find the following page useful: https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/hybrid.md

1 Like

I have successfully automated my hybrid app. Here is the method that I use to switch to the web view and invoke commands upon it.

        driver.context("WEBVIEW_2"); //This context can be found in the appium inspector when inspecting your app

        System.out.println("Current context is: " + driver.getContext()); //Just checking that it was changed

        driver.switchTo().frame("manageFrame"); //If your app contains frames, this switched to it

        driver.findElement(By.xpath("//div[@id='accountList']/div[1]/div[1]/div[1]/a")).click(); //Click edit

        Thread.sleep(20000);

         WebElement editESecurity = driver.findElement(By.xpath("//div[contains(@class,'enhancedSecurity')]//a[@class='editSection']"));

            ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);" , editESecurity); //This makes it so that the element you are trying to tap is in the view.

            editESecurity.click();

            Thread.sleep(2000)

        driver.switchTo().defaultContent();

        driver.context("NATIVE_APP"); //Changes back to the native applications

I also use the developer menu in OS X Safari to inspect the web view within the application.

Hope this helps

1 Like