How to change context view for when running test on mobile device using serenity page object model

323 views
Skip to first unread message

Lovesh Jain

unread,
Sep 29, 2016, 7:34:05 PM9/29/16
to Serenity BDD Users Group
Hi John/All,

I am working on web application which has a date picker when it comes to mobile devices so the code which work on desktop browser does not work for device.

I tried finding the date picker properties using UIAutomator and found that the class of date picker element is :- android.widget.DatePicker. 

But when I try to enter value using getDriver().findElement(By.xpath("//android.widget.DatePicker[@index='0']")).sendKeys("Oct"), I am getting error as unable to locate element.

I did some goggling and suspecting that it might be because my application is running in webview mode and date picker is a mobile native element so I might need to change context to native but in page object class I am unable to do it.

"getDriver()" does not have "getContextHandles()" method.

Could you please help me out. How I can change context.

Serenity properties file :- 

webdriver.driver= appium
appium.platformName = Android
appium.platformVersion = 6.0.1
appium.deviceName = "deviceName"
appium.browserName = Chrome

Thanks,
Lovesh Jain

Lovesh Jain

unread,
Sep 29, 2016, 10:56:08 PM9/29/16
to Serenity BDD Users Group
Hi,

I was able to get context change using below code.                           

AndroidDriver<WebElement> androidDriver = ((AndroidDriver<WebElement>)((WebDriverFacade) getDriver()).getProxiedDriver()); 
Set<String> contextNames = androidDriver.getContextHandles();
      for (String contextName : contextNames) {
   System.out.println(contextName);
     System.out.println(contextNames); //prints out something like [NATIVE_APP, WEBVIEW_<APP_PKG_NAME>]
    }
    androidDriver.context("NATIVE_APP");

But when I use the same code to run test on Saucelabs, getting below error :-


Error:org.openqa.selenium.remote.RemoteWebDriver$$EnhancerByCGLIB$$d2f9355c cannot be cast to io.appium.java_client.android.AndroidDriver

Could you please advice.

Thanks,
Lovesh

Lovesh Jain

unread,
Oct 3, 2016, 4:43:57 PM10/3/16
to Serenity BDD Users Group
Hi,

I figured out that the reason why I was getting error when running on saucelabs was because of the serenity property "saucelabs.url". When I commented that out the issue was resolved.
But in that case, the tests run fine on saucelabs but serenity report does not have saucelabs video link attached to test.

I think there is an update required either to remote webdriver class or html report class.

Thanks,
Lovesh
Reply all
Reply to author
Forward
0 new messages