Showing posts with label parallel testing. Show all posts
Showing posts with label parallel testing. Show all posts

Sunday, 11 September 2016

Selenium Grid Implementation

Parameterization in TestNG


Assertions in TestNG

Most Commonly used Assertions in TestNg for automation testing are :

•       assertEquals(boolean actual, boolean expected)
     Asserts that two booleans are equal. If not, assertions fails.
•       assertEquals(boolean actual, boolean expected, String message)
                 Asserts that two booleans are equal. If not, assertions fails, & message is displayed.
•       assertEquals(String actual, String expected)
               Asserts that two Strings are equal. If not, assertions fails.
•       assertEquals(String actual, String expected)
               Asserts that two Strings are equal. If not, assertions fails.
•       assertEquals(String actual, String expected, String message)
               Asserts that two Strings are equal. If not, assertions fails, & message is displayed.
•       assertFalse(boolean condition)
              Asserts that a condition is false. If not, assertions fails.
•       assertFalse(boolean condition, String message)
              Asserts that a condition is false. If not, assertions fails, & message is displayed.

•       assertNotNull(Object object)
        Asserts that an object isn't null. If not, assertion fails
•       assertNull(Object object)
        Asserts that an object is null.
•       assertNull(Object object, String message)
        Asserts that an object is null. . If not, assertion fails, & message is displayed.
•       assertTrue(boolean condition)
        Asserts that a condition is true. If not, assertion fails.
•       assertTrue(boolean condition, String message)

        Asserts that a condition is true. If not, assertion fails, & message is displayed

Next

Skipping a test case in TestNG

package testng.examples;
  import org.testng.Assert;
 import org.testng.annotations.Test;

  public class Ignore {
       @Test(enabled = false)
         public void test() {
              Assert.assertEquals(true, true);
      }
}

Creating Suites in TestNG

In TestNG suites are created using xml file. 

Below is an example.


<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >  
 <!-- @BeforeSuite -->
<suite name="TestAll">
   <!-- @BeforeTest -->
              <test name="case1">
                     <classes>
                                <class name="com.testng.examples.configuration.Test1" />
                                <class name="com.testng.examples.configuration.Test2" />
                                <class name="com.testng.examples.configuration.Test3" />
                       </classes>
               </test>
<!-- @AfterTest -->
•
  <!-- @BeforeTest -->
           <test name="case2">
                  <classes>
                         <class name="com.testng.examples..Test1" />
                         <class name="com.testng.examples.Test2" /> 
                   </classes>
            </test>
<!-- @AfterTest -->
 </suite>

<!-- @AfterSuite -->

Next

Parameters passed to @Test annotation

•       dataProvider : The name of the data provider for this test method.

•       dependsOnMethods : The list of methods this method depends on.

•       enabled : Whether methods on this method are enabled.

•       groups :  The list of groups this class/method belongs to.

•       expectedExceptions : The list of exceptions that a test method is expected to throw. If no exception or a different than one on this list is thrown, this test will be marked a failure.


•       timeOut : The maximum number of milliseconds this test should take.

Next

Why do we need TestNG in Selenium?

  1. TestNG can generate reports based on our Selenium test results.
  2. TestNG simplifies the way the tests are coded.
  3. Uncaught exceptions are automatically handled by TestNG without terminating the test prematurely. These exceptions are reported as failed steps in the report.

Next

TestNG Annotations

@Test: The annotated method is a part of a test case

@BeforeMethod: The annotated method will be run before each test method.

@AfterMethod: The annotated method will be run after each test method.

@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.

@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.

@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.


@DataProvider : Marks a method as supplying data for a test method. The annotated method must return an Object[][] where each Object[] can be assigned the parameter list of the test method. The @Test method that wants to receive data from this DataProvider needs to use a dataProvider name equals to the name of this annotation. 

Next

How to Install TestNG ?

In eclipse :

1.       Launch the Eclipse IDE and from Help menu, click “Install New Software”.
2.       On the dialog window, click “Add” button.
3.       Type name as “TestNG” and type http://beust.com/eclipse/” as location. Click OK.
4.       You will now see TestNG option selected, if not selected select the check box and click on Next button.
5.       Click “I accept the terms of the license agreement Finish.
6.       Eclipse will prompt to restart . Click on OK.

Else 
  1. Go to Help -> Eclipse Market Place.
  2.  Search for testng.
  3.  Select testNG option and click on install.
  4. Click “I accept the terms of the license agreement Finish.
  5.  Eclipse will prompt to restart . Click on OK.


Maven dependency :
<dependency>

  <groupId>org.testng</groupId>

  <artifactId>testng</artifactId>

  <version>6.8</version>

  <scope>test</scope>


</dependency>

Next

Thursday, 25 August 2016

Parallel Testing with JUnit 4

With increasing demand for parallel testing (saves executions time tremendously) , here is an article from #saucelabs for which explains how it can be achived with Junit 4 and Selenium

http://sauceio.com/index.php/2010/10/parallel-junit-4-and-selenium-part-three-parallelism-and-ondemand/