Sunday, September 25, 2011

Adding Main() to JUnit to run from command prompt

//package com.example.tests;

import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
import junit.framework.*;

public class GE_TC1 extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://www.ge.com/", "*firefox");
}
public void testGE_TC1() throws Exception {
selenium.open("http://www.ge.com/");
// Search for any word
selenium.type("textToSearch", "energy efficient");
// This is just a comment
selenium.click("searchSubmit");
selenium.waitForPageToLoad("30000");
assertEquals("GE: Search Results", selenium.getTitle());
assertTrue(selenium.isTextPresent("energy efficient"));
}
public static Test suite() {
//method added
return new TestSuite(GE_TC1.class);
}
public void tearDown(){
//Added . Will be called when the test will complete
selenium.stop();
}
public static void main(String args[]) {
// Added. Execution will started from here.
junit.textui.TestRunner.run(suite());
}
}