Code Refactoring : Why Is It Crucial For Software Testers

Software development involves one of the major key terms which is essential for the testers. This key term is known as Code Refactoring.

We’ll take a closer look at this technique and how important it is to know. What are the benefits associated with code refactoring? And most importantly why testers need to know about it?
What Exactly is Code Refactoring?
Basically, software normally fails when it becomes so complex that it can no longer provide additional features while remaining error-free. Code refactoring is used to improve code design to make it easier to understand and extend.
It is the process of modifying the code without actually modifying the functionality of that code.
If you believe a feature may be needed in the future and your current code won’t easily be able to accommodate it, you refactor that code to make it easier to add that feature now rather than worrying about what you need to change with your code to add the feature later.
Why There is a Need For Refactor?
By moving duplicate code, you remove the amount of code and hence, the less code that you have the easier it is to modify as well as to understand.
If you’ve looked at huge programs and tried to understand how they work by writing understandable codes, you will be able to easily modify the code using the process of code refactoring.
This will enable you to understand the system better. This would come into play if you were given someone else’s code. Very often, you can look at that code and not have any idea what’s going on, but if you go in and refactor it on your own, you’ll completely understand of how the system works.
By better understanding the system, the easier it will be to spot bugs.
Moreover, if you’re writing understandable codes, refactoring will help you to write these codes quicker.
Adding the features in source code usually takes a lot of time and tries to fix bugs by going back repetitively.
Therefore, instead of adding features to your code, try to go back and understand the code better which will help you to get rid of bugs. Not only this, it also makes code easy to read by minimizing the complex conditional logic and eliminating duplications.
Many people think refactoring only deals with forcing design patterns into your code, this is absolutely not true. However, that is what you spend a lot of your time doing. Creating a better design is the simple goal of refactoring.
Types of Code Refactoring
There are many techniques of code refactoring, but we’ll discuss only few which are commonly used and easy to learn. Following are the types of code refactoring:
1. Preparatory Refactoring: While creating an application, there are certain aspects which testers can use in their codes to make it effortless while building new features for their code. This feature is called preparatory refactoring. While adding a new feature in the code, the existing code might be structured in such a way that makes it difficult for them to add new features. With the help of this technique, they can first refactor the structure of the code which makes it easier for them to add new features.  
 2. Red-Green Refactoring: This approach of refactoring helps the testers to build a test suite, write codes and modify their code in a short period of time. This type of refactoring is based on Test-Driven Development where testers first writes tests and then uses these tests to modify and develop software applications. It can be broken into three phases:

  • Red: This is the first stage of the Red-Green-Refactor In this phase, the tester generally writes a test that informs the implementation of a feature. Only if the exceptions are met, the test will pass.
  • Green: The green phase is where the tester will implement codes to ensure the test pass. The main purpose is to find an optimal solution without modifying the implementation.
  • Refactor: This stage is the final stage of the cycle which involves the thinking and how a developer/tester can implement ideas to improve the code with better efficiency.

3. Composing Methods Refactoring: In most cases, the code can be extremely long and repetitive. This may cause difficulties in understanding the logic of the code and thus becomes harder to change. This refactoring technique will eliminate every repetitive code, or remove any other streamline This will help the tester to easily understand the logic and look for any other improvements.
4. Simplifying Conditional Expressions Refactoring: Conditional expressions can sometimes become more complicated which also complicates their logic over time. This approach of refactoring will simplify the conditional expressions which eventually turn the code simple and understandable. The logic behind complicated conditional expressions becomes clearer and it is easier for the tester to understand logic better.
Benefits of Using Code Refactoring
There are various benefits that are associated with the use of code refactoring. These benefits are mentioned below:

  • Efficient Process: Using this technique eliminates the efforts that are needed in the future while modifying or adding any new features to the code which eventually improves efficiency.
  • Eliminates Complexity: It helps in the reduction of complexity thus makes it easier for you and your team to work on a development
  • Sustainability: Code refactoring usually organizes and creates clear codes that are easy to read and understand. Thus, it helps in maintaining a properly structured code which is ready for an improvement in the future.
  • Easy to Read and Understand: No doubt, code refactoring will make it easy for people to read and understand the code more effectively.
  • Understand the Concept Better: When there is only one method which handles all the functionality of the process, there are chances that it becomes exceptionally complex to understand. If the process is broken down into parts it is easy to understand what actually is really being done. This can be achieved through the use of code refactoring.

