lunes, 25 de mayo de 2015

Using Dataprovider annotation


 We can use a Data Provider to supply the values you need to test.  A Data Provider is a method on your class that returns an array of array of objects.  This method is annotated with @DataProvider:


we must call  annotation  dataprovider @Test(dataProvider=dataprovider's name).
 If The "prime" method has twenty data, the test will execute twenty times. If our prime  number  method has five attributes, our test method should receive five  parameters.





Using  objects 


In this case the parameter is a person object




To read a data in excel, first we should have access to workbook, sheet which we want to read as workbook contains multiple sheets and if you want to read a particular cell we need to location  a Cell.
We need "jxl-2.6.12.jar" to read the file.














lunes, 18 de mayo de 2015

Design Patterns

In this part we are going to have a look design pattern for creating maintainable and reusable bits of code that we can use with our Selenium Tests. This means that if there any changes needed to our web application or changes in the way we need to find elements, we can change it once and have it fix everything  every quickly.

In this part, we shall learn:

  •  Page Object 
  • using Page Factory with Page Object
  • Using LoadableComponents


Page Objects: This is a technique where we split the test login out into separate classes. This allows us to create a java class for each of the pages that we use on the page.

Using Page Factory with Page Object 

  • Page Factory: This allows us to decorate our webElement variables in our age objects so that we remove a lot of the look up code.

          The code that we have learnt to write earlier can be quite verbose.To clean up our code, we can start to use page factories.This allows us to annotate variable in our page object with how to search the page.  To use the pageFactory project in Webdriver, we will have to make sure that the we have added it as a  dependency.

For Examples:
we can look for element by name, id, xpath, css, linkText, parcialLinkText, tagName

@FindBy(name="q")
Public webElement textSearch;



@FindBy (how=How.Name, using="q")
WebElement verifyButton2;



 where "q" is the name the element.

We need to initialize the factory by calling initElement() , at the same class.

pageFactory.initElements(driver, this)


we can initialize the page factory in other class in which they were defined the webElement elements.
pageFactory.initElements(driver, nameClass.class);




We can call initElement() in constructor  method or in other method.

For Example:



Using LoadableComponents: In this section we had a look at the base page for page objects that comes with the Selenium Project. It is in a base class allows us to remove quite a bit of code and move the boilerplate to LoadableComponent.

LoadableComponent is another way to approach PageObject. It is a base class that all of the page need to extend. The base class has the following methods on the interface.
  • get()
  • isLoaded(): This method can allow us to check id the page has been loaded correctly.
  • load(): This method will load the page for us
We will have to add overrides for the load() and isLoaded() method.
I will modify at the same example the Page Factory , you can create a new class.

Instead of the usual public class PageObject, we change it:

public class PageObject extends LoadableComponent<PageObject>

For example.