Published December 31, 2018 by

How to encode the password for selenium using java


when you automate any application we do not want to share the password to outside the world. So, we will use Base64 class of the Java to encode and decode strings or passwords to use securely. In this article I will show you a practical selenium program to achieve the same thing how to encode the password and use the same to log into the application.


Read More
    email this
Published December 28, 2018 by

Headless Browser Testing in Selenium Web Driver



A headless browser is a browser simulation program that does not have a user interface (UI less).
Headless browser programs operate like any other browser, but do not display any UI. Selenium executes its' tests in the background.

There are several headless browsers available in the market, the following are the most popular ones:
  • Chrome
  • Firefox
  • HTMLUnit driver
  • PhantomJS
Read More
    email this
Published December 27, 2018 by

How to Check Drop down options are sorted or not in selenium with Java



In this post, I'm going to explain how to check Drop down options are sorted or not in selenium webdriver with java.
  • Open the browser and navigate to the webpage
  • Find the dropdown using the findElement method in selenium
  • Create a object to Select class and pass the dropdown element as the parameter to constructor
WebElement element = driver.findElement(By.xpath("//*[@id=\"animals\"]"));
Select se = new Select(element);
  • Using getOptions() method from Select class you can get all the options from the dropdown in the form of WebElement.
  • Using the loop we can retrive the values from the List of WebElement
  • Add all the values into a list called originalList that we have already created
ArrayList originalList = new ArrayList();

for (WebElement e : se.getOptions()) {
originalList.add(e.getText());
}
  • The values we retrieved could be sorted or not sorted values [ we are not sure, we have to verify this]
  • Now lets create a temporary list alled tempList and get the values from originalList
  • Now sort the Either tempList or originalList and compare them, We can sort the list using the Collections.sort(list) method
ArrayList tempList = originalList;
Collections.sort(tempList); 
  • We can compare the list using conditional statement
Complete program for not working sorting

import java.util.ArrayList;
import java.util.Collections;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class VerifyDropDownSortedOptions {

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver", "C://Drivers/chromedriver_win32/chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.get("https://testautomationpractice.blogspot.com/");

WebElement element = driver.findElement(By.xpath("//*[@id=\"animals\"]"));
Select se = new Select(element);

ArrayList originalList = new ArrayList();

for (WebElement e : se.getOptions()) {
originalList.add(e.getText());
}
System.out.println("originalList:" + originalList);

ArrayList tempList = originalList;
Collections.sort(tempList); // When you change one list, it changes the other list as well.

System.out.println("originalList:" + originalList);
System.out.println("tempList:" + tempList);

/*So the test gets pass all the time because the sequence in the originalList
and tempList is going to be same.
If you are following above process then your test never fails, because When
you change one list, it changes the other list as well.*/

if (originalList == tempList) {
System.out.println("Dropdown sorted");
} else {
System.out.println("Dropdown NOT sorted");
}
driver.close();
}
}

So the test gets pass all the time because the sequence in the originalList and tempList is going to be same.

If you are following above process then your test never fails, because When you change one list, it changes the other list as well.

How to check the options in drop down are sorted order or not

Step1: Create a List tempList variable
Step2: While iterating the option in the dropdown, add values to tempList (along with originalList)
Step3: Now sort the tempList, sorting of tempList will not affect the originalList because we have created two different objects
Step4: Compare the two Lists

import java.util.ArrayList;
import java.util.Collections;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class VerifyDropDownSortedOptions {

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver", "C://Drivers/chromedriver_win32/chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.get("https://testautomationpractice.blogspot.com/");

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

WebElement element = driver.findElement(By.id("animals"));

Select se = new Select(element);

ArrayList originalList = new ArrayList();
ArrayList tempList = new ArrayList();

for (WebElement e : se.getOptions()) {
originalList.add(e.getText());
tempList.add(e.getText());
}

System.out.println("this is originalList before Sorting" + originalList);
System.out.println("this is tempList before Sorting" + tempList);

Collections.sort(tempList);

System.out.println("this is originalList after Sorting" + originalList);
System.out.println("this is tempList after Sorting" + tempList);

if (originalList == tempList) {
System.out.println("Dropdown sorted");
} else {
System.out.println("Dropdown Not sorted");

}
driver.close();
}

}



Read More
    email this
Published December 22, 2018 by

Webservices API Testing





What is an API?

API is means Application Programming Interface.
It enables communication and data exchange between two separate software systems. 
A software system implementing an API contains functions/sub-routines which can be executed by another software system.

What is API testing?

API Testing is entirely different from GUI Testing and mainly concentrates on the business logic layer of the software architecture. This testing won't concentrate on the look and feel of an application.
Instead of using standard user inputs(keyboard) and outputs, in API Testing, you use software to send calls to the API, get output, and note down the system's response.
API Testing requires an application to interact with API. In order to test an API, you will need to 
Use Testing Tool to drive the API 
Write your own code to test the API






What is Web Service?

Web Service available over the web which Enables communication between applications over the web,
Provides a standard protocol/format for communication 

Why we use it?

Platform independent communication - using web services two different applications (implementation) can talk to each other and exchange data/information

Difference between API & Web service

Web Service is an API wrapped in HTTP.
All Web Services are API but APIs are not Web Services.
Web Service might not perform all the operations that an API would perform.
A Web Service needs a network while an API doesn't need a network for its operation.

What is WSDL?

WSDL stands for Web Services Description Language, an XML-based language that describes Web services and how to access and locate them.

What is UDDI?

UDDI stands for Universal Description, Discovery and Integration. It is an open, Internet-based specification that offers directory service for storing information about web services.

Types of Web Services

There are mainly two types of web services.

  • SOAP web services. (Simple Object Access Protocol) 
  • RESTful web services. (Representational State Transfer)


SOAP (Simple Object Access Protocol) – SOAP is a protocol which was designed before REST and came into the picture. The main idea behind designing SOAP was to ensure that programs built on different platforms and programming languages could exchange data in an easy manner.

REST – This was designed specifically for working with components such as media components, files, or even objects on a particular hardware device. Any web service that is defined on the principles of REST can be called a RestFul web service. A Restful service would use the normal HTTP verbs of GET, POST, PUT and DELETE for working with the required components.

HTTP V/S HTTPS

What Is HTTP?
HTTP stands for Hypertext Transfer Protocol. At it’s most basic, it allows for the communication between different systems. It’s most commonly used to transfer data from a web server to a browser in order to allow users to view web pages. It’s the protocol that was used for basically all early websites.

What Is HTTPS?
HTTPS stands for Hypertext Transfer Protocol Secure. The problem with the regular HTTP protocol is that the information that flows from server to browser is not encrypted, which means it can be easily stolen. HTTPS protocols remedy this by using an SSL (secure sockets layer) certificate, which helps create a secure encrypted connection between the server and the browser, thereby protecting potentially sensitive information from being stolen as its transferred between the server and the browser.

















Read More
    email this