Why does a Tester need to Know About Code Refactoring?
 As the term code refactoring has been discussed in brief, we’ll look for the further important question which needs an answer. Thus, discussed below is the answer to the question, why a tester needs to know about refactoring?
1. For Unit Testers: Refactoring the code means adding of new code and updating different elements of the code. Such as new classes are being added, old classes, are being updated which leads to failure of existing unit testing. Thus, the Unit tester needs to create and set up new unit tests for these updated classes.
2. For Testers: When the code is refactored (considering there is no addition of new features) the functionality of the code remains the same for the end users. For testers, to test a refactored code usually means to use comprehensive testing and regression testing. In comprehensive testing, the tester will ensure whether the functionality of the code is working as before or not and In regression testing, tester ensures whether the updated code has affected the functionality of the code or not.
3. For Automation Test Engineers: The functional and non-functional automation scripts may face failure if the code is refactored. This may occur because the selenium automation which tester uses, rely on the page objects. If these page objects are updated during refactoring procedure it may cause the failure in an automation To overcome this failure, it is recommended for automation testers that functional automation tests should only be conducted when the feature of code has become stable otherwise, there would be a lot of rework.
 4. For Test Leads: Test leads usually work together with the development team, product analyst and stakeholders to ensure proper test planning of the projects is done carefully. Therefore, it is important to ensure the proper documentation and functioning of the product, user flows, user acceptance tests or business cases. If the code is refactored, these scenarios need to be validated with the help of regression testing of the affected functionality.
Use of Refactoring Technique for Testers
Refactoring can be important for testers too, here are a few reasons to illustrate why it is important for testers to use refactoring techniques.

  • Testers ensure the proper testing of the functionality of the application. As the test written by testers is code too, it is necessary for testers to use refactoring technique to simplify their complex code.
  • The test code written by testers should be easily understandable and readable. Using code refactoring , the tester can use better expressions which make it easier for other testers to understand the test code.
  • As the develop uses code refactoring to make their code easier to update, in the same way, testers can also use this technique to make their test easy to update.

app testing
To summarize above details, learning code refactoring can be beneficial for the testers to improve their test cases as well as to make proper test procedure for developer’s refactored code.

Also Read : TestCafe vs Selenium : Which is better?

How to Integrate Selenium With Gecko Driver : Full Tutorial

Mozilla Firefox browser’s versions greater than 47.0 were not compatible with Selenium WebDriver 2.53.0 or 2.53.1 that means Firefox browsers version after 47.0 can’t be used in Selenium without any drivers. As of version 3.0, the Selenium uses a driver to form a link with Firefox browser. This driver is known as Gecko Driver.

