Integration of Webdriver ruby RSpec test suite with CircleCi

CircleCI has a continuous integration tool which builds and run your application in cloud environment. You can integrate and build your automation test scripts. CircleCI support following language:
Language:
1. Ruby.
2. PHP.
3. Java.
4. Python

Mobile Platform:
1. Android
2. iOS

How to setup:
1. You must have a git account.
2. Click on login circleci it will redirect git account login page.
3. Login in to git with your credential.
4. Click on Add Projects menu.
5. Choose a repository, of GitHub such as pushes and pull requests. It will kick off the first build immediately, and a new build will be initiated each time someone pushes commits.

Working in Git branches

In this post you will learn how to work in Git branches like: create, delete, merge branch data.
1. List all branches of your repository.
$ git branch

2. Create new branch.
$ git branch {branchName}

Example:
$git branch qa

3. Delete the specified branch. This is a “safe” operation in that Git prevents you from deleting the branch if it has unmerged changes.
$ git branch -d {branchName}

Example:
$git branch -d qa

How to read XML file data in Java || How to create object repository in selenium

As most of the commercial automation tools has feature of object repository concept, which separate application objects from automation scripts, it help us to modify object when AUT object change without going into code.  Also if we create object repository then it reuse throughout scripts from one place.

In Webdriver we can put locator (object) of web elements in to xml, properties, excel file etc at one place, and can separate from test scripts with logically divided into files.

In this post I am going to show you how to read data and put locators into xml files.

We create xml files for object locator like “Header.xml” where put all locators related to header menus, “Login.xml” for locators of login page, “Dashborad.xml” for locator of dashboard page.

Codeception webdriver integration

In my previous post of codeception, I posted that how to setup and create codeception acceptance test using phpbrowser. As phpbrowser has following limitation:

  • Can click only on links with valid urls or form submit buttons
  • Not support input fields that are not inside a form
  • Not support JavaScript interactions, like modal windows, datepickers, etc.

So we can integrate codeception with selenium webdriver and can easily handle phpbrowser drawbacks

Road to Codeception setup and first test script for beginner

Codeception:  Codeception is PHP testing framework in BDD stype,It is easy to setup and use, not required any dependency except php. It has three sections for testing
  1. Acceptance Testing
  2. Functional Testing
  3. API testing 
Features:
  1. Can be integrated with selenium Webdriver
  2. Supported Symphony2, Laravel4, YII, Phalcon, Zend framework integration.
  3. BDD style data set.
  4. API testing Rest, Soap, XML-RPC
  5. Report in HTML, XML, JSON.
  6. Parallel execution

Road to generate html report for Python Webdriver test suite using HTMLTestRunner

In my previous post ""Road to create test suite for python Webdriver scripts, I posted that how to create Suite file for webdriver python test script, but In this post I will show you how to integrate test suite with HTMLTestRunner to generate report in html format.

Before going through this post click here ( “Road to create test suite for python Webdriver scripts” ) to see both webdrive python unit test scripts.  I am taking these as example.

Follow below steps to setup:
1. Click on link "HTMLTestRunner" and download “HTMLTestRunner.py”, and “test_HTMLTestRunner.py” file put in your webdriver python project root folder.
2. Import all your test script in “test_HTMLTestRunner.py” as below:
import WebdriverTest2
import WebdriverTest1

Road to create test suite for python Webdriver scripts

In this post I will show you how to create suite file for Webdriver python UnitTest.
Following are two webdriver python unit test script.
1. WebdriverTest1.py

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import unittest, time, re

class WebdriverTest1(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "http://en.wikipedia.org"
       
    def test_Wikipedia(self):
        driver = self.driver
        driver.get(self.base_url + "/wiki/Main_Page")
        driver.find_element_by_id("searchInput").clear()
        driver.find_element_by_id("searchInput").send_keys("India")
        driver.find_element_by_id("searchButton").click()    
   
    def tearDown(self):
        self.driver.quit()       

if __name__ == "__main__":
    unittest.main()

TestNG factory class with example

TestNG factory class is used to create instance of testNg class at runtime (dynamically). When we apply Factory annotation on method, it always return object array of Object class ( “Object[]”). This is useful annotation when you run test multiple time.

TestNG pick @Factory method from class and consider each object mentioned in factory test as a TestNg class and invoke in separate.

Example:  FactoryClassImp.java
package com.tests;

import org.testng.annotations.Factory;

public class FactoryClassImp {

 @Factory
 public Object[] createTest() {
  Object[] res = new Object[3];
  res[0] = new FactoryTestClass(2, 2);
  res[1] = new FactoryTestClass(2, 3);
  res[2] = new FactoryTestClass(2, 4);

  return res;
 }
}


TestNG - Exception Test

In this post I will show you how to handle exception in Testng. TestNg provides expectedExceptions parameter  which is used along with @Test annotation, exp @Test(expectedExceptions)

package com.test;

import org.testng.annotations.Test;

public class TestNgException {

        @Test(expectedExceptions = ArithmeticException.class)
        public void testException() {
               int a = 10;
               int b = 0;
               a = a / b;
        }

        @Test
        public void testException1() {
               int a = 10;
               int b = 0;
               a = a / b;
        }
}

In test method testException I used “@Test(expectedExceptions = ArithmeticException.class)” so airthmetic exception handle but in  test testException1 exception generated.

TestNG - Ignore Test

In this post I will show you how to ignore testng test case to execute,  TestNg provide attribute enabled which make the test to be execute or not, if test mark @Test(enabled = false) then test will not execute. By default enabled value is true.

Here is example for ignore test case:

package com.test;

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

public class IgnoreTestClass {

        @Test
        public void testMethod1() {
               Assert.assertTrue(true);
        }

        @Test(enabled = false)
        public void testMethod2() {
               Assert.assertTrue(true);
        }

        @Test(enabled = true)
        public void testMethod3() {
               Assert.assertTrue(true);
        }
}

Run above test you will see that testMethod2 will ignored and not executed:

PASSED: testMethod1
PASSED: testMethod3

===============================================
    Default test
    Tests run: 2, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 2, Failures: 0, Skips: 0
====================================