Saturday, September 28, 2019

Post#129.Dependency Test in TestNG


Dependency Test in TestNG:
Sometimes, you may need to invoke methods in a Test case in a particular order or you want to share some data and state between methods. This kind of dependency is supported by TestNG as it supports the declaration of explicit dependencies between test methods.

Post#128.Data driven Testing using TestNG


TestNG Data Providers
Data Provider feature helps you to write data-driven tests, which essentially means that same test method can be run multiple times with different data-sets. It helps in providing complex parameters to the test methods as it is not possible to do this from testng.xml file.
Please note that @DataProvider is the second way of passing parameters to test methods (first way we already discussed in @Parameters example).

Post#127.Parallel Execution of test In multiple browsers using testNG


Parallel Execution of test In multiple browsers using testNG
Selenium WebDriver does not have any feature which will allow us to perform parallel execution in multiple browsers. So with the help of TestNG we can perform parallel execution in selenium. 
This can be done by using @parameters annotation.

Post#126.Parallel Execution of test methods in TestNG


Parallel Execution of test methods in TestNG

TestNG provides multiple ways to execute tests in separate threads. In testng.xml, if we set 'parallel' attribute on the tag to 'tests', testNG will run all the ‘@Test’ methods in tag in the same thread, but each tag will be in a separate thread.
If we want to run methods/classes in separate threads, we need to set 'parallel' attribute on the tag to 'methods' / 'classes'

Post#125.Exception Test in TestNG


TestNG – Expected Exception and Expected Message 

While writing unit tests there can be certain scenarios where we need to verify that an exception is being thrown by the program during execution or not. TestNG provides a feature to test such scenarios by allowing the user to specify the type of exceptions that are expected to be thrown by a test method during execution.

Post#124.Optional annotation in TestNG

Optional annotation in TestNG

As we know, we can pass parameter values to the test methods during run time from testng.xml file by specifying Parameters annotation to test method.
To do this, we need to declare parameters tag in xml file using 'name' and 'value' attribute. Where the name attribute of the tag defines name of the parameter and the value attribute defines the value of the parameter.

Post#123.TestNG Assertions


TestNG Assertions:
While using Selenium for automated testing of web applications, we need to add validations in our tests to report them as pass or fail. And assertions can let us do that within a single line of code. Here, you’ll learn how to use TestNG assertions and know the different methods to assert conditions.
Assertions give you a way, other than If-Else blocks, to test conditions. They are not only easy to use but also eliminate the chances of making any error in forming test conditions. Hence, it’s always beneficial to use them in Selenium WebDriver projects.

Post#122.Groups in TestNG

TestNG – Test Groups, Meta Group, Default Group 
Grouping test methods is one of the most important features of TestNG. In TestNG users can group multiple test methods into a named group. You can also execute a particular set of test methods belonging to a group or multiple groups. This feature allows the test methods to be segregated into different sections or modules. For example, you can have a set of tests that belong to sanity test where as others may belong to regression tests. You can also segregate the tests based on the functionalities/features that the test method verifies. This helps in executing only a particular set of tests as and when required.

Post#121.Class level annotations in TestNG


Class level annotations in TestNG
TestNG has the feature to define annotations on a class instead of each test method.
Let’s say there are 20 test methods, where adding @Test on a class level is simpler than adding @Test for each method.

When we make class level @Test annotation, all the public methods of this class will become test methods even if they are not annotated.

Post#120.Timeout Test in TestNG


Timeout Test in TestNG
While running tests there can be cases where certain tests get stuck or may take much more time than expected. In such a case you may need to mark the said test case as fail and then continue. In this tutorial, we will learn to configure TestNG tests to timeout after some configured time duration.
TestNG allows user to configure a time period to wait for a test to completely execute. Timeout can be configured in two ways:

Post#119.Preserve Order in Testng


Preserve Order in Testng
Preserve Order in TestNG will all about the order of test case execution in testNG. If you want your classes / methods to be run in an unpredictable order, then we should go for preserve-order attribute in testng. In TestNg bydefault the preserve-order attribute will be set to 'true', this means, TestNG will run your tests in the order they are found in the XML file.
Let me explain this with below example.

Post#118.TestNG Test Case Priority


