Friday, May 2, 2025

android – Appium caught after context change from native to webview


I’m testing a Hybrid Android app – Tubemate in Appium.

I am utilizing the next configuration:

  1. selenium-java = model 3.0.1
  2. appium java-client = model 4.1.2
  3. chromedriver = model 2.19
  4. Android = 6.0.1 Marshmallow
  5. Chrome Webview = model 44.0.2403.119

All the pieces is the newest model from mvn repository.

The next Java Code is used.

package deal tk.sathyacse67.tcs;

import org.testng.annotations.Take a look at;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;

import org.testng.annotations.BeforeMethod;

import java.internet.MalformedURLException;
import java.internet.URL;
import java.util.Listing;
import org.openqa.selenium.By;
import org.openqa.selenium.distant.DesiredCapabilities;
import org.openqa.selenium.assist.ui.ExpectedConditions;
import org.openqa.selenium.assist.ui.WebDriverWait;
import org.testng.annotations.AfterMethod;

public class HybridTest {
    AppiumDriver driver;

    @BeforeMethod
    public void beforeMethod() throws MalformedURLException {
        DesiredCapabilities android_dcb = new DesiredCapabilities();
        android_dcb.setCapability("platformName", "Android");
        android_dcb.setCapability("platformVersion", "6.0.1");
        android_dcb.setCapability("deviceName", "machine");
        android_dcb.setCapability("appPackage", "devian.tubemate.house");
        android_dcb.setCapability("appActivity", "devian.tubemate.house.TubeMate");

        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), android_dcb);
    }

    @Take a look at
    public void f() throws InterruptedException, MalformedURLException {
        WebDriverWait wait = new WebDriverWait(driver, 30);
        driver.findElement(By.id("devian.tubemate.house:id/title_ic_drawer")).click on();

        wait.till(ExpectedConditions.visibilityOfElementLocated(By.id("devian.tubemate.house:id/title")));
        Listing a=driver.findElements(By.id("devian.tubemate.house:id/title"));
        a.get(6).click on();

        driver.context("WEBVIEW_devian.tubemate.house");

        wait.till(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("enter#lst-ib"))).sendKeys("TCS");
    }

    @AfterMethod
    public void afterMethod() {
        driver.give up();
    }
}

However each time I modify my context from NATIVE_APP to WEBVIEW, it does not succeed at all times. More often than not, Appium will get caught at this stage.

> information: [debug] returning course of title: devian.tubemate.house
> information: [debug] Out there contexts: 
> information: [debug] ["WEBVIEW_devian.tubemate.home"]
> information: [debug] Out there contexts: NATIVE_APP,WEBVIEW_devian.tubemate.house
> information: [debug] Connecting to chrome-backed webview
> information: Chromedriver: Modified state to 'beginning'
> information: Chromedriver: Set chromedriver binary as: C:Program Information (x86)Appiumnode_modulesappiumnode_modulesappium-chromedriverchromedriverwinchromedriver.exe
> information: Chromedriver: Killing any previous chromedrivers, working: FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %a))
> information: Chromedriver: No previous chromedrivers appeared to exist
> information: Chromedriver: Spawning chromedriver with: C:Program Information (x86)Appiumnode_modulesappiumnode_modulesappium-chromedriverchromedriverwinchromedriver.exe --url-base=wd/hub --port=9515
> information: Chromedriver: [STDOUT] Beginning ChromeDriver 2.19.346078 (6f1f0cde889532d48ce8242342d0b84f94b114a1) on port 9515
> Solely native connections are allowed.
> information: JSONWP Proxy: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no physique
> information: JSONWP Proxy: Received response with standing 200: "{"sessionId":"","standing":0,"worth":{"construct":{"model":"alpha"},"os":{"arch":"x86_64","title":"Home windows NT","model":"10.0"}}}"
> information: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with physique: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"devian.tubemate.house","androidUseRunningApp":true,"androidDeviceSerial":"EBAZFG563168"}}}

After someday holding at that stage, it says the next and give up.

> information: [debug] Did not get a brand new command in 60 secs, shutting down...
> information: Shutting down appium session
> information: [debug] Urgent the HOME button
> information: [debug] executing cmd: D:tools_r25.2.3-windowsplatform-toolsadb.exe -s EBAZFG563168 shell "enter keyevent 3"
> information: [debug] Stopping logcat seize
> information: [debug] Logcat terminated with code null, sign SIGTERM
> information: [debug] [BOOTSTRAP] [debug] Received knowledge from consumer: {"cmd":"shutdown"}
> information: [debug] [BOOTSTRAP] [debug] Received command of sort SHUTDOWN
> information: [debug] [BOOTSTRAP] [debug] Returning outcome: {"standing":0,"worth":"OK, shutting down"}
> information: [debug] [BOOTSTRAP] [debug] Closed consumer connection

What could be potential workaround?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

PHP Code Snippets Powered By : XYZScripts.com