How to test HTML ordered list in Selenium

HOME

<ol>
<html>

<head>
    <title>Numbered List Example</title>
</head>

<body>
    <h2>Ordered List with Numbers</h2>
    <ol>
        <li>JavaScript</li>
        <li>Python</li>
        <li>Java</li>
        <li>C++</li>
        <li>C#</li>
    </ol>
</body>

</html>

package com.example;

import org.openqa.selenium.Alert;
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.time.Duration;
import java.util.List;

public class OrderedList {

    public static void main(String[] args) {

        // Setup the webdriver
        ChromeOptions options = new ChromeOptions();
        WebDriver driver = new ChromeDriver(options);

        // Put an Implicit wait and launch URL
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));

        //Start Browser
        String filePath = "file:///C:/Users/vibha/OneDrive/Desktop/OrderedList.html";
        driver.get(filePath);

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

        //Locate the ordered list using its tag name
        WebElement orderedList = driver.findElement(By.tagName(("ol")));

        //Fetch all the list items
        List<WebElement> listItems = orderedList.findElements(By.tagName("li"));

        //Iterate through the list and print the contents
        for (int i = 0; i < listItems.size(); i++) {
            System.out.println(listItems.get(i).getText());
        }

        //Close the main window
        driver.quit();
    }

}

// Setup the webdriver
ChromeOptions options = new ChromeOptions();
WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
String filePath = "file:///C:/Users/vibha/OneDrive/Desktop/OrderedList.html";
driver.get(filePath);
driver.manage().window().maximize();
 WebElement orderedList = driver.findElement(By.tagName(("ol")));
 List<WebElement> listItems = orderedList.findElements(By.tagName("li"));
for (int i = 0; i < listItems.size(); i++) {
            System.out.println(listItems.get(i).getText());
 }

driver.quit();

JMeter Multiple Choice Answers – MCQ1

HOME

JMeter Multiple Choice Questions – MCQ1

























JMeter Multiple Choice Questions – MCQ1

HOME

Answer


Answer


Answer



Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer





====================================================================

Verifying Status Code and Status Line in Robot Framework

HOME

In this article, we will discuss how to verify status code and status line in Robot Framework. 

HTTP/1.1 200 OK

RequestLibrary is a Robot Framework library aimed to provide HTTP API testing functionalities by wrapping the well-known Python Requests Library.

Prerequisite:

  1. Install Python
  2. Install PIP
  3. Install Robot Framework
  4. Install Robot framework RequestLibrary
  5. Install PyCharm IDE

Please refer to this tutorial to install Robot Framework – How to install and setup Robot Framework for Python.

Implementation Steps:

Create API tests to verify status code

*** Settings ***
Library           RequestsLibrary
Library           Collections
Library           BuiltIn

*** Variables ***
${BASE_URL}          https://reqres.in/api/users/2

*** Test Cases ***
Validate HTTP Response Details
    [Documentation]   This test case validates the HTTP response status code, line, body, headers, and content type

    # Create session
    Create Session    api    ${BASE_URL}

    # Create headers dictionary in the test case
    ${HEADERS}=       Create Dictionary      Content-Type=application/json

    # Send GET request
    ${response}=      GET On Session    api    url=${BASE_URL}    headers=${HEADERS}

    # Validate Status Code
    Should Be Equal As Numbers    ${response.status_code}    200
    Log To Console    Status Code: ${response.status_code}

   # Construct expected status line dynamically
    ${expected_status_line}=    Set Variable    HTTP/1.1 ${response.status_code} OK
    Log To Console    Expected Status Line: ${expected_status_line}

    # Validate Status Line
    ${actual_status_line}=   Evaluate    f"HTTP/1.1 ${response.status_code} OK"
    Should Be Equal    ${actual_status_line}    ${expected_status_line}
    Log To Console    Status Line: ${actual_status_line}

Create Session    api    ${BASE_URL} 
 ${HEADERS}=       Create Dictionary      Content-Type=application/json
  ${response}=      GET On Session    api    url=${BASE_URL}    headers=${HEADERS}

${response}= We are saving the response of the GET operation in the ${response} variable.

4. Asserts that the response status code is 200, indicating a successful request. We have logged the Status Code too

