"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;
Showing posts with label Selenium - Examples. Show all posts
Showing posts with label Selenium - Examples. Show all posts

April 29, 2014

Selenium Reads & QA Tools Post


Good Reads
PhantomJS
Tools / Useful Scripts
Fitnesse
Sikuli
Mobile Automation
Jmeter
Windows Testing
More Tools
Happy Learning!!!

May 25, 2011

Selenium - Soft Assertions

Thanks Tarun for providing feedback on Selenium Automation Assignment. His observation is correct. If one of Assertion fails this should not stop verifying rest of the cases.
On Google Search found a couple of solutions for this problem
Would work on this suggestions soon :).
Happy Reading!!

January 15, 2011

Selenium - Parsing Lists and Links in a Page

Next Example is to try looping through Lists and Links in a page
Followed the below steps
1. Created Sample Test Page link
2. Create a project and add required libraries. Verify earlier post

Below is the Example Code - Working Code

import static org.testng.Assert.assertTrue;
import java.util.Vector;
import org.testng.Assert;
import org.testng.annotations.*;
import com.thoughtworks.selenium.*;
public class TestLists
{
     
public static Selenium selenium;

@BeforeTest
public void openBrowser()
{
      System.out.println("Before Test");
      selenium = new DefaultSelenium("localhost", 4444, "*iehta","http://sqlandsiva.blogspot.com/2011/01/test-page-for-selenium-example.html");
}

@Test
public void LoopthruElement()
{
try
{
      System.out.println("Running Test1");
      selenium.start();
      selenium.open("http://sqlandsiva.blogspot.com/2011/01/test-page-for-selenium-example.html");
      int j=1;
      while(selenium.isElementPresent("//div[@id='OrderList']/ol/li["+j+"]"))
      {
            System.out.println("Value is " + selenium.getText("//div[@id='OrderList']/ol/li["+j+"]"));
            j++;
      }
      j=1;
     
      while(selenium.isElementPresent("//div[@id='UnOrderedList']/ul/li["+j+"]"))
      {
            System.out.println("Value is " + selenium.getText("//div[@id='UnOrderedList']/ul/li["+j+"]"));
            j++;
      }
      j=1;
      while(selenium.isElementPresent("//div[@id='Links']/a["+j+"]"))
      {
            System.out.println("Value is " + selenium.getText("//div[@id='Links']/a["+j+"]"));
            j++;
      }
     
}
catch(Exception ex)
{
                  ex.toString();
}
}
}

This is tested and working code. Run it as TestNG Test. Below is the output for the program













I used firebug XPATH copier to get exact Xpath location. Below is snapshot of the same















Happy Reading!!

January 01, 2011

Selenium Xpath Looping Example

Thanks to author for article Selenium IDE with an XPath Locator. I wanted to try the same example using TestNG code.

Followed the below steps
1. Created Sample Test Page link
2. Create a project and add required libraries. Verify earlier post

Below is the Example Code - Working Code

import static org.testng.Assert.assertTrue;
import java.util.Vector;
import org.testng.Assert;
import org.testng.annotations.*;
import com.thoughtworks.selenium.*;
public class SeleniumXpath
{
     
public static Selenium selenium;

@BeforeTest
public void openBrowser()
{
      System.out.println("Before Test");
selenium = new DefaultSelenium("localhost", 4444, "*iehta","http://sqlandsiva.blogspot.com/2011/01/test-xml-page-for-selenium.html);
}

@Test
public void LoopthruElement()
{
try
{
      System.out.println("Running Test1");
      selenium.start();
      selenium.open("http://sqlandsiva.blogspot.com/2011/01/test-xml-page-for-selenium.html");
      int i=1,j=1;
      while(selenium.isElementPresent("//table[@id='firstTable']//tr["+i+"]/td["+j+"]"))
{
      while(selenium.isElementPresent("//table[@id='firstTable']//tr["+i+"]/td["+j+"]"))
                       
{
            System.out.println("Value is " + selenium.getText("//table[@id='firstTable']//tr["+i+"]/td["+j+"]"));
            j++;
      }
      j=1;
      i++;
}
}
catch(Exception ex)
{
                  ex.toString();
}
}
}

This is tested and working code. Run it as TestNG Test. I intend to add more examples in the page and improve on this example.

Happy Reading!!

July 01, 2010

Learning Selenium - Part II

In continuation to my earlier post. One of my friend asked me Pagination in Selenium. I got help from one of my team members Avinash.

Learning's are
1. Install Firebug add in to firefox
2. Install Xpather add in to firefox
3. From Existing post I want to goto page 2 of Search Results
4. Choose Xpather Location as shown below


5. Select the Xpath for Selecting Second page
6. Add the below line of code as last line. Only from footer part I am selecting the xpath.
selenium.click("//div[@id='foot']/table[@id='nav']/tbody/tr/td[3]/a/span[1]");
7. Modified code snapshot as below


7. Search Results would take you to page 2 of results
Good Read - Identifying XPath of a element using XPath Query
Happy Reading!!!