مدونات

Automation Testing Guide  Website

03

19 سبتمبر

Ahmed Adel

For: POs, Developers, and Testers.Version Number: V 1.0 

  • Introduction

 

    •  Introduction to Test Automation
    •  When to Automate
    •  The Test Automation Process
    •  Test Automation Tools
    •  Benefits of Test Automation

 

 

  • About the Automation 

 

    •  Cost Reduction
    •  Productivity
    •  Availability
    •  Reliability
    •  Performance 

 

 

  • Target User

 

    • Product Owners 
      • Prerequisites before testing start
    • Developers 
    • Testers
      • Environment Tools
      • Project Platforms
      • Steps to build a project structure 

 

Introduction 

 

Introduction to Test Automation

For many software projects, test automation is becoming a vital part of the development process. This is because it enables teams to verify functionality, test for regression and run tests simultaneously in an efficient way. Though manual testing has traditionally been the method employed by many organizations, with the growing number of web-based applications and the increase in quality tools in the marketplace, this is no longer the case. Test automation is the right choice for many projects because it makes verifying and testing web-based interfaces easier than ever before.

When to Automate

There are several situations when automated testing is beneficial. In general, you should automate testing for projects with these characteristics:

  • Large scope and critical specifications
  • Frequent testing of the same areas
  • Requirements are stable and do not change frequently
  • Need for assessment of the application for load and performance with virtual users

 

The Test Automation Process

In order to automate testing processes, teams use software tools to write scripts. The following is an overview of the automation process:

  • Identify the areas within software that need testing
  • Select the appropriate automation tool
  • Write test scripts
  • Develop test suits
  • Execute test scripts
  • Create a result report
  • Identify any potential bugs or performance issues

Test Automation Tools

There is a wide variety of QA testing tools that software teams can use to build and execute automated tests. The following tools, in particular, make the automation process for web applications easier.

Selenium: This tool is a portable software testing framework that provides a record/playback tool that allows teams to author tests without learning a scripting language. It provides a test domain-specific language to write tests in a variety of popular coding languages. Using Selenium, tests can be run for most web browsers. Selenium is an open source.

Rational Function Tester: The Rational Software division of IBM created Rational Function Tester. This tool allows users to create tests that simulate the actions of a human tester. This tool is primarily used by quality assurance teams.

Testing Anywhere: This software allows developers to test applications, web sites, objects, controls and more. It is produced by Automation Anywhere, Inc. and can also test GUI front-ends.

HP LoadRunner: Hewlett-Packard designed this tool, which can be used to test applications for system behavior and performance under load. It is able to simulate a large number of users interacting with the application software at the same time. It records and analyzes performance by simulating this user activity.

SoapUI: This tool is open-source, created for service-oriented architectures (SOA) and representational state transfers (REST). It can test web service inspection, development, simulation, functional testing, load and compliance testing, and more. It is built entirely on the Java platform

Benefits of Test Automation

Automated testing is an ideal way of ensuring that new versions of an application don’t introduce bugs or performance issues. It allows development teams to complete projects more quickly because they can quickly verify functionality after each change.  And apart from regression testing, automation can be used to test an application for load, performance, and stress. This increases test coverage improves accuracy and can be cheaper and more efficient than manual test

About the Automation

General information about the importance of automation 

1. Cost Reduction

Every business faces global pressure to increase their profitability. One approach is to reduce costs. But, reducing the capabilities of the computer center negatively impacts the entire company.

Automation software is a better and more intelligent approach to cost containment and reduction. The greatest opportunity is to increase service to the customer (end user) while systematically reducing costs. Management often overlooks this potential for savings. Most modern servers have a low operating cost and the total cost of ownership has been declining. Even so, the cost of the operations staff can be as high as 71% of the total cost.

2. Productivity

As an organization’s technology demands grow, productivity becomes a bigger concern. Typically, as other business areas were given tools to increase their productivity and effectiveness, IT operations took a back seat. The proliferation of desktop productivity software has created substantial gains in the office and HR environments. But, instead of alleviating the workload for the IT professionals in the back room, the spread of PCs has meant more tasks to be accomplished.

As people use computers more, they place greater demands on the system. More users are generating more jobs, and printed output has increased despite efforts to reduce printed reports. In spite of the trend to online transaction-oriented and client/server systems, batch workloads continue to grow. Production batch jobs still consume the majority of CPU time, and in large shops, jobs are constantly being added.

 

