We are creating autotests with Appium for Android app. Our app has a few webview pages. After redirection to the webview page - I changed the context but still cant work with webview elements.
@test
@DisplayName("DAF-T14 Check feedback form after clicking it from profile page")
public void ProfileAppFeedbackFlow() throws Exception {
String expectedFeedbackTitle = "Feedback";
String expectedFeedbackWebTitle = "What are your experiences with the DKV app?";
String expectedDescription = "You have noticed incorrect station information? Please repor";
var onboardingPage = new OnboardingPage();
var onboardingLinearLayout = onboardingPage.clickSkipButton();
var locationPopUp = onboardingLinearLayout.clickLaterButton();
var analysisPopUp = locationPopUp.clickAllowAllTimeButton();
analysisPopUp.clickActivateButton();
var feedbackProfilePage = new DoYouLikePopUp().clickNoButton();
Assertions.assertEquals(feedbackProfilePage.getFeedbackTittle(), expectedFeedbackTitle);
Now I'm checking and changing the context to webview
Set strcontext = null;
try{
strcontext = ((AndroidDriver) AppiumInit.getAppiumDriver()).getContextHandles();
System.out.println("Found contexts size: '" + strcontext.size() + "'");
for (String s :strcontext) {
System.out.println("Found context: '" + s + "'");
if (s != null && s.contains("WEBVIEW")) {
System.out.println("Switching context to: '" + s + "'");
((AndroidDriver) AppiumInit.getAppiumDriver()).context(s);
break;
}
}
} catch (Exception e){
e.printStackTrace();
}
Checking if the context is webview
String currentContext = ((AndroidDriver) AppiumInit.getAppiumDriver()).getContext();
System.out.println("Current Context: " + currentContext);
and checking the title text
Assertions.assertEquals(feedbackProfilePage.getFeedbackWebTitl(), expectedFeedbackWebTitle);
where
public String getFeedbackWebTitl() {
WebElement feedbackWebTitle = driver.findElement(By.xpath("//span[@id='title']"));
return feedbackWebTitle.getText();
}
What can I see in logs:
Found contexts size: '2'
Found context: 'NATIVE_APP'
Found context: 'WEBVIEW_com.dkveuroservice.mobileappkit'
Switching context to: 'WEBVIEW_com.dkveuroservice.mobileappkit'
Current Context: WEBVIEW_com.dkveuroservice.mobileappkit
<html><head></head><body></body></html>
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//span[@id='title']"} (Session info: chrome=103.0.5060.71) For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception Build info: version: '4.10.0', revision: 'c14d967899' System info: os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '13.5.1', java.version: '17.0.6' Driver info: io.appium.java_client.android.AndroidDriver Command: [629bae0e-84be-463f-86a7-49e1c58ddbcb, findElement {using=xpath, value=//span[@id='title']}] Capabilities {appium:app: //Users//nifargo//Documents..., appium:appActivity: com.dkveuroservice.mobileap..., appium:appPackage: com.dkveuroservice.mobileap..., appium:automationName: UiAutomator2, appium:databaseEnabled: false, appium:desired: {app: //Users//nifargo//Documents..., appActivity: com.dkveuroservice.mobileap..., appPackage: com.dkveuroservice.mobileap..., automationName: UiAutomator2, deviceName: autoTests, newCommandTimeout: 800, platformName: ANDROID}, appium:deviceApiLevel: 33, appium:deviceManufacturer: Google, appium:deviceModel: sdk_gphone64_arm64, appium:deviceName: emulator-5554, appium:deviceScreenDensity: 560, appium:deviceScreenSize: 1440x2560, appium:deviceUDID: emulator-5554, appium:javascriptEnabled: true, appium:locationContextEnabled: false, appium:networkConnectionEnabled: true, appium:newCommandTimeout: 800, appium:pixelRatio: 3.5, appium:platformVersion: 13, appium:statBarHeight: 84, appium:takesScreenshot: true, appium:viewportRect: {height: 2392, left: 0, top: 84, width: 1440}, appium:warnings: {}, appium:webStorageEnabled: false, platformName: ANDROID} Session ID: 629bae0e-84be-463f-86a7-49e1c58ddbcb changed
LOGs https://gist.github.com/Nifargo/2920de27ba7ea76625f7430a6bf6bf96
Expect that i can chech the text of web element