Should Be Equal As Numbers    ${response.status_code}    200
Log To Console    Status Code: ${response.status_code}

5. Set Variable to construct expected Status Line. It dynamically constructs the expected status line using ${response.status_code}.

${expected_status_line}=    Set Variable    HTTP/1.1 ${response.status_code} OK

${actual_status_line}=   Evaluate    f"HTTP/1.1 ${response.status_code} OK"

Execute the tests

We need the below command to run the Robot Framework script.

robot ValidateStatusCode.robot

The output of the above program is

View Report and Log

We have the test case passed. The Robot Framework generates log.html, output.xml, and report.html by default.

Let us now see the report and log details.

Report

Right-click on report.html. Select Open In->Browser->Chrome(any browser of your wish).

The Report generated by the framework is shown below:

Log

Robot Framework has multiple log levels that control what is shown in the automatically generated log file. The default Robot Framework log level is INFO.

Right-click on log.html. Select Open In->Browser->Chrome(any browser of your wish).

That’s it! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!

Additional Tutorials

How to Install Python on Windows 11
How to install and setup Robot Framework for Python
How to rerun failed tests in Robot Framework
Page Object Model in the Robot Framework
Parallel Testing in Robot Framework
How to load data from CSV files in the Robot Framework?

Jenkins Multiple Choice Answers – MCQ2

HOME

Jenkins Multiple Choice Questions – MCQ2

























Jenkins Multiple Choice Questions – MCQ2

HOME

Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer

====================================================================

How to pass authorization token in header in Robot Framework

HOME

In this article, we will discuss how to pass the Authentication Token in the header. We will focus on its implementation in Robot Framework. 

Prerequisite:

  1. Install Python
  2. Install PIP
  3. Install Robot Framework
  4. Install Robot framework Selenium Library
  5. Install PyCharm IDE

Please refer to this tutorial to install Robot Framework – How to install and setup Robot Framework for Python.

RequestLibrary is a Robot Framework library aimed to provide HTTP API testing functionalities by wrapping the well-known Python Requests Library.

Implementation Steps:

Step 1.1 – Open PyCharm and create a new project. Go to File and select New Project from the main menu.

Step 1.2 – Choose the project location. Click the “Browse” button next to the Location field and specify the directory for your project.

Deselect the Create a main.py welcome script checkbox because you will create a new Python file for this tutorial.

Click on the “Create” Button.

Step 1.3 – A new dialog appears asking to open the project using any one of the given options. I have selected New Window as I like to have separate windows for each project.

Below is the image of the new project created in PyCharms.

Step 2 – Install RequestLibrary

To install RequestLibrary, you need to use the below command:

pip install robotframework-requests

Step 3 – Add robotframework-requests package to the PyCharms

Go to File->Settings ->Project:API_RobotFramework ->Python Interpreter.

Click on the “+” sign and enter robotframework-requests in the search bar. It will show a list of packages. Select the “robotframework-requests” package and click on the “Install Package”.

Once the package is installed, we will see the message that the package is installed successfully.

Once the package is installed, it can be seen under the package list as shown below:

Step 4 – Create a new directory in the new project

Right-Click on the project, select New->Directory, and provide the name as Tests

Below is the image of the new directory.

Right-click on the new directory and select New File and provide the name as AuthTokenDemo.robot as shown below:

Step 5 – Create API tests in Robot Framework

*** Settings ***
Library           RequestsLibrary
Library           Collections
Library           BuiltIn


*** Variables ***
${BASE_URL}       https://httpbin.org/basic-auth/user/pass
${AUTH_TOKEN}     Basic dXNlcjpwYXNz


*** Test Cases ***
Example API Request with Authorization Header
    [Documentation]   Example of sending a GET request with an Authorization token in the header

    Create Session    api    ${BASE_URL}

     # Create headers dictionary in the test case
    ${headers}=       Create Dictionary    Authorization=${AUTH_TOKEN}    Content-Type=application/json

   ${response}=      GET On Session    api    url=${BASE_URL}     headers=${headers}
    Log To Console    Status Code: ${response.status_code}
    Log To Console    Response Body: ${response.text}
    Should Be Equal As Numbers    ${response.status_code}    200

