Posts

Showing posts with the label Selenium

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...

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 ...

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...

Change Default Download Path Of Chrome Browser Using Selenium

Image
Hello, Welcome to the first Blog by me on one of the very simple yet important aspects of creating a Test Automation Framework. Changing/Setting up the Default path to Download files while executing a script. Downloading files in the correct folder is one of the crucial steps when doing Test Automation of a Web Application. By default, files are downloaded in the Download folder under User Directory typically the path address is C:\Users\<User_Name>\Downloads . But if the user wants to reuse the downloaded file or verify the content of the file, then it may become hard to find the right file among all the other already downloaded files/folders. So we can always change the path of Download directory and save files at our desired location which is always the right choice to be done inside a framework. This path should remain inside our Project Directory Workspace folder so as it is easy to find when used by a new person. Doing it inside our project structure would guarantee a cons...