Prioritizing Tests in TestNg
Prioritizing tests in testng will discuss about the order of execution tests in test suite. We will write test methods our own way using @Test annotation. After writing the test cases we will execute the test cases either normally or from the testng.xml file. After execution of the tests if we observe the order of execution then we can find that tests executed by taking the alphabetical order. And all the tests will have the equal priority as we did not set any priority to the tests.

Post#117.How to Skip Exception Test in TestNG


How to Skip Exception Test in TestNG
Using TestNG, we have multiple ways to Skip a test based on our requirement. We can Skip complete test without executing it or we can Skip a test when a specific condition is not satisfied.
Case 1: In TestNG, @Test(enabled=false) annotation is used to skip a test case if it is not ready to test. We don't need to import any additional statements.

Post#116.Using Regular Expression To Include-Exclude Test Method From Execution


Using Regular Expression To Include/Exclude Test Method From Execution
In my previous post I have explained testng.xml configuration to include/exclude selected test methods or packages in execution. There is also another way of including or excluding selected test method using regular expression. Let me describe it with one simple example.
First of all configure your Project Structure as below.
Step 1: Create package = "TestNGPack1" and under this package Create classes as Program1.java and Program2.java

Post#115.How to Include-Exclude Selected Test package Using testng.xml File


How to Include/Exclude Selected Test packages using testng.xml File
In this Post I will explain you, how you can include/exclude selected test packages for execution.
First of all configure your Project Structure as below.
Step 1: Create package = "TestNGPack1" and under this package Create classes as Program1.java and Program2.java
Step 2: Create package = "TestNGPack2" and under this package Create classes as Program3.java and Program4.java

Post#114.How to Include-Exclude Selected Test Methods Using testng.xml File


How to Include/Exclude Selected Test Methods Using testng.xml File
In this Post I will explain you, how you can include/exclude selected test methods from execution.
First of all configure your Project Structure as below.
Step 1: Create package = "TestNGPack1" and under this package Create classes as Program1.java and Program2.java
Step 2: Create package = "TestNGPack2" and under this package Create classes as Program3.java and Program4.java

Post#113.How to execute All Or Specific Packages Using testng.xml File

How to execute All Or Specific Packages
In testng.xml file, You can also configure to run specific package or all packages of a project.
Let’s consider that your Project Structure is as below.
Step 1: Create package = "TestNGPack1" and under this package Create classes as Program1.java and Program2.java
Step 2: Create package = "TestNGPack2" and under this package Create classes as Program3.java and Program4.java

Monday, September 23, 2019

Post#112.How to Execute Multiple Classes From Different Packages Using testng.xml File


How to Execute Multiple Classes from Different Packages:
We have already seen example of how to configure testng.xml file to run single/multiple classes of same package. 
In this post we will see how to execute multiple classes from different packages.
First of all let’s create new packages and classes as described in below steps.

Post#111.How to execute Multiple Classes and Multiple Test using testng.xml File


How to execute Multiple Classes and Multiple Test using testng.xml File
In testng.xml file we can specify multiple names which need to be executed.
In a project there may be many classes, but we want to execute only the selected classes.
If say suppose, you have two/multiple classes in your test suite then how will you run them? We can run both the classes in same test as well in 2 different tests.

Post#110.How to configure testng.xml File with TestNG


How to configure testng.xml File with TestNG
In any project, you will end up to a place where you need to execute so many test cases on a run. Running a set of test cases together is call executing a Test Suite. Those test cases can be dependent to each other or may have to be executed in a certain order. The main advantage of using TestNG framework in Selenium is its ease of running multiple tests from multiple classes using just one configuration

Sunday, September 22, 2019

Post#109.TestNG Reporting

TestNG Reporting:
A perfect test automation tool is what you need for the successful execution of the testing requirements in the Agile process. And there are multiple factors which play a critical role in the formation of a robust automation framework. One such factor is reporting which not only make you aware of the status of the success or failure but helps you in finding out the potential bugs. So, you should mindfully choose how you are going to generate reports in Selenium WebDriver project. That’s where this post would lead you to make a decision.

Post#108.Create First TestNG Script And execute


Create and execute Your First TestNG Program:
Before moving forward make Sure TestNG and Eclipse is ready in your System. In my previous post I have explained How to install TestNG. Now we have done with all the basic setup to get started with the test script creation using TestNG. In this post I will discuss How to create a sample script using TestNG.
Before creating TestNG script let’s understand how TestNG script is differ from normal java program and what are the benefits of using TestNG.

