viernes, 26 de septiembre de 2014

Create Test Case with TestNG and Eclipse

Automation  of Test Case  with TestNG and Eclipse

 I willTalk about concepts, creating, structure and execute through xml files to automate the test cases using TestNG

TestNG:

TestNG is a test framework desigined to simplify a broad of testing needs, from unit test,  integretion testing.

In order to Write a test with TestNG, you need three step
  • You need write the business of your test and insert TestNG annotation in  your code.
  •  Add the information about your test (class name or  group to run) in a testng.xml file
  •  Run TestNG. 

For automation of Test Case, first you need to follow steps of  my own last post


TestNG  has the followings Annotation

@BeforeSuite
@AfterSuite
@BeforeTest
@AfterTest
@BeforeGroups
@AfterGroups
@BeforeClass
@AfterClass
@BeforeMethod
@AfterMethod

In this example we will use the followings
@BeforeTest:  The annotated method will be run before any test method belonging to the classes inside the <test> tag is run. 
@Test: The annotated method will be run test method.
@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run

Int this example is using dependsOnMethods, is the list of methods , this methods, we are guaranteed that all these methods will be run before the test method that contains this annotation is run. Furthermore, if any of these methods was not a SUCCESS, this test method will not be run and will be flagged as a SKIP.

We will use a xml file, so we will call to our class. For example firstTestNG.java

First Test Case with TestNG

Following the steps

1. Creating of new project








 2. Add package a this class






3.Create a new class for this project







4. Add the Annotations for the test case 

                                          








5. The test case finished

 if you want to test with other browsers review my  other own page where I explain how do them.



6. Create xml file for run the test cases.









Adding TestNG library and JARs for Selenium WebDriver

















lunes, 7 de julio de 2014

Selenium WebDriver

For create test cases
Need the following
1.       In this example using Eclipse IDE ,Download of https://www.eclipse.org/downloads/













2.       You need download from page selenium-java-client-driver-1.0.1.jar and selenium-server-standalone-2.42.2 of http://docs.seleniumhq.org/download/



3.       For execute in different browser, you  need download the plugins.
Download for internet explorer plugins of http://docs.seleniumhq.org/download/

Download for google chrome plugins of  http://docs.seleniumhq.org/download/


  4. The plugins download

   Create test case  in Eclipse

   We follow  next steps .Execute Eclipse IDE









Adding JARs






Create JUnit Test case




The labels is important in executing the test
The label "@Before" indicates to JUnit, that the this method code be execute first before that the test. Preparation for the execution of the test. its name of the method is "setUp ()".
on this section we  initialize the browser and execute
the label “@Test” indicates to JUnit, this part is the test and that it should execute it.
this method, we can put the name  that we want.
The label “@After” indicates to JUnit that execute to  ends the test case .
on this part, close the browser and  ends the test.
Its name of the method is “ tearDown ()”.

We need import the follow in this test
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;

Execute the test case on Firefox


Execute the test case on different browsers



Configure for execute the test case