Tuesday, November 25, 2014

Selenium: Important packages

org.openqa.selenium.WebDriver

Contains WebDriver Interface need to instantiate a new browser


org.openqa.selenium.chrome.ChromeDriver


Contains the Chrome driver class used to instantiate chrome driver onto the browser which is instantiate using WebDriver class

WebDriver w= new ChromeDriver()

org.openqa.selenium.By

By class is used to locate the various elements on a web page

java.util.concurrent.TimeUnit

Used for implicit wait

WebDriver w= new ChromeDriver()
w.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS)


org.openqa.selenium.support.ui.WebDriverWait

org.openqa.selenium.support.ui.ExpectedConditions

Used for explicit wait

WebDriverWait w= new WebDriverWait(driver, 5)

  Use wait object with ExpectedConditions on portions where you need the explicit wait to occur-

w.until(ExpectedConditions.visibilityOfElementLocated(By.name("id")))

org.openqa.selenium.support.ui.Select

Used to control & acccess the drop down values

Select s= new Select(driver.findElement(By.name("elementName")))
s.selectByVisibleText("Value")
OR
s.selectByValue("value")


org.openqa.selenium.interactions.Actions

org.openqa.selenium.interactions.Action



Actions is user-facing API used to perform complex user gesture. This can be used instead of directly using keyboard or mouse

Instantiate a new Actions object.
Actions a= new Actions(driver)
Instatiate an Action using above Actions object
Action a1= a.moveToElement(driver.findElement(By.name("elementName"))).build()
Perform the Action
a1.perform();

Actions are very useful for some of the complex user gesture which can't be perform using simple locaters e.g. following code will do a right click on an element

Instantiate a new Actions object.
Actions a= new Actions(driver)
Instatiate an Action using above Actions object
Action a1= a.moveToElement(driver.findElement(By.name("elementName"))).contextClick().build()
Perform the Action
a1.perform();

More details can be found here under "Building a Series of Multiple Actions"


org.testng.annotations.DataProvider;

org.testng.annotations.Test;

org.testng.annotations.BeforeTest;

org.testng.annotations.AfterTest;



All the above packages are used when we use Annotations in TestNG framework. Annotations in TestNG framework are a way to control the code execution below them. Annotations are preceded with an @

Summary of various TestNG Annotations (For more details on TestNG and Annotations usage example, click here)

@BeforeSuite: The annotated method will be run before all tests in this suite have run.

@AfterSuite: The annotated method will be run after all tests in this suite have run.
@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the tag is run.
@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the tag have run.
@BeforeGroups: The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked.
@AfterGroups: The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked.
@BeforeClass: The annotated method will be run before the first test method in the current class is invoked.

@AfterClass: The annotated method will be run after all the test methods in the current class have been run.

@BeforeMethod: The annotated method will be run before each test method.
@AfterMethod: The annotated method will be run after each test method.
@Test: The annotated method is a part of a test case

Note- Here is the hierarchy for the Annotations in TestNG framework and they will be called in that order-
BeforeSuite
        BeforeTest
                   BeforeClass
                              BeforeMethod
                                         Test
                              AfterMethod
                   AfterClass
       AfterTest
AfterSuite
A very good example using all these Annotations can be referred here

7 comments:

  1. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…

    selenium training in chennai|

    ReplyDelete
  2. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

    Java Training In Bangalore

    ReplyDelete
  3. Its pleasure to across your post.Good representation of the connectivity of selenium with java with neat descriptions.
    motorola mobile service centre in chennai
    moto g service center in chennai
    motorola service center in velachery

    ReplyDelete
  4. Incredible data. Fortunate me I went over your site by some coincidence (stumbleupon). I've book-checked it for some other time!news updates

    ReplyDelete