Unfortunately currently robotium does not support testing of webview even if it is used with native app but there is a way to test webview using Android WebDriver. So the solution is using combination of robotium + android webdriver. Here is the sample code to test contents of webview.
Little background about AUT: Native app has a button (assume ‘Google’) clicking on which opens webview with google.com.
Sample Code:
Activity mActivity = getActivity();
WebView web;
ArrayList<View> views = solo.getCurrentViews();
for(View view : views) {
if(view instanceof WebView) {
web = (WebView) view;
break;
}
}
WebDriver driver = new AndroidWebDriver(mActivity);
driver.get(web.getOriginalUrl());
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Test");
element = driver.findElement(By.xpath("//span[text()='Google Search']"));
element.click();
Did this code worked?
ReplyDeletedriver.get(web.getOriginalUrl()); throwing Null pointer exception.
This is working for me. Please make sure you have only one webview by checking the count of webview.
DeleteI can't seem to import AndroidWebDriver.
ReplyDeleteI download this https://code.google.com/p/selenium/downloads/detail?name=selenium-java-2.32.0.zip&can=2&q= & added to my Build Path.
Where can I get the AndroidWebDriver?
Thanks.
Nice it seems to be good post... It will get readers engagement on the article since readers engagement plays an vital role in every blog.. i am expecting more updated posts from your hands.
ReplyDeleteMobile App Development Company
Android App Development Company