Saturday, September 21, 2019

Post#107.TestNG Annotations for Selenium WebDriver


TestNG Annotations for Selenium WebDriver

I have explained the three unique ways to install the TestNG plugin in Eclipse IDE. Now the next important item is to learn about the TestNG annotations.
Annotations are nothing but a piece of instruction for the compiler that you apply to classes, methods or variables in your Java code. It is a powerful feature and an integral part of the TestNG framework. There are multiple TestNG annotations which you can use for different tasks. It is essential to know each of the annotation so that you could apply them correctly while working on a TestNG Selenium WebDriver project. Let’s see what the TestNG annotations for Selenium WebDriver are and what is their objective?

Post#106.Install TestNG In Eclipse IDE Via Offline Jar Files


How to Install TestNG in Eclipse IDE?

3- Install TestNG In Eclipse IDE Via Offline Jar Files.
First step:
Download the latest TestNG Jar files from the link given below.

Post#105.Installing TestNG Plugin In Eclipse Using The “Install New Software…” Feature


How to Install TestNG in Eclipse IDE?

2- Installing TestNG Plugin In Eclipse Using The “Install New Software…” Feature.

First step:

Open the Eclipse IDE, from the main menu bar, select the Help menu and click on the “Install New Software…” option. It’ll launch an install popup window.

Post#104.Install TestNG In Eclipse From Eclipse Marketplace


How to Install TestNG in Eclipse IDE?

1- Install TestNG In Eclipse Directly From The Eclipse Marketplace.

All the new Eclipse IDE versions are now coming up with the Eclipse marketplace plugin. It’s the easier and quicker way to install any third party plugin in Eclipse including the TestNG plugin. Eclipse Marketplace gives you a rich interface to search and install the plugins.

Post#103.Introduction to TestNG


Introduction to TestNG

 

TestNG, as the name suggest, is the next generation test automation tool that fills the gaps in the JUnit framework. The basic idea behind the inception of these tools was to cut down the unit testing efforts during the Java development. However, these tools are now being utilized by the software testers for test-driven development.
Since TestNG is the new entrant, it brings a list of cool features like TestNG annotations, parallel execution, test case management, effective reporting and much more. Interestingly, there is a TestNG plugin that we can integrate with the Eclipse IDE and instantly start creating TestNG projects in Eclipse. In this post, I’ll train you on how to install TestNG in Eclipse. And I’ll showcase the two unique ways for installing the TestNG plugin in Eclipse IDE.
Just to talk a little about the TestNG features such as annotations, they are like the small hooks yet so powerful where you can put instructions to control the flow of a test case, a group of test cases or the whole test suite. Next is the intelligent reporting which comes up with the following key benefits.
§  Tracking of the application performance,
§  Enhance debugging,
§  Quick identification of the defects,
§  Aging and the historical comparison of the data.

Benefits of TestNG

There are number of benefits but from Selenium perspective, major advantages of TestNG are:

1.      It gives the ability to produce HTML Reports of execution
2.      Annotations made testers life easy
3.      Test cases can be Grouped & Prioritized more easily
4.      Parallel testing is possible
5.      Generates Logs
6.      Data Parameterization is possible

I’ve stated earlier that I’ll present you the two ways to install TestNG in Eclipse IDE.  Let’s now get through each of the methods one by one.
1.      Install TestNG in Eclipse directly from the Eclipse Marketplace.
2.      Installing TestNG Plugin in Eclipse using the “Install New Software…” feature.
Before you move to the next section, please make sure you have got the right version of Eclipse software installed.
In case, you are uncertain or don’t have the software then use the below link to download Eclipse.

Friday, September 20, 2019

Post#102.Setup Pipeline in Jenkins



Install Build Pipeline Plugin in Jenkins

Step#1. The settings for the plugin can be found under Manage Jenkins > Manage Plugins.


If you have already installed the plugin, it is shown under the installed tab. If you do not have the plugin previously installed, it shows up under the Available tab.

Post#101.What is CI CD Pipeline?

What is CI CD Pipeline?


CI stands for Continuous Integration and CD stands for Continuous Delivery and Continuous Deployment. You can think of it as a process which is similar to a software development lifecycle.
Now let us see how it works. 



Post#100.How to Configure Email Notification in Jenkins?