3. Availability

Companies are continually more reliant on their computers. Day-to-day business is routinely conducted with online systems: order entry, reservations, assembly instructions, shipping orders—the list goes on. If the computer is not available, the business suffers.

Years ago, it was considered acceptable to have the computer unavailable for a few hours. Today, with the high volume of cloud computing, the outage of key systems can cost millions of dollars in lost revenue and tarnish a company’s reputation.

High availability is clearly one of IT management’s primary goals. Here too, automated operations can help. A disk drive may crash, but the situation becomes serious when there is not an adequate backup— or worse, the tape cannot be found. A key advantage to automation is the ability to automate your save and recovery systems to ensure protection from the potential disaster of disk loss, or inadvertent damage to system objects from human error.

In a networked environment, centralized management also makes sense. Remote resources can solve business issues while a single operator at a central console observes critical functions throughout the network. Continuous monitoring with a low CPU and communications overhead makes it easier to spot vital network performance trends.

 

4. Reliability

Productivity is an obvious benefit of automation. However, reliability is the real gem that sparkles with automation. It is the cornerstone of any good IT operations department and without it, you have confusion, chaos, and unhappy users. IT operations require two opposed skill sets: On one hand, an operations person needs highly technical skills, such as the ability to understand the complexities of an operating system and to analyze and solve problems as they arise. On the other hand, this same person has to be content pushing buttons and loading paper. 

Let’s face it, off-shift operations include some of the most boring, repetitive, and error-prone tasks of an IT organization. But, when you remove the human factor, you eliminate most batch processing errors.

Automated operations ensure that jobs are not forgotten or run out of sequence, that prerequisite jobs are completed successfully, that the input data is correct, and that any special processing is performed.

All these types of errors occur in single-location organizations. Now, imagine a network of multiple systems, geographically dispersed that include multiple operating systems, communications issues, integrated local area network processing, and attached PCs. The chance for errors rises exponentially. The only way to make this type of environment work is automated operations.

The software can handle complex tasks dynamically and intelligently, based on predefined parameters. Yet, critical company functions such as releasing jobs, performing backups, and ensuring communications, are normally performed by entry-level individuals within the IT organization. The benefit of an automated system is that these functions are reliably executed by the automation software, relieving operations personnel from hours of tedious, boring and manual tasks.

 

  1. Performance 

Every company would like to have their enterprise perform like a thoroughbred. In reality, it is more likely to be overburdened with work. Even though advancements in computers make them faster and less expensive every year, the demands on them always catch up and eventually exceed the level of capability that a company’s computer infrastructure possesses. That leaves a lot of companies wanting to improve their system performance.

Two options to improve performance are to upgrade hardware or purchase a newer system—both expensive choices. It’s also possible to tune a system for better performance, but this takes a highly skilled person who is not normally available 24 hours a day. And, once a system is tuned for a specific workload, if the workload changes, the settings are no longer optimum.

 

Target Users

 

Product Owners 

 

Prerequisites before testing start

 

  • Following are the requirements which should exist before the release plan in order to have the automation testing in your project
  • The decision if the automation will be done for the project and if it will add value. 
  • Ready design or full wireframe
  • Make sure that to ask for a unique identifier for each element in the developers ( could be added on the DoD)

 

Developers 

 

  • Unique identifier for each element 
  • Automation tester should be informed if there is any change of element’s ID

 

Testers 

 