Create Session    api    ${BASE_URL} 
${headers}=       Create Dictionary    Authorization=${AUTH_TOKEN}    Content-Type=application/json
${response}=      GET On Session    api    url=${BASE_URL}     headers=${headers}

${response}= We are saving the response of the GET operation in the ${response} variable.

4. Asserts that the response status code is 200, indicating a successful request.

Log To Console    Status Code: ${response.status_code}
Log To Console    Response Body: ${response.text}
Should Be Equal As Numbers    ${response.status_code}    200

Step 6 – Execute the tests

We need the below command to run the Robot Framework script.

robot AuthTokenDemo.robot

The output of the above program is

Step 7 – View Report and Log

We have the test case passed. The Robot Framework generates log.html, output.xml, and report.html by default.

Let us now see the report and log details.

Report

Right-click on report.html. Select Open In->Browser->Chrome(any browser of your wish).

The Report generated by the framework is shown below:

Log

Robot Framework has multiple log levels that control what is shown in the automatically generated log file. The default Robot Framework log level is INFO.

Right-click on log.html. Select Open In->Browser->Chrome(any browser of your wish).

That’s it! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!

Additional Tutorials

How to Install Python on Windows 11
How to install and setup Robot Framework for Python
How to rerun failed tests in Robot Framework
Page Object Model in the Robot Framework
Parallel Testing in Robot Framework
How to load data from CSV files in the Robot Framework?

SQL Multiple Choice Answers – MCQ3

HOME

SQL Multiple Choice Questions – MCQ3

























SQL Multiple Choice Questions – MCQ3

HOME

Answer


Answer


Answer


Answer


Answer


Answer


Answer


ALTER TABLE Employees ADD CHECK (Age >= 18);

Answer


Answer


Answer


Answer


UPDATE Products SET Price = Price * 1.1 WHERE Price < 100 OR Price > 200;

Answer


SELECT Name FROM Employees WHERE NOT (Age < 30 AND Department = 'Sales');

Answer


SELECT * FROM Employees WHERE Department = 'HR' XOR Department = 'Finance';

Answer


UPDATE Employees SET Salary *= 2 WHERE YearsOfExperience > 5;

Answer


Answer


Answer


SELECT Department, COUNT(*) FROM Employees GROUP BY Salary;

Answer


SELECT AVG(Salary) AS AverageSalary FROM Employees HAVING AverageSalary > 50000;

Answer


SELECT Name, Department, COUNT(*) FROM Employees WHERE Department = 'Sales' GROUP BY Department;

Answer


SELECT Department, SUM(Salary) FROM Employees GROUP BY Department HAVING COUNT(*) > 5;

Answer


SELECT * FROM Employees ORDER BY 3;

Answer


SELECT Department, MAX(Salary) FROM Employees WHERE MAX(Salary) > 50000 GROUP BY Department;

Answer


SELECT Department, COUNT(EmployeeID) FROM Employees GROUP BY Department HAVING COUNT(EmployeeID) > ALL (SELECT COUNT(EmployeeID) FROM Employees GROUP BY Department);

Answer


SELECT Department, COUNT(*) AS TotalEmployees FROM Employees GROUP BY Department HAVING TotalEmployees > 5 ORDER BY TotalEmployees;

Answer

====================================================================

SQL Multiple Choice Questions – MCQ2
SQL Multiple Choice Questions – MCQ3 

How to Implement Basic Auth in Robot Framework

HOME

In this article, we will discuss how to perform Basic Auth with base64. We will focus on its implementation in Robot Framework. 

Prerequisite:

  1. Install Python
  2. Install PIP
  3. Install Robot Framework
  4. Install Robot framework Selenium Library
  5. Install PyCharm IDE

Please refer to this tutorial to install Robot Framework – How to install and setup Robot Framework for Python.

RequestLibrary is a Robot Framework library aimed to provide HTTP API testing functionalities by wrapping the well-known Python Requests Library.

Implementation Steps:

Step 1.1 – Open PyCharm and create a new project. Go to File and select New Project from the main menu.

Step 1.2 – Choose the project location. Click the “Browse” button next to the Location field and specify the directory for your project.

Deselect the Create a main.py welcome script checkbox because you will create a new Python file for this tutorial.

Click on the “Create” Button.