How to Configure Email Notification in Jenkins?


Step#1

Navigate: Manage Jenkins->Configure System-> E-mail Notification Section and Click on Advanced... Enter the Details as below.

Post#99.GIT integration with Jenkins


GIT integration with Jenkins


Step#1.  Push your Automation project to GitHub repository. And copy the URL of that repository.

Step#2. Create a Freestyle project in Jenkins as discussed earlier.

Step#3. Select Git under Source Code Management. Paste the repository URL that you copied in Step#1.

Post#98.How to execute Build at scheduled time in Jenkins


How to execute Build at scheduled time in Jenkins


Navigate:-Your job-> Configure-> Build Triggers

Select “Build periodically” check box. Under Schedule text box you can provide time to execute your test cases in given time.

Post#97.Generate TestNG Report in Jenkins


Generate TestNG Report in Jenkins


To generate TestNG reports in Jenkins, we must install TestNG plugins.

Open Jenkins (localhost:8080) and click on ‘Manage Jenkins’ and click on ‘Manage Plugins


Click on ‘Available‘ tab and select the check box against ‘TestNG Results Plugin‘ and click on ‘Install Without Restart



Once the TestNG plugin is installed then Choose to configure the Build.

Go to Post-build Actions and select Publish TestNG Results option.

Save the changes made so far.
Run the project again using Build Now Link, refresh the Page.


Click the TestNG Results and select the Build Number, now it will navigate to result page.



Post#96.Creating and executing Jenkins Job


Creating new jobs


Post#95.Jenkins Introduction & Installation



Jenkins
·       
Jenkins is an open source tool written in Java. It provides continuous delivery and continuous integration (CI) service for software development.
Continuous Integration (CI) is a development practice where developers integrate code into a shared repository frequently, preferably several times a day. Each integration can then be verified by an automated build and automated tests.
Jenkins supports many plugins which you can integrate such as Git, SVN, build pipeline and many more. 

Post#94.GitHub with Eclipse


GitHub with Eclipse ➤

GitHub is highly used software which is typically used for version control. It is helpful when more than just one person is working on a project.
Version Control System (VCS) is software that helps software developers to work together and maintain a complete history of their work.

Post#93.Create Maven Project from Command Prompt


Create New Maven Project from Command Prompt
Step 1: Install and setup maven
Step 2: Use Maven template to generate project structure and artifacts

Syntax:
mvn archetype:generate -DgroupId=YourProjectGroupId -DartifactId=YourProjectName -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Post#92.Convert Java project to Maven Project


Convert the Existing Java project to Maven Project
We have to follow below steps to convert the java project into maven project.

1. Right click on the java project
2. Go to configure option
3. Select convert to maven project

Post#91.Maven Unit Test Report


Maven Unit Test Report

Maven can generate unit test reports in HTML. Maven does so by running the unit tests and recording the results of the unit tests. Maven then generates an HTML report from the unit test results.
Using Maven to generate unit test reports can be useful to see what unit tests fails during the build. Especially if the build is big and takes a long time, because then you might not run all the unit tests from inside your IDE during development. You might only run the unit tests relevant to the changes you make. Then, to check that everything in the project still works, you can tell Maven to run the unit tests and generate a unit test report. You can then read the report to see if any of the unit test have failed during the build.

Post#90.Maven Archetypes

Maven Archetypes


Maven archetypes are project templates which can be generated for your project by Maven. In other words, when you are starting a new project you can generate a template for that project with Maven. In Maven a template is called an archetype. Each Maven archetype thus corresponds to a project template that Maven can generate.

Post#89.Maven-Java Compiler Version


Maven Java Compiler Version

The default Java compiler version used by Maven is Java 1.5 . 
To make Maven compile your Java code with a newer version of the Java compiler, you need to specify the Java compiler explicitly in your project's POM file (pom.xml).
There are two ways to set the Java compiler version in a Maven POM file:

Thursday, September 19, 2019

Post#88.Maven Commands


Maven Commands

Maven contains a wide set of commands which you can execute. Maven commands are a mix of build life cycles, build phases and build goals, and can thus be a bit confusing. Therefore I will describe the common Maven commands in this tutorial, as well as explain which build life cycles, build phases and build goals they are executing.

Post#87.Create and Build Your First Maven Project


Your First Maven Project

