Posts

Passing Data From the TestNG.xml file to Tests

Image
  As we all know, that we might not always require to run the Test Automation Suite only on one specific instance, we can say it as QA Environment. As and when required we might need to put up execution on Dev Staging, UAT, or even PROD environment as well. But, here the problem arises as you might need to check in the new set of credentials for the other environment into the Credential file of your framework. This is one of the many use cases for the topic of the Blog, which is Passing Data From the TestNG.xml file to Tests . So here what we need to do. We can create multiple sets of XML files based on the credentials of the different environments and run the specified file as the request of execution easily.   Here is the code snippet of one such example depicting how to place and organize your code. 1. Creating the XML file with the required set-1 of credentials.                          Here, d...

Cypress: Storing Values Into A Variable Synchronously

Image
  Hello People, As I have moved towards a new venture in my career, with which I have got opportunity to work with a great and an amazing tool named Cypress.IO . With my previous experience all being into Selenium and JAVA, it was challenging to learn and quickly get into the shoe with Cypress. In my journey of leaning, I got many difficulties as a beginner in Cypress, which I would like to share with all of you. So that it is easier for the people to quickly look and learn from it. So as we all know JavaScript is asynchronous due to its single-threaded programming feature. Thus it becomes very cumbersome to store the variable value taken out from any calculation or on-screen UI element to be used further for any verification purpose. It would always give a undefined  value. Like in the below given example: Simply I visited a site and fetched an attribute using class, invoked its text and saved it into a variable named var1. Now as required, I printed the value of the variable...

Verify a Key exists in a Hashmap

Image
  In a very vast or old Automation suites project, where we have more than 10,000 lines of code and about 1000's test cases. For a new joiner into such projects, ould really find it difficult to understand the existing methods and whether to write new methods for new things or to accommodate into the existing ones only.  Thus, in such cumbersome situations where one feels that a functional method needs to be revamped by the addition of a parameter or a special conditional statement, but doing so may give a massive amount of errors in the entire suite. So instead of adding an additional parameter one way I thought of great help was the use of HashMaps. So let's first understand the concept and working of a HashMap in Java. What is HashMap? Hash table based implementation of the  Map  interface. This implementation provides all of the optional map operations and permits  null  values and the  null  key. (The  HashMap  class is roughly equi...

Automation Interview Questions - 1

Image
Hello Folks, Hope you all are doing good and safe under the current situation. Hereby I'm presenting a few of the most commonly asked questions for the  Software Test Automation Interview - Java. This is going to be a long thread and would surely put up many such topics related to Interviews for your convenience. So, without wasting a second let us jump to the very first and most asked Question:      •  Swapping 2 numbers without using third variable int x = 10; int y = 20; System.out.println("Before Swap : X is "+x +" and Y is "+ y); x = x + y; y = x - y; x = x - y; System.out.println("After Swap : X is "+x +" and Y is "+ y); Output: Before Swap : X is 10 and Y is 20 After Swap : X is 20 and Y is 10 The logic used for 2 numbers say, 10 & 20 is X = X + Y = 10 + 20  = 30 Y = X - Y = 30 - 20 = 10 X = X -Y = 30 - 10 = 20 • Swapping 2 numbers using a va...

Date & Time Handling In JAVA

Image
While automating any web application, there might arise a situation where you might need to play around with Date and Time objects and manipulate them as per your need. Also, you may land into a situation where you need to pick dates from the UI. There are ample situations where I have used Date in all different kinds of projects. So let us understand how to achieve this in Java. Java provides an inbuilt Date  class available under the java.util  package, this class holds the current date and time. Also, there are other classes using which we can simply use the date. First, let's see some methods to get the current date and time in Java. Following is a snippet showing three different ways to get Date/Time in Java, which can further be used to do some other action. Following is the output based on Line Number from the above code. As per the required pattern of date+time format, we can print the date into our console or save them in a variable. Line No. 23/24 shows the easiest ...

Parameterize job in Jenkins

Image
Hi All, In today's blog, we are going to see How to Parameterize our jobs in Jenkins for performing multiple kinds of actions from a single job. So simply starting with the need for this. There may arise a case where you are passing the Credentials and environment from outside the code by means of a CSV file saved in Amazon S3 or you have different TestNG configuration files with different data set and wish to choose one among those. In all these cases the Jenkins job needs to know and forward the same information to the executable. So this can be achieved by using the inbuilt feature of the Parameterization of Jenkins .  So let's start with this. For this, you first simply need to create a New Item from the Jenkins Dashboard, which is actually a new project for you. As soon as you name the Item and click on Save , you will land on the Configuration page of the new Item. Click on the This project is parameterized checkbox. You may now see a dropdown with different options to ...

Read Mails In Java

Image
  There may arise a case in Test Automation where you need to read an OTP from a Mail inbox or would like to access a URL link provided to you in your registered email account. One easy way to do so would be to directly login to the Mail Account on your Browser and perform Actions to read/write data from the webpage. This could sound easy at first but may get complicated when you tend to create locators to uniquely identify elements on these third-party applications which may even get change dynamically. But how about if you can directly get to access the Gmail account by using a simple Java library and writing a few lines of code to get through the content in your mailbox. Today we are going to discuss the same, in which we can easily read the Mail subject + body content without directly logging into the application but by doing so through the backend. Prerequisite Step : The account you are trying to log in must have the Setting  "Less secure app access" enabled, which allo...

Joins in SQL

Image
A JOIN clause in SQL is used to combine the records/rows from two or more tables, based on a common column that is present in the two tables. It creates a set that can be saved as a table or used as it is. They are predominantly used when a user is trying to extract data from tables that have one-to-many or many-to-many relationships between them. Following are the types of SQL Joins:   1.  Inner Join The Inner Join in SQL keyword selects all the common rows from each the tables which satisfies the given condition.                                                                2.  Left Join This Left Join returns all the rows from the left table (Table 1) and the matched records from the right table (Table 2). The result is NULL from the right side table if there is no match in Table 2....