Before starting with the GeckoDriver you need to understand what is GeckoDriver, why it is required in Selenium WebDriver? Or how can it be used in Selenium? Let us start with the very basics.
What is a Web Browser Engine and What is Gecko Driver?
Web browser engine is a software program that is used to control and enter the content such as HTML, CSS, XML, images etc.
On the browser and therefore it is also known as layout engine or rendering engine. It is a component of browsers and helps in displaying web-content.
Gecko is a web browser engine which is developed by Mozilla Foundation and is written in C++. It is an open source engine which can be easily available for the user.
GeckoDriver is a proxy which is used to interact with the browsers (such as Firefox) that run the Gecko browser engine. GeckoDriver provides an HTTP API to communicate with Gecko browsers (like Firefox version 47 onwards).
Why Selenium Needs Gecko Driver?
Until Selenium version 2, it had Firefox driver which were used to interact with the Firefox browser (version till 47).
Now, Firefox (with Firefox browser version 48 onwards) has done some changes and due to some security reasons, it does not allow any third party driver to directly interact with the browser.
Also Read : How to Integrate Maven and Jenkins with Selenium 
That means the user cannot use Firefox driver of selenium version 2 to interact with the browser version 48 onwards.
Thus, we need Selenium 3 which has marionette drivers and with this user can directly interact with the Firefox browsers using a proxy which is GeckoDriver. Marionette driver is an automation driver for Mozilla’s Gecko engine.
Getting Started with GeckoDriver
This section will help you to install Selenium 3 Jars and GeckoDriver for Firefox browser. Below are the steps which you need to follow:
Step 1: To Add Selenium 3 jars
If you are using Selenium 2 jars, you can easily upgrade it to Selenium 3 Jars by following this link.
www.seleniumhq.org
Click on download option and you will find “Version 3.0.1” to download. Click on the link to download Selenium 3 jar.
Now, copy this jar file by using ‘CTRL + C’ and go to your selenium tool. You will find ‘lib folder’ in test explorer.
Select ‘lib folder’ and right click to open options and select New > Folder and set folder name as ‘selenium3jars’ to make it easily accessible or whatever name you want to use.
You will see, the ‘selenium3jars’ folder is created as a children folder under ‘lib folder’. Use ‘CTRL + V’ to paste selenium 3 jar file that you copied earlier and paste inside ‘selenium3jars folder’.
You’ll see the jar file has been successfully copied to the folder. Next thing you need to do is to add this jar file into your project. You need to select Selenium 3 jar file and right click to open the options palette. Then left click on Build Path > Add to Build Path to add jar file into your project easily.
You’ll see that Selenium 3 jar has been added to Referenced libraries that mean your selenium is ready to execute the tests via the driver.
Step 2: Installing Gecko Driver
To download GeckoDriver for your WebDriver you need to follow this link.
https://github.com/mozilla/geckodriver/releases
If you are running 32bit or 64bit Windows, MACOS, or Linux you can easily download the file which is compatible with your operating system.
You’ll see many versions to download, but you can choose the latest version from the options. You can easily download this zip file to your computer by clicking on the appropriate link.
If you are using windows operating system, you can download either win32.zip or win64.zip and if you are using MAC operating system then you can choose macos.tar.zip.
After downloading the zip file you can simply extract it in your preferred location and then copy the GeckoDriver.exe file using ‘CTRL + C’.
Again, you have to follow the same procedure to copy this file in the ‘lib folder’.
Go to Selenium and select the lib directory from the test explorer. Again, right-click to open option palette then left click on New > Folder to create a new folder.
automation testing
Then set the name as ‘geckodriver’ or any other name which is easier for you to recognize and click ‘Finish’. Then you have to add a GeckoDriver.exe file into the folder you have just created.
After adding a geckodriver.exe file to a folder, the next step is to use the following syntax to show the exact location of the executable file.
Syntax

System.setProperty(webdriver.gecko.driver”, ”location of gecko driver executable”);

You need to enter the exact location of the executable file in the above syntax. To see the location of your file, you can select a geckodriver.exe file from the folder and right click to open the options palette. Then left click on the properties to open details.
Select the location and copy all. Use this location address to enter this address in the syntax. For instance:

System.setProperty(“webdriver gecko driver”, “C:/Users/raghav/Desktop/Tools/Eclipse/Selenium/SeleniumTest/lib/geckodriver/geckodriver.exe”);

If you find it difficult to add the location manually or showing any unwanted errors, you can also use an alternative method to add an executable file to your project.
Go to your computer and search the above location in the file explorer. Then copy the executable file from the downloaded folder to the current address location.
Left click and drag the executable file from the download folder to the location of the searched folder. The dialogue box will appear saying to replace it or not. Click on replace button and copy the .exe file to the folder.
Step 3: Adding Latest Version of Firefox Browser
Download the latest version of Firefox by following this link
https://filehippo.com/download_firefox/
In the next step, you need to add the syntax and also the location of this browser.
Syntax

System.setProperty(webdriver.Firefox.bin”, “Location of Firefox exe”);

Again, you need to enter this syntax in your selenium tool and also the exact location of the Firefox.exe file.
To know the exact address of the .exe file you can select firefox.exe and right click to open option palette. Then left click on properties to know the location.
Copy the location and enter this address in the syntax. For instance:

System.setProperty(webdriver.Firefox.bin”, “C:\Program Files\Mozilla Firefox\firefox.exe”);

Use of Gecko Driver to Launch Firefox Browser

