Created
March 12, 2011 01:43
-
-
Save jtemplet/866933 to your computer and use it in GitHub Desktop.
Selenium Basics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.thoughtworks.selenium.*; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Test; | |
import java.util.regex.Pattern; | |
import org.openqa.selenium.internal.seleniumemulation.GetHtmlSource; | |
import org.openqa.selenium.server.SeleniumServer; | |
import org.openqa.selenium.server.RemoteControlConfiguration; | |
public class Test extends SeleneseTestCase { | |
Selenium selenium; | |
public static final String MAX_WAIT_TIME_IN_MS="60000"; | |
private SeleniumServer seleniumServer; | |
@Before | |
public void setUp() throws Exception { | |
RemoteControlConfiguration rc = new RemoteControlConfiguration(); | |
rc.setAvoidProxy(true); | |
rc.setSingleWindow(true); | |
rc.setReuseBrowserSessions(true); | |
seleniumServer = new SeleniumServer(rc); | |
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "https://baseurl.com"); | |
seleniumServer.start(); | |
selenium.start(); | |
} | |
@Test | |
public void testGoogleTestAsJava() throws Exception { | |
selenium.open("/pathUrlToOpen"); | |
selenium.type("USER", "userName"); | |
selenium.type("PASSWORD", "myPassword"); | |
selenium.click("//input[@value='Login']"); | |
selenium.waitForPageToLoad("40000"); | |
for (int second = 0;; second++) { | |
if (second >= 60) break; | |
try { | |
if (selenium.isElementPresent("//table[@id='isc_2Ltable']")) { | |
System.out.println("Focus on Sales Forecast"); | |
break; | |
} | |
// Pause for 1 second. | |
Thread.sleep(1000); | |
} catch (Exception e) { | |
System.err.println(e.getMessage()); | |
e.printStackTrace(); | |
} | |
} | |
selenium.click("//table[@id='isc_7Rtable']/tbody[2]/tr[1]/td/div/nobr/table/tbody/tr/td[3]/nobr"); | |
System.out.println("Focus on another element"); | |
} | |
@After | |
public void tearDown() throws Exception { | |
seleniumServer.stop(); | |
selenium.stop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment