Junit and sahi

Solo disponible en BuenasTareas
  • Páginas : 6 (1417 palabras )
  • Descarga(s) : 0
  • Publicado : 7 de diciembre de 2011
Leer documento completo
Vista previa del texto

1 Junit + Sahi
1.1 how Junit and Sahi work together
1.1.1 Sahi Java Driver
1.1.2 Sahi Scripting - Calling Java
1.2 POC
1.2.1 Sahi Java Driver
1.2.2 MyJavaClientTest.java
1.2.3 compile
1.3 execute
1.3.1 Sahi Scripting - Calling Java
1.4 References
1.5 Links
Junit + Sahi

Base on this documentation http://sahi.co.in/forums/viewtopic.php?id=1442

* Research and documenthow Junit and Sahi work together
* Create a working POC
how Junit and Sahi work together

Sahi Java Driver

The Sahi Java Driver can be used to write Java unit tests and functional tests for web applications.

The Sahi Java Driver is bundled with Sahi’s releases and has been available since 2nd Sep 2009. We are thankful to ThoughtWorks for partially funding its development.

There isa sample Eclipse project available in sahi/sample_java_project. One needs to use the correct path for sahi.jar (or copy it into sahi/sample_java_project/lib from sahi/lib). More detailed examples are available in DriverClientTest.java which is in sahi/sample_java_project

Full documentation is available as http://sahi.co.in/java/javadocs/

Make sure that the proxy settings are properlyconfigured on the browser (not needed for firefox) and that the Sahi proxy is running. Have a look at Using Sahi for details on configuring the browser and starting the proxy.

Sahi Scripting - Calling Java

Sahi scripts run on the Rhino javascript engine. This allows Sahi to call any Java code in the classpath of Sahi.


Sahi Java Driver

A POC to get started with Sahi Java.

Have alook at DriverClientTest.java in sample_java_project dir for more detailed use of APIs.
You need sahi/lib/sahi.jar in your classpath.

My environment


create a class "MyJavaClientTest.java",i put it in sahi/sample_java_project/src/in/co/sahi/ directory

package in.co.sahi;

import junit.framework.TestCase;
import net.sf.sahi.client.ExecutionException;
import net.sf.sahi.config.Configuration;

* This is a sample class to get started with Sahi Java.
* Have a look at DriverClientTest.java in sample_java_project dir for more detailed use of APIs.
* You need sahi/lib/sahi.jar in your classpath.
public class MyJavaClientTest extends TestCase {
private Browserbrowser;
private String sahiBase;
private String userDataDirectory;

* This starts the Sahi proxy, toggles the proxy settings on Internet Explorer
* and starts a browser instance. This could be part of your setUp method in a JUnit test.
public void setUp(){
sahiBase = "/mnt/sda4/Sahi/sahi0321/sahi/"; // where Sahi is installed or unzipped
userDataDirectory ="myuserdata";
Configuration.initJava(sahiBase, userDataDirectory); // Sets up configuration for proxy. Sets Controller to java mode.

// toggleIEProxy(true); // Not needed for Firefox. Needed for IE, Safari, Chrome on Windows

String browserPath = "/usr/bin/firefox";
String browserProcessName = "firefox";
String browserOption = "-profile/mnt/sda4/Sahi/sahi0321/sahi/userdata/browser/ff/profiles/sahi1 -no-remote";
browser = new Browser(browserPath, browserProcessName, browserOption);

public void testGoogle() throws ExecutionException{
browser.textbox("q").setValue("sahi forums");
browser.submit("Google 搜尋").click();
browser.link("Sahi - Web Automation and TestTool").click();
System.out.println("check: browser.textbox("req_username").exists() = " + browser.textbox("req_username").exists());

public void tearDown(){
// proxy.stop();
// toggleIEProxy(false); // Not needed...
tracking img