Sunday 10 March 2013

Robotium testing webview example (test application and application) source download



Robotium test source code - https://github.com/tejasv02/Robotium4Webviewtest 
Webview sample test application - 
https://github.com/tejasv02/Androidwebviewsampleapp

 Robotium 4.0 has been released with webview support which enables testing of hybrid applications .
Some new functionalities have been added which enables testing of webpage embedded within native app also called as hybrid android application.
new functionalities inculde:
waitForWebElement(By by), clickOnWebElement(WebElement webElement), enterTextInWebElement(By by, String text), typeTextInWebElement(By by, String text), clearTextInWebElement(By by), getWebElement(By by, int index)

webview component is present in this file : https://github.com/tejasv02/Androidwebviewsampleapp/blob/master/src/com/myapp/WebViewActivity.java

customHtml  string is used to create a temporary html, which is used to fill 
webview and then this html is loaded into webview 

String customHtml = "<html><body><h1>Hello, WebView</h1></body></html>";
webView.loadData(customHtml, "text/html", "UTF-8"); // if this line is commented , 
// uncomment it for test purpose


Tests are located in - https://github.com/tejasv02/Robotium4Webviewtest/blob/master/Robotium4webviewtest/src/com/testcalc/Testcase1.java


package com.testcalc;
import java.io.IOException;
import java.util.ArrayList;
import com.jayway.android.robotium.solo.By;
import android.view.View;
public class Testcase1 extends Apptest{
public Testcase1() throws ClassNotFoundException {
super();
}
public void testDisplayBlackBox() throws IOException {
Commonval.log(this.getName().toString());
solo.clickOnText("Go to");
solo.waitForWebElement(By.textContent("Hello, WebView"), 10, false);
solo.sleep(5000);
}
}


This is not an exhaustive explanation for a starter but should suffice some one who knows a bit of robotium,
Please feel free to leave comments below




Steps 

Part1: running webview application
Steps
1) Go to github copy project link - https://github.com/tejasv02/Androidwebviewsampleapp.git
2) Import project into eclipse
3) Solve dependency errors
4) Run web view application test as Android application

Part2: Testing webview application
Steps:
1) Go to github and copy project link - https://github.com/tejasv02/Robotium4Webviewtest.git
2) Import project into eclipse
3) Solve dependency errors
4) Run web view application test as Android application

Dependency
    Git plugin to download project from github -     http://download.eclipse.org/egit/updates
  
  
Problems : The import android cannot be resolved
    Install plugin for android - https://dl-ssl.google.com/android/eclipse/
    set path for Android SDK - Windows -> preferences -> Android


Video