Monday, February 8, 2010

Accessing a datafile through Selenium RC

In our testing most of us require to call data from a data storage and execute our tests to confirm various validations work as expected, different conditions are met etc.

Below is a code snippet that I used in calling data used in a .txt file in validating a simple test in user name password based sign-in process. I was on Selenium RC/JUnit/Java platform in this.

public class SignIn extends SeleneseTestCase {

public void setUp() throws Exception {
   setUp("https://localhost:9443/carbon/", "*chrome");
}

   public void testSignInValdation() throws Exception {
       BufferedReader in = null;
       InputStreamReader inputStream = null;

       inputStream = new InputStreamReader(new FileInputStream("C:" + File.separator + "signin.txt"));
       in = new BufferedReader(inputStream);
       String line = null;

       while ((line = in.readLine()) != null) {
            System.out.println("password: " + line);
            selenium.open("/carbon/admin/login.jsp");
            selenium.waitForPageToLoad("30000");
            selenium.type("txtUserName", "yumani");
            selenium.type("txtPassword", line);
            selenium.click("//input[@value='Sign-in']");
            selenium.waitForPageToLoad("30000");
       }
   }
}

Featured

Selenium - Page Object Model and Action Methods

  How we change this code to PageObjectModel and action classes. 1 2 3 driver . findElement ( By . id ( "userEmail" )). sendKeys (...

Popular Posts