To use Maven you must first make sure that you have installed Maven on your computer.

Creating the Project Directory

Once you have assured that Maven is installed, create a new directory somewhere on your hard disk. This directory will be the root directory for your first Maven project.

Post#86.Maven Repositories


Maven Repositories
Maven repositories are directories of packaged JAR files with extra meta data. The meta data are POM files describing the projects each packaged JAR file belongs to, including what external dependencies each packaged JAR has. It is this meta data that enables Maven to download dependencies of your dependencies recursively, until the whole tree of dependencies is download and put into your local repository.
Maven has three types of repository:
  • Local repository
  • Central repository
  • Remote repository

Post#85.Project Dependencies


Project Dependencies

Unless your project is small, your project may need external Java APIs or frameworks which are packaged in their own JAR files. These JAR files are needed on the classpath when you compile your project code.
Keeping your project up-to-date with the correct versions of these external JAR files can be a comprehensive task. Each external JAR may again also need other external JAR files etc. Downloading all these external dependencies (JAR files) recursively and making sure that the right versions are downloaded is cumbersome. Especially when your project grows big, and you get more and more external dependencies.

Post#84.Maven Directory Structure


Maven Directory Structure

Maven has a standard directory structure. If you follow that directory structure for your project, you do not need to specify the directories of your source code, test code etc. in your POM file.
You can see the full directory layout in the Introduction to the Maven Standard Directory Layout.
Here are the most important directories:

Post#83.Running Maven


Running Maven

When you have installed Maven and have created a POM file and put the POM file in the root directory of your project, you can run Maven on your project.
Running Maven is done by executing the mvn command from a command prompt. When executing the mvn command you pass the name of a build life cycle, phase or goal to it, which Maven then executes. 

Post#82.Maven Build Profiles and Plugins


Maven Build Profiles

Maven build profiles enable you to build your project using different configurations. Instead of creating two separate POM files, you can just specify a profile with the different build configuration, and build your project with this build profile when needed.
Maven build profiles are specified inside the POM file, inside the profiles element. Each build profile is nested inside a profile element. Here is an example:

Post#81.Maven Build Life Cycles, Phases and Goals


Maven Build Life Cycles, Phases and Goals

When Maven builds a software project it follows a build life cycle. The build life cycle is divided into build phases, and the build phases are divided into build goals. 

Post#80.Maven Settings File


Maven Settings File
Maven has two settings files. In the settings files you can configure settings for Maven across all Maven POM files. For instance, you can configure:
  • Location of local repository
  • Active build profile
  • Etc.

Post#79.Maven POM Files


Maven POM Files

A Maven POM file (Project Object Model) is an XML file that describe the resources of the project. This includes the directories where the source code, test source etc. is located in, what external dependencies (JAR files) your projects has etc.

Post#78.Maven Overview - Core Concepts


What is Maven?
Maven is a powerful project/build management tool that is based on POM (project object model).

Post#77.Maven setup to execute from command prompt


Installing Maven:
To install Maven on your own system (computer), go to the Maven download page and follow the instructions there. In summary, what you need to do is:
  1. Set the JAVA_HOME environment variable to point to a valid Java SDK (e.g. Java 8).
  2. Download and unzip Maven.

Post#76.Maven setup in Eclipse for Selenium Tests


Running WebDriver Tests Using Maven in Eclipse IDE
Maven is a well-known tool for building large Java applications. In this tutorial, we’ll discover what Maven is and what advantages it has over other build tools like ANT? Finally, we’ll expose a detailed process of building WebDriver project in Maven.
Eclipse is one of the most widely used IDE in the Java world. It provides support for various plug-ins like Maven to ease up the build management tasks for Java projects.
Before we get through the procedure for running Webdriver tests using Maven, let’s begin by understanding the Maven.

Post#75.Extent Report version 3


Generate Extent Reports in Selenium WebDriver:

Selenium provides inbuilt reports using frameworks such as JUnit and TestNG.
Although the built-in reports provide information on the steps that are executed as part of the test case, they need more customization to be shared with all the major project stakeholders.

Post#74.Log4j with Selenium

Log4J

Log4j is framework which helps the java user to record the messages (logs) during the execution time. Logs are nothing but the detailed execution steps
Log4j write all the messages into files, files could be in many formats like text file, logfile, html file. Users have to configure the log4j before using it.