Environment Tools :

 

  1. intellij Ide / Eclipse Ide (https://www.jetbrains.com/idea/download/?utm_source=product&utm_medium=link&utm_campaign=IU&utm_content=2018.2#section=linux ,
    https://www.eclipse.org/downloads/ )
  2. Selenium for web (https://www.seleniumhq.org/ )
  3. Maven (https://maven.apache.org/ )
  4. TestNg (https://testng.org/doc/index.html )
  5. Java Faker (https://github.com/DiUS/java-faker )
  6. Use Page Object Model as Design Pattern (https://medium.com/tech-tajawal/page-object-model-pom-design-pattern-f9588630800b )
  7. integration with jenkins (https://jenkins.io/ )
  8. Java as language (Required)
  9. OOP (Required)

 

Project Platforms :

 

  1. FireFox Last Version driver (https://github.com/mozilla/geckodriver/releases )
  2. Chrome Last Version driver (http://chromedriver.chromium.org/downloads )

 

Steps to build Project Structure :

 

1-Make Maven project 

2-Add selenium as a dependency in a project in pom.xml link

3-Add testng as a dependency in the project

4-Add java faker as a dependency in the project

5-make class helper to print screenshot after catching the bug like this 

 

// Code

 

package utilities;import java.io.FileOutputStream;

import java.io.IOException;

import java.nio.file.Path;

import java.nio.file.Paths;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

public class Helper {

// Method to take screenshot when the test case fails

public static void caputreScreenShoot(WebDriver driver, String   screenShootName) {

Path dest = Paths.get(“./ScreenShoot/ScreenShoot” + screenShootName + “.png”);

try {

java.nio.file.Files.createDirectories(dest.getParent());

FileOutputStream out = new FileOutputStream(dest.toString());

out.write(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES));

out.close();

} catch (IOException e) {

System.out.println(“Excpetion while take screen shoot” + e.getMessage());

}

}

}

 

6-Split the project into two parts 

 

  • First part is page base like this to make user can init elements with the driver 

 

  • In page base part you add all function & element you catch it to use it in your script because the user should be don’t see a function in the test part 

 

// Code

 

package pages;

import org.openqa.selenium.JavascriptExecutor;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.support.PageFactory;

import org.openqa.selenium.support.ui.Select;

public class PageBase {

public WebDriver driver;

public JavascriptExecutor jse;

public Select select;

// create constructor

public PageBase(WebDriver driver) {

PageFactory.initElements(driver, this);

}

public static void clickButton(WebElement button) {

button.click();

}

public static void setTextElementText(WebElement textElement, String value) {

textElement.sendKeys(value);

}

}

 

  • Second part is tested base like this & in this part you build two platforms to make the user uses it (FireFox , Chrome) & add URL to direct user to website to make automation on it & in this part you start the driver & close it after finishing the script you run & after any method you call the helper method you make to catch bug if found it & add it in screenshot folder to see it after

 

  • in the test part, you call all the function & method you make in the page base part 

 

// Code

 

package test;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.phantomjs.PhantomJSDriver;

import org.openqa.selenium.phantomjs.PhantomJSDriverService;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.testng.ITestResult;

import org.testng.annotations.*;

import utilities.Helper;

public class TestBase {

public static WebDriver driver;

@BeforeTest

@Parameters({ “browser” })

public void startDriver(@Optional(“firefox”) String browserName) {

if (browserName.equalsIgnoreCase(“firefox”)) {

System.setProperty(“webdriver.gecko.driver”,

                                              System.getProperty(“user.dir”)+”/drivers/geckodriver”);

driver = new FirefoxDriver();

} else if (browserName.equalsIgnoreCase(“chrome”)) {

System.setProperty(“webdriver.chrome.driver”,

                                              System.getProperty(“user.dir”)+”/drivers/chromedriver”);

driver = new ChromeDriver();

driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.navigate().to(“https://asala-dashboard.ibtikar.net.sa/auth/login”);

}

@AfterTest

public void stopDriver() {

driver.quit();

public void stopDriver() {

driver.quit();

}

// Take Screenshot when test case fail and add it in the screenshot folder

@AfterMethod

public void screenShootsOnFailure(ITestResult result) {

if (result.getStatus() == ITestResult.FAILURE) {

System.out.println(“Failed!”);

System.out.println(“Taking ScreenShot…….”);

Helper.caputreScreenShoot(driver, result.getName());

}

}

} public void stopDriver() {

driver.quit();

}

 


// Take Screenshot when test case fail and add it in the screenshot folder

@AfterMethod

public void screenShootsOnFailure(ITestResult result) {

if (result.getStatus() == ITestResult.FAILURE) {

System.out.println(“Failed!”);

System.out.println(“Taking ScreenShot…….”);

Helper.caputreScreenShoot(driver, result.getName());

}

}

}

 

  •  until this moment the automation can run the script manually from ide 

 

  • but to use this code to achieve the full cycle automation should use jenkines tool & Testers Make job on it to run all script after deployment the developer does 
تعليقات