import org.openqa.selenium.WebDriver;[]
public class FirstSeleniumTest {
public static void main(String[] args) {
System.setProperty(“webdriver gecko driver”,      “C:/Users/raghav/Desktop/Tools/Eclipse/Selenium/SeleniumTest/lib/geckodriver/geckodriver.exe”);
System.setProperty(webdriver.Firefox.bin”, “C:\Program Files\Mozilla Firefox\firefox.exe”);
 WebDriver driver = new FirefoxDriver();
driver.get(Http://www.google.com/);

This code is used to generate a test for Firefox browser when executed. It will open the Firefox browser and go to the link which is specified in the code.
In this test, the Firefox will open selenium.org website and after successful loading of the file, the test will close the Firefox browser and execution will be completed.
You need to remember, if you want to move your project to a new location, the current address which you have specified in order to add Firefox.exe and geckodriver.exe will not run.
You need to specify their location again if you wish to move your project location.
Understanding the Code
1. Import org.openqa.selenium.WebDriver: This syntax is used to import every reference which is needed for the WebDriver This WebDriver is later needed to represent the new browser.
2. setProperty: This syntax is used to set the system property to have some value. The browser does not have its own inbuilt server which can run the automation code. Therefore, System.setProperty is needed for the browser to set a respective path.
3. WebDriver driver = new FirefoxDriver(): This syntax is generally an interface which contains methods defined by the user to perform on the Firefox browser.
4. get(http://www.google.com): This syntax will lead the browser to go to the specified link and open it.
Additional Tips:

  • Always run automation on a separate browser version
  • Use selenium 3 with latest (stable) version of Firefox
  • Have Java 8 or higher for Selenium 3

Top 10 Game Testing Companies In India

The gaming industry has changed a lot in the past few years in India. With the advancement in technology, the game testing companies in india have seen an unexceptional boom in the industry with so many games developed and launched in the market globally.

There is no doubt that the demand for interactive games has increased a lot in the recent times.
The rise in the gaming companies is the major show point of the increment that is using the demand in their favour at every turn.
However, with development comes testing that is one of the most crucial points of the gaming.
Here are the top game testing companies in india that are making their names in the national as well as international market.
1. Testbytes – Pune
With Pune as their home ground Testbytes has managed to gain good reputation within a short span of time.
They have a pretty decent track record and have clientele spread around the world.
Testbytes offer wide range of testing services and game testing one among them. They have a big team of testers who has got years of experience and exposure to various test scenarios and can perfectly and professionally manage testing procedure with ease and efficiency. Their test environment is also equipped to carry out any sort of testing.
2. SuperSike Game – Delhi NCR
They are the government registered privately held software development company that is famous for their design, development, testing and on-time delivery of the gaming software and application for India based platforms of smartphones.
19 Studios are providing their services in the Unity 3D Game Development, Mobile Game Design Services and Game Testing Services.
They have managed to set out their footprint in the global market that is power-driven by the best and experienced brains.
19 Studios have its headquarters in Delhi but are widely spread in the global market due to their best gaming solutions.
They deal in core services of Game Testing Services, Augmented Reality Development, 3D Modeling & Animation, Web Application Development, Unity 3D Game Development and many more. The games under their achievements are See and Match, Paint Ball Game, Treasure Match, etc.
3. Rolocule – Pune
It is one of the reputed game development and testing company that is in the market for over decades.
They are backed off by some of the leading investors including IIM Ahmedabad, Blume Ventures and Mumbai Angels.
The games that fall under the name of Rolocule development are well-known in over 110 countries.
Their headquarters are in Pune with the consistent delivery in the international market with the top-quality that is loved by millions of heart.
They deal in design, 3D development, testing and Modeling and animation. The games under their name are Flick Tennis, Dead Among Us, Dance Party, etc.
4. Ironcode Gaming – Dehradun
The Ironcode has experienced, creative and professional members that deals with developing unique games. In addition to this, they provide full service for the concept development of the games and testing.

Once, everything is set, they even deploy the gaming application. They have already written names on multiple platforms such as Windows, Linux, Mac, Android, iOS.
In addition to this, you can find them on Appstore, Steam, Amazon, Google Play, AOL, BigFish Games, and Yahoo, etc.
The headquarters of the company is in Dehradun with their own cross-platform gaming development services even though they have a third-party engine for the consumertasks.
Their team provides services such as Unity 3D Game Development, Game Designing, Lastman Standing Games, Riotball, Angkor, Turbogems, Pahelika Series, and 2D/3D art.
5. Ingenuity Gaming – Noida
Ingenuity is in the gaming sector for over 13 years and has managed to evolve the sector at a drastic rate.
They are now a multi-channel development studio whose aim is to offer services for the e-gaming and land-based sectors.
The industry has proven their worth with the rating record of their 500+ games that are amazing customers at a global rate.
Also Read : Top 7 Test Automation Companies In India

They are focused on providing gaming solutions in such the way to provide the best solution to the customers.
The headquarters of the industry is in Noida with approximately 250+ team members that workmeticulously with HTML5 Conversions, Game Art, Testing, Compliance, and Engine Development.
They have games such as Trip Trap Trolls, Diamond Fortunes, and RollemRollem, etc. under their name.
6. Mango Games – Hyderabad
The smartphone game building company – Mango Games deals in several platforms such as Android, iOS, Cloud Games and Windows.
They deal in all the gaming solutions in-house with many services including development, designing, promotion, testing and publishing.
In addition to this, they deal in a different type of games such as turn-by-turn multiplayer, single player and multi-player.
The headquarters of the company is in Hyderabad that hasa firmbelief in persuasive games that are enjoyed by global customers.
Their core services are Game Design Services, Android Game Development, Game Development, Game Testing Services, Unity 3D Game Development, 3D Modeling and animation. The games under their names are Teen Patti, Mumbai Mobsters, and Social Rummy, etc.
7. Synqua Games – Mumbai
Synqua Games falls in the category of the top-rated games in India. They deal in providing services for game development in many platforms for tablets and mobile such as BB10, Android, iOS and Window Phones.
Till today, they have over 60 games that are played by the customers. The download count of the games is approximately 30 million which is still in counting.They are still developing a number of games with are extremely loved by the clients. In addition to this, the gaming studio is redefining their strategies to achieve goals.
The headquarters are located in Mumbai that is working to complete their dream of achieving award-winning gaming applications.
They deal in the Game Design Services, Game Development, Unity 3D Game Development, Android Game Development, 3D Modeling and Animations and Game Testing Services. Their games are Rescue Monster, Snowball Baseball and Tap Baseball.
8. Zapak Digital LTD – Mumbai
They are the leading gaming website that deals in online games with a category that is widespread with multiple categories including the dress up games and action games.
They are dealing in the services including Android Game Development, Game Development, Unity 3D Game Development, 3D Modeling and Animation, and Game Testing Services.
The games that are famous under their names are Speedway Racing, Super Boxing, Stealth Sniper, etc.
9. T&A Solutions – Chandigarh
One of the big shots in game development and testing. They are a pioneer in rendering the Solutions in multiple domains including HR professionals.
The game testing is their forte in which they have managed to develop a name with the great efforts and amazing work.
They are in the business world for many years and have a strongholdin the gaming industry.
The headquarters of the company T & A Solution is in the Chandigarh with the aim to provide the best services to their valuable customers. They work for the quality and not quantity.
10. Indium Game Testing Company – Bengaluru
It is a leading software testing Services Company that is focusing on multiple domains. They are not only making a name in the national market but in the international market as well.
automation testing
The company aim for the perfection and quality of the games in multiple domains. Their business is widely spread in many locations including Bengaluru and Chennai in India market and in USA, Georgia, California, etc.
They provide a number of services that includes the software testing of Games, Technology, Banking, Retail, Education, Life Science, and Healthcare.
In the present time, they are aggressively working in the field of cloud agenda, mobile and social platform with many emerging paradigms.

Why is TestNG Awesome? Advantages of Integrating it with Selenium

Basically, TestNG is a user – friendly automation framework that overcomes the drawbacks and limitations of Java Unit, thus introducing the entire new set of features which makes it more powerful and useful.

This automated testing framework helps in elimination of numerous limitation of the older framework. It facilitates the developer the ability to write more flexible and powerful tests.
TestNG Framework

  • TestNG is a testing framework designed for unit testing. Today it is used for every kind of testing.
  • Initially, it is developed to simplify a broad range of testing, no matter from system testing or Unit testing.
  • It is an open source framework which is inspired from the Java platform (JUnit) and NET platform (NUnit).
  • It can be used for any testing, be it API testing or UI testing.
  • It is introduced as a brand new automated framework whose functionalities make it more powerful and easier to use.

Features of TestNG

  • Maintains flexible runtime configuration.
  • Guards easy going plug-in API.
  • Supports Multi threaded testing.
  • Upholds parallel testing, group testing, partial testing and load testing.
  • Supports annotations of JUnit and have some more annotations to make testing easier.
  • Separates compile-time test code from run-time configuration/data info.
  • Supports testing integrated classes.
  • TestNG supports the ‘dependence’ method which is not available in JUnit.

How to Download or Install TestNG for a project
Before performing this step by step process, do not forget to visit these prerequisites to install selenium IDE.
In order to download TestNG plug-in, all you need to have is a selenium IDE and Active internet connection. But, if selenium IDE is already installed in your system, then follow these simple steps:
Step 1: Download and install the Java Software Development Kit (JDK)
Step 2: Download “Eclipse IDE for Java Developers”. You choose 32 bit or 64 bit as per your requirement.
Step 3: You can download the Selenium Java Client Driver. There would be different languages, choose only the Java from the options.
Step 4: Configure Eclipse IDE with Web Driver.
TestNG Basic Annotations
Annotations are a new feature in Java provided by JDK 5.0 version. Annotations can be used to describe metadata in java programs. To describe any information about the coding part, annotations are used. Following is the list of annotations usually used in TestNG:

Sr. No. Annotation Description
1. @BeforeSuite This annotation will always be executed before all tests are run inside a TestNG.
2. @AfterSuite This annotation will always be executed after all tests are run inside a TestNG.
3. @BeforeClass This annotation will always be executed before the first test method in a class is called on.
4. @AfterClass This annotation will always be executed after the first test method in a class is called on.
5. @BeforeTest Executed before any test method associated with the class inside <test> tag is run.
6. @AfterTest This annotation will always be executed before any test method associated with the class inside <test> tag is run.
7. @BeforeGroups This annotation will always be executed before the first test method associated with these groups is called on.
8. @Aftergroups This annotation will always be executed shortly after the first test method associated with these groups is called on.
9. @BeforeMethod This annotation will always be executed before each test method.
10. @AfterMethod This annotation will always be executed after each test method.
11. @DataProvider This annotation must return object [ ], it marks a method as supplying data for a test method.
12. @Factory This annotation will return the object and marks a method as a factory that will be used by TestNG as test classes.
13. @Listeners This annotation defines the listeners on a test class.
14. @parameters This annotation describes how parameters can be passed to a test method.
15. @Test This annotation marks a class as a part of the test.

Execution Procedure of Methods in TestNG with Annotations

import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.AfterSuite;
 
public class TestngAnnotation {
// Case 1
@Test
public void testCase1() {
System.out.println(“Case I”);
}
// Case 2
@Test
public void testCase1() {
System.out.println(“Case II”);
}
@BeforeMethod
public void beforeMethod() {
System.out.println(“Before Method Annotation”);
}
@AfterMethod
public void afterMethod() {
System.out.println(“After Method Annotation”);
}
@BeforeClass
public void beforeClass() {
System.out.println(“Before Class Annotation”);
}
@AfterClass
public void afterClass() {
System.out.println(“After Class Annotation”);
}
@BeforeTest
public void beforeTest() {
System.out.println(“Before Test Annotation”);
}
@AfterTest
public void afterTest() {
System.out.println(“After Test Annotation”);
}
@BeforeSuite
public void beforeSuite() {
System.out.println(“Before Suite Annotation”);
}
@AfterSuite
public void afterSuite() {
System.out.println(“After Suite Annotation”);
}
}
Creating XML file in C:\>TestNG for executing annotations
<?xml version = “1.0” encoding = “UTF-8”?>
<!DOCTYPE suite SYSTEM “http://demo” >
<suite name = “Suite1”>
<test name = “test1”>
<classes>
<class name = “Annotation”/>
</classes>
</test>
</suite>
Test case compilation using javac
C:\TestNG>javac Annotation.java
Output:
Before Suite Annotation
Before Test Annotation
Before Class Annotation
Before Method Annotation
Case I
After Method Annotation
Before Method Annotation
Case II
After Method Annotation
After Class Annotation
After Test Annotation
After Suite Annotation
===============================================
Suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

Why use TestNG with Selenium?
Selenium tests alone cannot generate a proper format for the test results. However, with the help of TestNG, you can generate the proper format for the test results.

Read also :  10 Best Automation Testing Tools of 2018

TestNG is widely used by other selenium users because of its features and feasibility. Moreover, it is associated with several advantages through which a user can be very comfortable to leverage TestNG.
Following are the points why you need to use TestNG with selenium:

  • You don’t have to write a single line of code to generate a proper format for the test results as they are generated by default. The report usually includes a number of test cases runs or a number of test cases that failed or passed.
  • If you want to control the test executions, then you have access to multiple annotations which can control how the test can be run.
  • You can run your tests in arbitrarily big threads pools. You can simply group multiple test cases and convert them into an XML file and then set the priority of test case in a specific order.
  • It provides easy and flexible test configuration in which you don’t have to write a code to modify any test methods.
  • Using it you can create data-driven frameworks. You can use the @DataProvider annotation to support data-driven testing.
  • If you want to run your tests based on the parameters, TestNG supports parameter feature which will make your test cases or test suite very flexible. You can easily pass the parameter at runtime so that based on the requirement you can pass the parameter and you don’t have to modify your existing test.
  • If you have multiple classes to execute in the test suite, you can directly right click and run the complete test suite.
  • It is supported by a variety of tools and plugins. Also, it supports multiple IDE such as Webstorm, IntelliJ or NetBeans.
  • You can simply group the test cases with the use of TestNG. Suppose you have four categories of smoke, recreation, functional and non-functional. You can group all of these test cases and can run them individually.

Advantages of TestNG over JUnit                     
app testing

  • It gives an option to run out same test case with multiple sets of test data.
  • It provides default reports which are not provided if you are using JUnit.
  • It has a higher level of customization which enables the user to customize test case execution so that the user can run his script when something happens.
  • Test cases can also be grouped easily as compared to JUnit.
  • The annotations used in TestNG are very simple and easy to understand.

 

All You Need To Know About Apache Maven

When you start running an application you need somebody to instruct. Most of the people start running their programs without much thought that what is happening behind the scenes.

They might store all the Java libraries in a folder on their hard drive. The problem arises when you try to move the program from one computer to another, the directories that you have created might not match the directories on your new computer.
The problem gets much worse when you try to make sure that everyone using this program is using the same versions of libraries to compile but you don’t need to worry as there is a much better solution i.e. Apache Maven.
It is a tool that helps you to structure your project. If you want to learn more about maven keep reading…
About Apache Maven
Apache Maven is a build automation tool or a project management tool that provides the developer with complete build lifecycle framework.
It is used for building and managing any Java-based project and it is built under the license of Apache 2.0. There are lots of libraries available on the Maven repository.
Most of the times when you work on a project you require 3rd party libraries like MySQL connector, spring, spring mvc, hibernate etc.
You can do it in two ways i.e. you can download the dependencies and place the jar files in lib folder or you can use Maven Repository. Well, the second one is the best option.
Maven is a Yiddish word that means “accumulator of knowledge”. The main motive behind developing the Maven is to get a standard way to build the projects, to get a clear picture of what is a project consists of and to get an easy way to publish the project information.
The day to day work of Java developers could be easier with the use of Maven and it also helps in the comprehension of any Java-based project. Maven is developed by the Apache Software foundation initially on 13 July 2014.
Objectives of Apache Maven

  • The main objective of Apache Maven is to enable the developer to understand the complete state of development effort in shortest time span and to give a comprehension project model that is easy to understand, reusable and maintainable.
  • Making build process easy by providing shielding from the details.
  • Maven provides a uniform build system by using project object models and a set of plugins that are shared by all projects
  • Maven provides the developers with quality project information such as dependency list, mailing list, unit tests, cross-referenced sources, etc.
  • It makes easy to guide a project in one direction and provide best practices guidelines
  • Maven provides its clients with an easy way to update the installations so that they won’t miss taking advantages of changes done in Maven software.

Features of Apache Maven

  • Apache Maven offers a simple project setup following the best practices. Developers can easily get a new project and start it in seconds
  • There is no ramp-up time for new developers coming with a project
  • Maven can easily work with multiple projects at the same time
  • There is no need for extra configuration and provide instant access to new features
  • It is extensible, with the ability to easily write plugins in Java or scripting languages
  • Maven has the capacity to build a number of projects into predefined outputs like metadata, jar, war etc.
  • Maven has better and improved error reporting. It provides the developers with a link to the Maven wiki page where a developer can get the whole description of errors.
  • There is no need to specify parent in the sub-model for the purpose of maintenance
  • Apache Maven is extensible via plugins that keep the Maven core small. For example, if you don’t know how to compile Java source code, the Maven compiler plugin will handle all this
  • Maven has a large repository of libraries. You can load project dependencies from the local file system or from the internet
  • Apache Maven comes with a feature of dependency management. The build system of maven resolve the dependencies and build the dependent projects if required
  • It has another distinguish feature of convention over configuration.
  • They don’t have to mention configuration details

How to Use Apache Maven
Maven is a Java tool, so, if you want to use Maven for your projects you must have installed Java. First of all, you need to download the Maven and follow the installation instructions to install Maven on your system.
Once you have downloaded and installed Maven on your computer you need to type a command prompt i.e. “mvn –version”, then it will print out the installed version of Maven.
Sometimes you may require extra configuration depending upon the network setup. Make sure that you are prepared to use Maven on windows.
Create a Project

  • You need to create a directory and need to start a shell in that directory. Execute the Maven goal on your command line i.e. “mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false”
  • Sometimes you may need to execute the command twice before it succeeds. You will notice a standard project structure under the directory such as:
my-app
|– pom.xml
`– src
|– main
|   `– java
|       `– com
|           `– mycompany
|               `– app
|                   `– App.java
`– test
`– java
`– com
`– mycompany
`– app
`– AppTest.java

The directory contains project source code, test source, and POM.xml files.

  • To create and build a project in Maven you need to start eclipse and create a Maven project. You need to add necessary dependencies and build the project.
  • Then you need to add the dependency to the POM.xml file.
  • After that, you need to add Java class to the project
  • After adding Java class build a project then add Maven plugin and rebuild

What is Maven POM?
POM or Project Object Model is a fundamental unit of work in Maven. It contains all the project information and configuration details that Maven uses to build the project.
Maven checks the POM in the current directory while executing a task. POM was initially named as project.xml in Maven 1then it was renamed in to pom.xml in Maven 2. A POM contains the default values for most projects.

Also Read : 10 Key Factors for Successful Test Automation

It also reads and gets the needed information related to configuration and then executes the goal. Following are some of the configurations that are specified in the POM:

  • Project dependencies
  • Plugins
  • Goals
  • Build profiles
  • Project version
  • Developers
  • Mailing list etc.

Example of POM

<project xmlns = “http://maven.apache.org/POM/4.0.0”
xmlns:xsi = “http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation = “http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd”>
<modelVersion>4.0.0</modelVersion>
<groupId>com.companyname.project-group</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
</project>

Super POM
The super POM is the default POM of Apache Maven. The POMs that you create for your projects are extended in configuration specified in the super POM.
Maven uses the POM configuration from super POM and project configuration in order to execute the relevant goal.
A super POM helps the developers to specify minimum configuration details in pom.xml file. You can run the command mvn help:effective-pom to look the default configurations of super POM.
Minimal POM
The minimal POM requires the following things:

  • Project root
  • Model version set to 4.0.0
  • GroupId
  • ArtifactId
  • And the version of the artifact under the specified group

Example of minimal POM

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>

Maven Repository
The Maven repository is a directory to store project jars, library jars, plugins and other project specific artifacts that are later used by Maven. It is categorized into three different groups
app testing
Local Repository: the local Maven repository is created when you run any of the Maven command for the first time. It keeps all your project’s dependencies into a folder.
It automatically downloads the dependency into local repository when you run a Mavel build
Example of Local Repository

<settings xmlns = “http://maven.apache.org/SETTINGS/1.0.0”
xmlns:xsi = “http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation = “http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd”>
<localRepository>C:/MyLocalRepository</localRepository>
</settings>

Central Repository: It is a Maven repository containing a large number of commonly used libraries. Central repository is used when Maven could not find the dependency in the local repository.
It is managed by Maven community and is not required to be configured; it only requires an internet access to be searched.
Remote Repository: When Maven fails to search the dependency on both local and central repository then it stops the build process and output an error message to console.
Maven provides the concept of remote repository to prevent such situation. Maven can download dependency from remote repository in the pom.xml file.
Example of Remote Repository

<project xmlns = “http://maven.apache.org/POM/4.0.0”
xmlns:xsi = “http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation = “http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd”>
<modelVersion>4.0.0</modelVersion>
<groupId>com.companyname.projectgroup</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.companyname.common-lib</groupId>
<artifactId>common-lib</artifactId>
<version>1.0.0</version>
</dependency>
<dependencies>
<repositories>
<repository>
<id>companyname.lib1</id>
<url>http://download.companyname.org/maven2/lib1</url>
</repository>
<repository>
<id>companyname.lib2</id>
<url>http://download.companyname.org/maven2/lib2</url>
</repository>
</repositories>
</project>