UI Automation

Exceptions

Exceptions are run time errors that could let the running program to break unexpectedly. The exceptions should be handled correctly to communicate the issue to the user or stop the unnecessary break of the application. The technique of handling exception is using a try { } catch(Exception e) { } statements.

@Method - 1
 try{
            userNameField=driver.findElement(new By.ByName("my-text"));
            userNameField.sendKeys(userName);
            Thread.sleep(TIMEOUT);
        }
        catch (ElementNotFoundException e){
            throw (e);
            
        }

@Method-2
  try{
            userNameField=driver.findElement(new By.ByName("mytext"));
            userNameField.sendKeys(userName);
            Thread.sleep(TIMEOUT);

        }
        catch (ElementNotFoundException e){
            return false;
        }

Figure 1.4 :- Exception Handling

BDD and TDD

  • TDD is a Test Driver Development which has an approach writing down first a Test then maintain the test in order to reach to the solution It starts with RED, YELLOW, and then finally GREEN.
  • BDD is a Behavioral Driver Development which has an approach of testing solution writing down the exact behavior of the application. The framework is more readable since it is using a plain text and any one can understand without a need of technical background.

Cucumber

It is a framework that could let us to write down plain English text to script the behavioral nature of the application. the framework has got a keywords such as Given, When, And , Then. The following example demonstrate the BDD test script using Cucumber

/*Checking a home page and/or a disable field */

Feature: Home Page
Background: Pre-Conditions
  Given I open the main page
@Scenario-1
Scenario: Checking The Title Of A Page
   When I check the page title
   Then The page has got a title "web form"
@Scenario-2
Scenario Outline: Check Disabled Fields
   When I checked disabled fields "<field>"
   Then The field "<field>" is disabled
      Examples:
      |field|
      |input_disabled|
/*Searching all registered user 
and/or specific user */
Feature: Registered user
Background: Logged In As E-Commerce User
     Given I logged in successfully to the e-commerce application. 
     And The application page loaded successfully.
@Scenario-1
Scenario: Search all registered user
    When I tap on search “Search all = user” button
    Then I see all registered users details
@Scenario-2
ScenarioOutline: Search specific registered user 
    And I click on “search user”
    And I type “username”in the search box
    When I click on “search”button
    Then The target user with “username” successfully displayed
    Examples:
     |userName|
     |abert_rama@reply.com|

Figure 1.5 :- Cucumber – BBD

Keywords

There are various keywords integrated with the Cucumber framework that could let us to create a BDD scripting.

  • Features :- Define the name of functionality
  • Background : – uses to set up the pre-conditions
  • Scenario : – Name each scenarios in the feature using Given When, And, Then Keyword
  • Scenario Outline : – Used to write down a scenario having example with several inputs for the same type of work
  • Examples : – represent the possible values that the scenario should be expected
  • Tags: – Label any element of the feature and will be used to run the test automation smooth for those labelled with a certain tags. Possible tags @sprint, @smoke_test, @regression

Hooks

Cucumber Hooks allows us to better manage the code workflow and helps us to reduce the code redundancy. some of the know Hooks are @Before or @After. This will let us to run a scenario @Before or @After.

@Before
    public void initDriver() {
        homePage= new HomePage();
        webDriver= new WebDriverSet();
    }

 @After
    public void teardown() {
        webDriver.getDriver().quit();
    }

Reports

The report is one of the final result that every automation activity is expected to have it. This confirm the health fo your Project. Once you show it to management, they can make decisions to ship it to the customer.The report can be default or with a plugin libraries like Extent reports.

The report will be presented in HTML format which demonstrate the passed, failed tests. It is also possible to add a screenshot or a description about why the test failed, and other details that could help us to determine the cause of the failurity.

There are three main different ways to generate reports

  • TestNG
  • Junit
  • Extent Report

Cross Browsing/Browser Compatibility Matrix

It its technique writing UI test automation for various types of Browser. The same script can be used just by changing browser type to interact with web elements. For such kind of activity it is important to set a scope to the most relevant browser-OS combinations, thus help us to make the process more manageable.

Scroll to Top