Thursday, July 14, 2011

Selenium with Regular Expression

import static org.junit.Assert.assertTrue;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;


public class SeleniumWithRegex {
 static Selenium selenium;
 @BeforeClass
 public static void setUp() throws Exception {
  selenium = new DefaultSelenium("localhost", 2323, "*chrome", "http://qtp-help.blogspot.com");
  selenium.start();
 }
 /**
  * Verify Text using regular expression
  * @throws InterruptedException
  */
 @Test
 public void verifyText() throws InterruptedException {
  selenium.open("/2010/10/selenium-checkbox-example.html");
  assertTrue(selenium.isTextPresent("regexp:.*gaurang00.*"));
 }
 
 /**
  * Click on button using regular expression
  * @throws InterruptedException
  */
 @Test
 public void testButton() throws InterruptedException {
  selenium.allowNativeXpath("false");
  selenium.click("//input[matches(@id,'Gaurang.*')]");
 }
 
 /**
  * Click on link using regular expression
  * @throws InterruptedException
  */
 @Test
 public void testLink() throws InterruptedException {
   selenium.click("link=regexp:gaurang.*");

 }
 
 @AfterClass
 public static void tearDown(){
  selenium.close();
  selenium.stop();
 }
}

0 comments:

Post a Comment