Step 1.3 – A new dialog appears asking to open the project using any one of the given options. I have selected New Window as I like to have separate windows for each project.

Below is the image of the new project created in PyCharms.

Step 2 – Install RequestLibrary

To install RequestLibrary, you need to use the below command:

pip install robotframework-requests

Step 3 – Add robotframework-requests package to the PyCharms

Go to File->Settings ->Project:API_RobotFramework ->Python Interpreter.

Click on the “+” sign and enter robotframework-requests in the search bar. It will show a list of packages. Select the “robotframework-requests” package and click on the “Install Package”.

Once the package is installed, we will see the message that the package is installed successfully.

Once the package is installed, it can be seen under the package list as shown below:

Step 4 – Create a new directory in the new project

Right-Click on the project, select New->Directory, and provide the name as Tests

Below is the image of the new directory.

Right-click on the new directory and select New File and provide the name as AuthTokenDemo.robot as shown below:

Step 5 – Create API tests in Robot Framework

*** Settings ***
Library           RequestsLibrary
Library           Collections
Library           BuiltIn

*** Variables ***
${BASE_URL}       https://httpbin.org/basic-auth/user/pass
${USERNAME}       user
${PASSWORD}       pass
#${HEADERS}        Create Dictionary    Content-Type=application/json

**** Keywords ***
Create Basic Auth Header

    # Concatenate the username and password in "user:pass" format
    ${credentials}=    Set Variable    ${username}:${password}
    Log To Console    Credentials: ${credentials}

    # Encode the credentials using base64 encoding
    ${encoded}=    Evaluate    str(base64.b64encode('${credentials}'.encode('utf-8')), 'utf-8')    modules=base64
    Log To Console    Encoded Credentials: ${encoded}

    # Create a headers dictionary and add the Authorization header
    ${headers}=    Create Dictionary    Content-Type=application/json
    Set To Dictionary    ${headers}    Authorization=Basic ${encoded}
    RETURN    ${headers}

**** Test Cases ***
Test Preemptive Basic Auth with Custom Header
    [Documentation]   Manually setting Authorization header for preemptive Basic Authentication

    ${headers}=    Create Basic Auth Header

    Create Session    api    ${BASE_URL}    headers=${headers}
    ${response}=      GET On Session    api    url=${BASE_URL}
    Log To Console    Status Code: ${response.status_code}
    Log To Console    Response Body: ${response.text}
    Should Be Equal As Numbers    ${response.status_code}    200

${credentials}=    Set Variable    ${username}:${password}
Log To Console    Credentials: ${credentials}
${encoded}=    Evaluate    str(base64.b64encode('${credentials}'.encode('utf-8')), 'utf-8')    modules=base64
Log To Console    Encoded Credentials: ${encoded}
${headers}=    Create Dictionary    Content-Type=application/json
Set To Dictionary    ${headers}    Authorization=Basic ${encoded}
RETURN    ${headers}

${headers}=    Create Basic Auth Header
Create Session    api    ${BASE_URL}    headers=${headers}
${response}=    GET On Session    api    url=${BASE_URL}

${response}= We are saving the response of the GET operation in the ${response} variable.

4. Asserts that the response status code is 200, indicating a successful request.

 Log To Console    Status Code: ${response.status_code}
Log To Console    Response Body: ${response.text}
Should Be Equal As Numbers    ${response.status_code}    200

Step 6 – Execute the tests

We need the below command to run the Robot Framework script.

robot BasicAuthDemo.robot

The output of the above program is

Step 7 – View Report and Log

We have the test case passed. The Robot Framework generates log.html, output.xml, and report.html by default.

Let us now see the report and log details.

Report

Right-click on report.html. Select Open In->Browser->Chrome(any browser of your wish).

The Report generated by the framework is shown below:

Log

Robot Framework has multiple log levels that control what is shown in the automatically generated log file. The default Robot Framework log level is INFO.

Right-click on log.html. Select Open In->Browser->Chrome(any browser of your wish).

That’s it! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!

Additional Tutorials

How to Install Python on Windows 11
How to install and setup Robot Framework for Python
How to rerun failed tests in Robot Framework
Page Object Model in the Robot Framework
Parallel Testing in Robot Framework
How to load data from CSV files in the Robot Framework?