In this tutorial, I will explain to pass a JSON or XML file as a payload to the request. This is needed when the payload is static or there is minimal change in the request payload. This can be done by using the body() method, which accepts “File” as an argument. This is elaborated in Javadoc.
RequestSpecification body(File body)
This specifies file content that’ll be sent with the request. This only works for the POST, PATCH and PUT HTTP methods. Trying to do this for the other HTTP methods will cause an exception to be thrown.
Add Rest Assured dependency to the project. Use the latest version from here.
GitHub Actions are automated tasks, or workflows, that you can set up in your repository to build, test, package, release, and deploy any project on GitHub. With GitHub Actions, you can orchestrate any workflow, based on nearly any event, while GitHub manages the execution, provides rich feedback, and secures every step along the way.
Why should you care? Well, imagine merging your code into the main branch, only to realize later that it broke your build. With GitHub Actions, you can automate your unit tests to run on every push or pull request, thereby catching bugs before they creep into your production code. This means less time debugging and more time developing!
Implementation Steps
Step 1 – Create GitHub Actions and Workflows
I have a repository available in GitHub – RestAPITesting_Python as shown in the below image. Go to the “Actions” tab. Click on the “Actions” tab.
Step 2 – Select the type of Actions
You will see that GitHub recommends Actions depending on the project. In our case, it is recommending actions suitable for a Python project. I have selected the “Python application” option.
Step 3 – Generation of Sample pipeline
If you choose an existing option, it will automatically generate a .yaml for the project as shown below.
We will replace the current workflow with the following yml file as shown below:
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python application
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.12.1
uses: actions/setup-python@v3
with:
python-version: "3.12.1"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install requests
- name: Test with pytest
run: |
cd TestCases
pytest --verbose --capture=no
Step 4 – Commit the changes
After the changes, hit the “Start Commit” button.
This will give the option to add a description for the commit. It will also enable the user to commit either to the main branch or commit to any other branch that exists in the project. Click on the “Commit new file” button to set up the workflow file.
It will create a python-app.yml file as shown below in the project.
Step 5 – Verify that the workflow is running
Next, head over to the “Actions” tab, and you will see your YAML workflow file present under the tab. The yellow sign represents that the job is in the queue.
In Progress – When the job starts building and running, you will see the status change from “Queued” to “in progress”.
Passed – If the build is successful, you will see a green tick mark.
Step 6 – Verify the execution status
Below is the execution log.
Click on the workflow and the below screen is displayed. It shows the status of the run of the workflow, the total time taken to run the workflow, and the name of the .yml file.
Gradle is an open-source build automation tool that is designed to be flexible enough to build almost any type of software. Gradle runs on the JVM and you must have a Java Development Kit (JDK) installed to use it. Several major IDEs allow you to import Gradle builds and interact with them: Android Studio, IntelliJ IDEA, Eclipse, and NetBeans.
An authentication token is a piece of data, often a string, that is used to represent the authenticated user. Instead of sending the username and password with each request, a token is sent, usually in the request headers.
Prerequisite:
Python is installed on the machine
PIP is installed on the machine
PyCharm or other Python Editor is installed on the machine
The syntax for basic authentication in Python Request is
headers = {'Authorization': 'Basic dXNlcjpwYXNz'}
In this scenario, all you need to do is to embed the basic auth token as Authorization header while making the API call. A sample basic auth token would look like this auth param and the get() method in requests will take care of the basic authorization for us.
Below is the example of basic authentication token.
Step 4 – Create a Test Code for the testing of REST API under src/test/java
Rest Assured and Allure Report are two popular tools for testing. Rest Assured is used for API testing and Allure Report is used for creating detailed reports about tests. To see our request and response in more detail using these tools, we need to add a line to our Rest Assured tests. This will provide the request and response details in the report.
For testing purpose, first test – Get Request one fails.
.filter(new AllureRestAssured())
Below is an example of the tests.
package org.example;
import io.qameta.allure.*;
import io.qameta.allure.restassured.AllureRestAssured;
import io.restassured.http.ContentType;
import org.json.JSONObject;
import org.junit.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.core.IsEqual.equalTo;
@Epic("REST API Regression Testing using JUnit4")
@Feature("Verify CRUID Operations on Employee module")
public class APITests {
String BaseURL = "https://dummy.restapiexample.com/api";
@Test
@Story("GET Request")
@Severity(SeverityLevel.NORMAL)
@Description("Test Description : Verify the details of employee of id-2")
public void getUser() {
// GIVEN
given()
.filter(new AllureRestAssured())
// WHEN
.when()
.get(BaseURL + "/v1/employee/2")
// THEN
.then()
.statusCode(200)
.statusLine("HTTP/1.1 200 OK")
// To verify booking id at index 2
.body("data.employee_name", equalTo("Garrett Winters!"))
.body("message", equalTo("Successfully! Record has been fetched."));
}
@Test
@Story("POST Request")
@Severity(SeverityLevel.NORMAL)
@Description("Test Description : Verify the creation of a new employee")
public void createUser() {
JSONObject data = new JSONObject();
data.put("employee_name", "APITest");
data.put("employee_salary", "99999");
data.put("employee_age", "30");
// GIVEN
given()
.filter(new AllureRestAssured())
.contentType(ContentType.JSON)
.body(data.toString())
// WHEN
.when()
.post(BaseURL + "/v1/create")
// THEN
.then()
.statusCode(200)
.body("data.employee_name", equalTo("APITest"))
.body("message", equalTo("Successfully! Record has been added."));
}
}
Step 5 – Run the Test and Generate Allure Report
To run the tests, use the below command
mvn clean test
The output of the above program is
This will create allure-results folder with all the test reports. These files will be used to generate Allure Report.
To create Allure Report, use the below command
allure serve
This will generate the beautiful Allure Test Report as shown below.
Allure Report Dashboard
Categories in Allure Report
The categories tab gives you a way to create custom defects classifications to apply for test results. There are two categories of defects – Product Defects (failed tests) and Test Defects (broken tests).
Suites in Allure Report
On the Suites tab a standard structural representation of executed tests, grouped by suites and classes can be found.
View test history
Each time you run the report from the command line with the mvn clean test command, a new result JSON file will get added to the allure-results folder. Allure can use those files to include a historical view of your tests. Let’s give that a try.
To get started, run mvn clean test a few times and watch how the number of files in the allure-reports folder grows.
Now go back to view your report. Select Suites from the left nav, select one of your tests and click Retries in the right pane. You should see the history of test runs for that test:
Graphs in Allure Report
Graphs allow you to see different statistics collected from the test data: status breakdown or severity and duration diagrams.
Timeline in Allure Report
Timeline tab visualizes retrospective of tests execution, allure adaptors collect precise timings of tests, and here on this tab, they are arranged accordingly to their sequential or parallel timing structure.
Behaviors of Allure Report
This tab groups test results according to Epic, Feature, and Story tags.
The below image shows the request body sent and the status code of the response, its body, and header provided by API.
Packages in Allure Report
The packages tab represents a tree-like layout of test results, grouped by different packages.
We are done! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!
Basic Authentication is a simple authentication scheme that is often used in HTTP (Hypertext Transfer Protocol) to provide a way for a client to send a username and password to a server for verification. It is a part of the HTTP protocol and involves sending the credentials (username and password) in the request headers.
Prerequisite:
Python is installed on the machine
PIP is installed on the machine
PyCharm or another Python Editor is installed on the machine
We can directly embed a basic auth username and password in the request by passing the username and password as a tuple to the auth param and the get() method in requests will take care of the basic authorization for us.
Below is an example of basic authentication in Postman.
Rest Assured enables you to test REST APIs using java libraries and integrates well with Maven/Gradle. REST Assured is a Java library that provides a domain-specific language (DSL) for writing powerful, maintainable tests for RESTful APIs.
What is JUnit?
JUnit is a simple framework to write repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks. JUnit 4 is one of the most popular unit testing frameworks which has a significant role in the test-driven development process.
Dependency List:-
REST Assured – 5.4.0
Java 17
JUnit – 4.13.2
Maven – 3.9.6
Detailed Step Description
Step 1- Download and Install Java
Java needs to be present on the system to run the tests. Click here to know How to install Java. To know if Java is installed or not on your machine, type this command in the command line. This command will show the version of Java installed on your machine.
java -version
Step 2 – Download and setup Eclipse IDE on the system
The Eclipse IDE (integrated development environment) provides strong support for Java developers, which is needed to write Java code. Click here to know How to install Eclipse.
Step 3 – Setup Maven
To build a test framework, we need to add a number of dependencies to the project. It is a very tedious and cumbersome process to add each dependency manually. So, to overcome this problem, we use a build management tool. Maven is a build management tool that is used to define project structure, dependencies, build, and test management. Click here to know How to install Maven.
To know if Maven is already installed or not on your machine, type this command in the command line. This command will show the version of Maven installed on your machine.
The tests should be written in src/test/java directory. To know how to create a JSON Request body using JSONObject, please refer to this tutorial.
import io.restassured.http.ContentType;
import org.json.JSONObject;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static io.restassured.RestAssured.given;
public class APITests {
String BaseURL = "https://dummy.restapiexample.com/api";
@Test
public void createUser() {
JSONObject data = new JSONObject();
data.put("employee_name", "NewUser1");
data.put("employee_salary", "1000");
data.put("employee_age", "35");
// GIVEN
given()
.contentType(ContentType.JSON)
.body(data.toString())
// WHEN
.when()
.post(BaseURL + "/v1/create")
// THEN
.then()
.statusCode(200)
.body("data.employee_name", equalTo("NewUser1"))
.body("message", equalTo("Successfully! Record has been added."));
}
}
Step 7 – Test Execution through JUnit Test
Go to the Runner class and right-click Run As JUnit Test. The tests will run as JUnit tests. (Eclipse)
Below is the image to run the tests in IntelliJ.
This is how the execution console will look like.
Step 8 – Run the tests from the command line
Maven Site Plugin creates a folder – site under the target directory, and the Maven Surefire Report plugin generates the JUnit Reports in the site folder. We need to run the tests through the command line to generate the JUnit Report.
mvn clean test site
The output of the above program is
Step 9 – Report Generation
After the test execution, refresh the project, and a new folder with the name site in the target folder will be generated. This folder contains the reports generated by JUnit. The structure of the folder site looks as shown below.
Step 10 – View the Report
Right-click on the summary.html report and select Open In -> Browser ->Chrome.
Summary Report
Below is the summary Report.
Surefire Report
Below is an example of a Surefire Report. This report contains a summary of the test execution.
We are done! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!
In Python, the requests library is commonly employed for retrieving content from a specific resource URI. When a request is made to a designated URI using Python, it yields a response object. This response object is then utilized to access various attributes, including content and headers. This article focuses on demonstrating how to examine the response.elapsed attribute within a response object.
Prerequisite:
Python is installed on the machine
PIP is installed on the machine
PyCharm or other Python Editor is installed on the machine
In Python, response.elapsed is an attribute of the Response object from the requests library, which is commonly used for making HTTP requests. The elapsed attribute represents the time elapsed between sending the request and receiving the response.
One of the major testing workflows involves switching between multiple windows. Selenium WebDriver has specific switch commands to serve this purpose. Selenium WebDriver assigns an alphanumeric id to each window as soon as the WebDriver object is instantiated. This unique alphanumeric id is called a window handle. Selenium uses this unique id to switch control among several windows. In simple terms, each unique window has a unique ID, so that Selenium can differentiate when it is switching controls from one window to the other.
1) GetWindowHandle
To get the window handle of the current window. It returns a string of alphanumeric window handles.
String parentHandle= driver.getWindowHandle();
2) GetWindowHandles
To get the window handle of all the windows. It returns a set of window handle.
Set handle= driver.getWindowHandles();
3) SwitchTo Window
WebDriver supports moving between named windows using the “switchTo” method.
driver.switchTo().window("windowName");
Let us explain window switch with an example:-
1) Launch new Browser and open https://demoqa.com/browser-windows 2) Check the count of windows which is 1 3) Locate “New Window” button using Id – “windowButton” and click to open a new window 4) Get the count of both windows which is now 2. 5) Get the parent window handle and print it to console 6) Get the window handles of both the open windows and print them 7) Switch to the new window (child window) 8) Get the text of Child Window and print it 9) Close the new window (child window)
The program for the above scenario is shown below:
package com.example.definitions;
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.chrome.ChromeOptions;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;
public class WindowSwitchDemo {
public static void main(String[] args) {
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Pass application url
driver.get("https://demoqa.com/browser-windows");
//Count of window - 1
Set<String> allWindowHandles = driver.getWindowHandles();
System.out.println("Count of Window :" + allWindowHandles.size());
//Open a child window
driver.findElement(By.id("windowButton")).click();
//Count of windows , changed from 1 to 2
Set<String> newAllWindowHandles = driver.getWindowHandles();
System.out.println("New Count of Window :" + newAllWindowHandles.size());
// Get the detail of the parent window
String ParentHandle = driver.getWindowHandle();
System.out.println("Parent Window :" + ParentHandle);
//Get details of parent and child windows
Iterator<String> iterator = newAllWindowHandles.iterator();
String mainWindow = iterator.next();
String childWindow = iterator.next();
System.out.println("Parent Window :" + mainWindow);
System.out.println("Child Window :" + childWindow);
//Switch control to child window
driver.switchTo().window(childWindow);
//Verify the text present on child window
WebElement text = driver.findElement(By.id("sampleHeading"));
System.out.println("Child_Title :" + text.getText());
// Close Child window
driver.close();
// Switch back to parent window
driver.switchTo().window(ParentHandle);
System.out.println("Parent Title :" + driver.getTitle());
// Close Parent window
driver.quit();
}
}
The output of the above program is
What is the difference between driver.close() and driver.quit()?
When we are working on multiple windows and a selective window needs to be closed, then transfer the control to that window and use driver.close() to close the selective window. This will not stop the execution of the rest of the program. But, in case it is needed to close all the open windows, then use driver.quit() which will close all the windows opened in a particular session. It basically stops the driver instance, and any further actions to WebDriver may result in an exception. It is generally the last statement of any code.
Congratulations. We have learnt about window switching in Selenium. I hope you find this tutorial helpful. Happy Learning!!
Cucumber Data Tables can be used to add multiple parameters in Step Definition in a tabular form rather than putting all the parameters in the Gherkin statement. This is much easier to read and multiple rows of data can be passed in the same step. Data tables from Gherkin can be accessed by using the DataTable object as the last parameter in a Step Definition. This conversion can be done either by Cucumber or manually.
Let’s write a simple data table and see how we use it.
1. Table into List of a List of Strings
| firstName | lastName | age |
| Thomas | Brown | 30 |
| Perry | Wilson | 26 |
| Ashley | William | 27 |
java type: List<List<String>>
The natural representation of list of a list of strings is shown below.
[
[ "firstName", "lastName", "age" ],
[ "Thomas", "Brown", "30" ],
[ "Perry", "Wilson", "26" ],
[ "Ashley", "William", "27" ]
]
2. Table into List of Maps
java type: List<Map<String, String>>
The natural representation of list of maps is shown below.
[
{ "firstName": "Thomas", "lastName": "Brown", "age": "30" },
{ "firstName": "Perry", "lastName": "Wilson", "age": "26" },
{ "firstName": "Ashley", "lastName": "William", "age": "27" }
]
3. Table into Single Map
Table where first colum is key as shown below
| IN | India |
| IRE | Ireland |
java type: Map<String, String>
TO convert the table into a single map
{
"IN": "India",
"IRE": "Ireland"
}
4. Table into map that uses a list as its value
A table with multiple column values per key.
| IN | India | 29 |
| IRE | Ireland | 8 |
java type: Map<String, List<String>>
{
"IN": ["India","29"],
"IRE": ["Ireland","8"]
}
Now, let us see how we can use DataTable in Cucumber
Cucumber Data Tables Example in Java
Data Table without Header Example
Below is an example of how to implement Data Tables without a Header. For example, we want to test the Login Page of an application. We can either mention all the arguments inside the Gherkin statement or use a table to list all the arguments, as we used below:
Feature: Login to HRM Application
@ValidCredentials
Scenario: Login with valid credentials - Data Table without Header
Given User is on HRMLogin page
When User enters valid credentials
| Admin | admin123 |
Then User should be able to login successfully and new page open
Below is the Step Definition of the above scenario.
import io.cucumber.datatable.DataTable;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
public class DataTableDefinitions {
WebDriver driver;
@Before
public void setup() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
}
@Given("User is on HRMLogin page")
public void userOnHomePage() {
driver.get("https://opensource-demo.orangehrmlive.com/");
}
@When("User enters valid credentials")
public void entersValidCredential(DataTable dataTable) throws InterruptedException{
System.out.println("Credentials Entered");
List<List<String>> signUpForm = dataTable.asLists(String.class);
String userName = signUpForm.get(0).get(0);
String passWord = signUpForm.get(0).get(1);
driver.findElement(By.name("username")).sendKeys(userName);
driver.findElement(By.name("password")).sendKeys(passWord);
driver.findElement(By.xpath("//*[@class='oxd-form']/div[3]/button")).submit();
}
@Then("User should be able to login successfully and new page open")
public void successfulLogin() throws InterruptedException {
String newPageText = driver.findElement(By.xpath("//*[@class='oxd-topbar-header-breadcrumb']/h6")).getText();
System.out.println("newPageText :" + newPageText);
assertThat(newPageText, containsString("Dashboard"));
}
@After
public void teardown(){
driver.quit();
}
}
To run the Feature file, we need a Cucumber TestRunner.
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(monochrome = true, plugin = "pretty", features = "src/test/resources/Features/DataTable.feature",
glue = "definitions", tags="@ValidCredentials")
public class CucumberRunnerTest {
}
The output of the above program is
In the above example, we don’t have a header. We have just got the List object. We get the values of DataTable starting from 0 index.
Cucumber converts the above table into a list of lists. It treats each row as a list of the column values. We use the asLists method — supplying a String.class argument — to convert the DataTable argument to a List<List<String>>. This Class argument informs the asLists method of what data type we expect each element to be.
Data Table with Header and Single Row Example
Below is a cucumber data tables example with the header.
Adding a header to your table makes it easier to read and maintain.
@InValidCredential
Scenario: Login with invalid credential - Header with Single Row
Given User is on HRMLogin page
Then User enters invalid credentials and Login will be unsuccessful with error message
| Username | Password | ErrorMessage |
| Admin1 | admin123!$ | Invalid credentials |
Below is the Step Definition of the above scenario.
package org.example.definitions;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.time.Duration;
import java.util.List;
import java.util.Map;
public class DataTableDefinitions {
WebDriver driver;
@Before
public void setup() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
}
@Given("User is on HRMLogin page")
public void userOnHomePage() {
driver.get("https://opensource-demo.orangehrmlive.com/");
}
@Then("User enters invalid credentials and Login will be unsuccessful with error message")
public void entersInvalidCredential(DataTable userTable) throws InterruptedException {
System.out.println("Enter Credentials");
List<Map<String, String>> user = userTable.asMaps(String.class, String.class);
String userName = user.get(0).get("Username");
System.out.println("Username :" + userName);
driver.findElement(By.name("username")).sendKeys(userName);
String passWord = user.get(0).get("Password");
System.out.println("Password :" + passWord);
driver.findElement(By.name("password")).sendKeys(passWord);
driver.findElement(By.xpath("//*[@class='oxd-form']/div[3]/button")).submit();
String errorMessage = user.get(0).get("ErrorMessage");
String actualErrorMessage = driver.findElement(By.xpath("//*[@class='orangehrm-login-error']/div[1]/div[1]/p")).getText();
System.out.println("Actual Error Message :" + actualErrorMessage);
Assert.assertTrue(actualErrorMessage.equalsIgnoreCase(errorMessage));
}
@After
public void teardown(){
driver.quit();
}
}
The output of the above program is
In the above example, we have only 1 row with the header, so have used get(0) to retrieve the first row of DataTable. After that, I used get(“HeaderName”) to get the value of the row of DataTable.
Data Table with Header and Multiple Rows Example
Below is a cucumber data table example with multiple rows of data with the header. This is helpful when we want to test multiple combinations of data in a step.
@Multiple_InValidCredentials
Scenario: Login with invalid credentials - Data Table with Header and Multiple Rows
Given User is on HRMLogin page
Then User enters invalid credentials and Login will be unsuccessful with custom error messages
| Username | Password | ErrorMessage |
| Admin1 | admin123! | Invalid credentials |
| Admina | admin123a | Invalid credentials |
Below is the Step Definition of the above scenario
import io.cucumber.datatable.DataTable;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
public class DataTableDefinitions {
WebDriver driver;
@Before
public void setup() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
}
@Given("User is on HRMLogin page")
public void userOnHomePage() {
driver.get("https://opensource-demo.orangehrmlive.com/");
}
@Then("User enters invalid credentials and Login will be unsuccessful with custom error messages")
public void entersInvalidCredentials(DataTable userTable) throws InterruptedException {
System.out.println("Enter Credentials");
List<Map<String, String>> user = userTable.asMaps(String.class, String.class);
for (Map<String, String> form : user) {
String userName = form.get("Username");
System.out.println("Username :" + userName);
driver.findElement(By.name("username")).sendKeys(userName);
String passWord = form.get("Password");
System.out.println("Password :" + passWord);
driver.findElement(By.name("password")).sendKeys(passWord);
driver.findElement(By.xpath("//*[@class='oxd-form']/div[3]/button")).submit();
String errorMessage = form.get("ErrorMessage");
String actualErrorMessage = driver.findElement(By.xpath("//*[@class='orangehrm-login-error']/div[1]/div[1]/p")).getText();
System.out.println("Actual Error Message :" + actualErrorMessage);
Assert.assertTrue(actualErrorMessage.equalsIgnoreCase(errorMessage));
}
}
@After
public void teardown(){
driver.quit();
}
}
The output of the above program is
Cucumber creates a list containing each row, but instead maps the column heading to each column value. Cucumber repeats this process for each subsequent row. We use the asMaps method — supplying two String.class arguments — to convert the DataTable argument to a List<Map<String, String>>.
The first argument denotes the data type of the key (header). The second indicates the data type of each column value. Thus, we supply two String.class arguments because our headers (key) and title and author (values) are all Strings.
Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers!!