Order By clause is used to sort the retrieved data in ascending or descending order. Group By clause is used to group the result-set by one or more columns. Order and Group are not valid SQL commands.
3) a) True
NULL signifies an unknown value or a value which doesn’t exist during the creation of the record.
4) c) Drop
5) a) <>
6) c) Select top
7) d) Limit
All database systems does not supports SELECT TOP clause. It can be used in SQL. Mysql supports the LIMIT clause to fetch a limited number of records from the database table.
8) d) All correct
9) b) Selects a record if both conditions are true
10) b) Adds a value to a column’s existing value
11) a) True
12) d) No syntax error
13) d) No error
14) a) XOR operator
SQL does not have an XOR logical operator. Use AND/OR instead.
15) d) All Correct
The compound operator ‘*=’ is correctly used to double the salary of specified employees.
16) a) It functions as a WHERE clause
Without GROUP BY, HAVING functions like a WHERE clause, filtering rows based on specified conditions.
17) a) The query fails
Using a column in SELECT that is not part of GROUP BY without an aggregate function causes the query to fail.
18) c) GROUP BY Salary
GROUP BY should be used with the column mentioned in SELECT, here it should be GROUP BY Department.
19) d) HAVING AverageSalary > 50000
HAVING should be used with an aggregate function directly, not with an alias.
20) a) SELECT Name
Name should be included in the GROUP BY clause or used within an aggregate function.
21) d) No Error
The query correctly groups by Department and uses HAVING to filter groups.
22) d) All Correct
ORDER BY 3 is correct, indicating ordering by the third column in the SELECT list.
23) c) WHERE MAX(Salary) > 50000
Aggregate functions such as MAX should be used in the HAVING clause when filtering groups created by the GROUP BY clause.
24) c) No error
The query correctly uses HAVING with ALL to compare counts across departments.
25) c) HAVING clause misuse
The original statement had an error in the HAVING clause. It incorrectly used the alias ‘TotalEmployees’. The correct HAVING clause should be “HAVING COUNT(*) > 5”.
Welcome to the SQL Quiz! This blog post features 25 multiple-choice questions that explore essential concepts of SQL.
1. Which of the following statement is true about views in SQL?
Select the best answer
a) We can delete but not insert rows in a view b) We cannot insert and delete rows in a view c) We can insert but not delete rows in a view d) We can insert and delete rows in a view
SELECT Department, COUNT(EmployeeID) FROM Employees GROUP BY Department HAVING COUNT(EmployeeID) > ALL (SELECT COUNT(EmployeeID) FROM Employees GROUP BY Department);
Choose one option
a) ALL operator b) COUNT(EmployeeID) c) No error d) subquery
In this article, we will discuss how to perform Basic Auth with base64. We will focus on its implementation in Robot Framework.
What is Basic Auth?
Basic Authentication (Basic Auth) is a simple authentication scheme built into the HTTP protocol. It is used to securely transmit user credentials (username and password) to authenticate to an API or a web service.
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 – Create a new project
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
The API Test 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
Variables Section
${BASE_URL}: The base URL for the HTTP request. ${USERNAME} and ${PASSWORD}: Credentials for Basic Authentication.
Keywords Section
This custom keyword creates an HTTP header with Basic Authentication.
1. This concatenates the username and password into the format "user:pass".
${credentials}= Set Variable ${username}:${password}
Log To Console Credentials: ${credentials}
2. Converts the string “user:pass” into a base64-encoded format. This is required for the Authorization header in Basic Authentication.
Create Dictionary: Initializes a dictionary with a key-value pair for Content-Type. Set To Dictionary: Adds the Authorization header with the value Basic . RETURN: Returns the dictionary to the calling test case.
${headers}= Create Dictionary Content-Type=application/json
Set To Dictionary ${headers} Authorization=Basic ${encoded}
RETURN ${headers}
Test Case Section:
This test case uses the Create Basic Auth Header keyword to perform an authenticated GET request.
1. Calls the Create Basic Auth Header keyword to get a dictionary containing the HTTP headers for the request.
${headers}= Create Basic Auth Header
2. Initializes an HTTP session named “api” with the specified base URL and headers. The headers contain Authorization for Basic Authentication.
Create Session api ${BASE_URL} headers=${headers}
3. Sends a GET request on the “api” session to the specified URL. This request uses the headers created earlier, which include Basic Authentication.
${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!!
1) B) A continuous integration/continuous delivery (CI/CD) tool
2) C) Java
3) C) Automating parts of the software development process
4) B) java -jar jenkins.war
5) D) Jenkins Client
Jenkins Client is not a core component of Jenkins. The core components of Jenkins include Jenkins Master, Jenkins Slave, and Jenkins Node.
6) B) A unit of work that Jenkins executes
7) C) Source Code Management
8) D) All of the above
9) B) A piece of software that provides additional functionality to Jenkins
A Jenkins plugin is a piece of software that provides additional functionality to Jenkins. There are thousands of plugins available for Jenkins, including plugins for source control, build tools, and notification systems.
10) C) Manage Plugins under Manage Jenkins
11) B) A tool used to manage the installation of plugins in Jenkins
The Jenkins Plugin Manager is a tool used to manage the installation of plugins in Jenkins. It allows users to search for and install new plugins, update existing plugins, and configure plugin settings.
12) C) Access “Manage Plugins” in Jenkins and install from the available plugins list
13) D) All of the above
14) C) To define tools like JDK, Maven, and Git that are available to Jenkins jobs
15) D) To manage security settings for Jenkins
The Jenkins Security Plugin is used to manage security settings for Jenkins. It allows users to define users, groups, and permissions for accessing Jenkins resources, ensuring that only authorized users can perform actions in Jenkins.
16) D) To create backups of Jenkins configurations and jobs
The Jenkins Backup Plugin is used to create backups of Jenkins configurations and jobs. It allows users to easily restore a Jenkins server in the event of a failure or to migrate to a new server.
17) B) To enable Jenkins to communicate with external systems
The Jenkins Notification Plugins are used to enable Jenkins to communicate with external systems. They allow users to send notifications, such as build results or deployment status, to other systems, such as chat services or email.
18) A) An interface used to interact with Jenkins via HTTP requests
The Jenkins REST API is an interface used to interact with Jenkins via HTTP requests. It allows users to perform common tasks, such as triggering builds or retrieving build results, using simple HTTP calls.
19) A) A command-line interface used to interact with a Jenkins server
The Jenkins CLI is a command-line interface used to interact with a Jenkins server. It allows users to perform common tasks, such as creating jobs or triggering builds, from the command line.
Welcome to the Jenkins Quiz! This blog post features 25 multiple-choice questions that explore essential concepts of Jenkins.
1. What is Jenkins?
Select the best answer
A) A database management tool B) A continuous integration/continuous delivery (CI/CD) tool C) A programming language D) An integrated development environment (IDE)
A) A set of scripts that automate the building of software B) A piece of software that provides additional functionality to Jenkins C) A configuration file that defines the build process in Jenkins D) A report generated by Jenkins after a build is complete
A) A feature that allows users to configure global settings in Jenkins B) A tool used to manage the installation of plugins in Jenkins C) A tool used to manage the installation of software on Jenkins nodes D) A tool used to manage the distribution of work to Jenkins slaves
A) Manually download the plugin file and move it to the Jenkins installation directory B) Use the “Install Plugin” option in Global Tool Configuration C) Access “Manage Plugins” in Jenkins and install from the available plugins list D) Jenkins does not support plugin installations
14. What is the purpose of the “Global Tool Configuration” in Jenkins?
Choose one option
A) To configure global security settings B) To manage system logs C) To define tools like JDK, Maven, and Git that are available to Jenkins jobs D) To configure job-level parameters
15. What is the purpose of the Jenkins Security Plugin?
Choose one option
A) To manage the installation of plugins in Jenkins B) To manage the distribution of work to Jenkins slaves C) To enable Jenkins to communicate with external systems D) To manage security settings for Jenkins
16. What is the purpose of the Jenkins Backup Plugin?
Choose one option
A) To manage the installation of plugins in Jenkins B) To manage the distribution of work to Jenkins slaves C) To enable Jenkins to communicate with external systems D) To create backups of Jenkins configurations and jobs
17. What is the purpose of the Jenkins Notification Plugins?
Choose one option
A) To manage the installation of plugins in Jenkins B) To enable Jenkins to communicate with external systems C) To define Jenkins jobs in code D) To extend the functionality of Jenkins
A) An interface used to interact with Jenkins via HTTP requests B) A tool used to manage the installation of software on Jenkins nodes C) A tool used to manage the distribution of work to Jenkins slaves D) A graphical user interface used to interact with a Jenkins server
A) A command-line interface used to interact with a Jenkins server B) A graphical user interface used to interact with a Jenkins server C) A tool used to manage the installation of software on Jenkins nodes D) A tool used to manage the distribution of work to Jenkins slaves
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 – Create 3 new directories in the new project
Right-Click on the project, select New->Directory, and provide the name as Tests, Drivers, and Resources
Below is the image of the new directories.
Step 3 – Download ChromeBinaries, Geckodriver and msedgedriver binaries
Download ChromeBinaries, Geckodriver and msedgedriver binaries and place in Drivers directory. This directory contains the browser binary in it. As we are using Chrome, will keep chromedriver.exe here.
The tests are going to use the Chrome browser, Firefox and Edge browsers, so we need to download the corresponding driver binaries to open a blank browser.
I will rename chromedriver.exe to Chrome, msedgedriver.exe to Edgeand geckodriver.exe to Firefox.
Step 4 – Create Test Files
This directory contains multiple test case files consisting of test steps.
Right-click on the new directory and select New File and provide the name as LoginPageTests.robot as shown below:
Below is the code for LoginPageTests.robot
*** Settings ***
Documentation Tests to login to Login Page
Library SeleniumLibrary
Test Setup Open the Browser with URL
Test Teardown Close Browser Session
Resource ../Resources/GenericResources.robot
Resource ../Resources/LoginResources.robot
*** Test Cases ***
Validate Unsuccessful Login using invalid credentials
LoginResources.Fill the login form ${valid_username} ${invalid_password}
LoginResources.Verify the error message is correct
Validate successful Login
LoginResources.Fill the login form ${valid_username} ${valid_password}
DashboardResources.Verify Dashboard page opens
Settings
Documentation: Allows to add the description about the Login Test page. Library: Import SeleniumLibrary for browser interactions. Test Setup: Open the Browser with URL keyword to setup the browser before each test Test Teardown: Capture Screenshot On Failure keyword to capture screenshots if the test fails Suite Teardown: Close Browser Session keyword close all the browsers at the end of the test suite. Resource: Provide the path of the resource file that contains the reusable keywords, variables and other settings.
Step 5 – Create Resources file for each page
It maintains the files which contain page elements as well as corresponding keywords.
Right-click on the new directory and select New File and provide the name as LoginResources.robot, DashboardResources.robot and GenericResources.robot as shown below:
GenericResources.robot contains the keywords that are common to all the tests, like the opening of the browser or closing of the browser.
*** Settings ***
Documentation A resource file with reusable keywords and variables.
Library SeleniumLibrary
*** Variables ***
${valid_username} Admin
${valid_password} admin123
${invalid_username} 1234
${invalid_password} 45678
${url} https://opensource-demo.orangehrmlive.com/web/index.php/auth/login
${browser} Chrome #Default browser, if no browser provided
*** Keywords ***
Open the Browser with URL
Open Browser ${url} ${browser} executable_path=C:/Users/vibha/Documents/Automation/Python/CrossBrowser_RobotFramework/Drivers/${browser}
Maximize Browser Window
Set Selenium Implicit Wait 5
Close Browser Session
Close Browser
Variables used in GenericResources.robot
${valid_username}, ${valid_password}, ${invalid_username}, ${invalid_password}: Assign values ${url}: The URL to navigate to ${browser_name}: Browser will be used to run the tests
Below is the code for LoginResources.robot
*** Settings ***
Documentation All the page objects and keywords of landing page
Library SeleniumLibrary
*** Variables ***
${login_error_message} css:.oxd-alert-content--error
${dashboard_title} css:.oxd-topbar-header-breadcrumb-module
${missing_username_error_message} xpath://*[@class='oxd-form']/div[1]/div/span
${missing_password_error_message} xpath://*[@class='oxd-form']/div[2]/div/span
${forgot_password_link} xpath://div[@class='orangehrm-login-forgot']/p
*** Keywords ***
Fill the login form
[Arguments] ${username} ${password}
Input Text css:input[name=username] ${username}
Input Password css:input[name=password] ${password}
Click Button css:.orangehrm-login-button
Verify the error message is correct
Element Text Should Be ${login_error_message} Invalid credentials
Below is the code for DashboardResources.robot
*** Settings ***
Documentation All the page objects and keywords of Dashboard page
Library SeleniumLibrary
*** Variables ***
${dashboard_title} css:.oxd-topbar-header-breadcrumb-module
*** Keywords ***
Verify Dashboard page opens
Element Text Should Be ${dashboard_title} Dashboard
All the below-mentioned keywords are derived from SeleniumLibrary. The functionality of keywords mentioned above:
1. Open Browser − The keyword opens a new browser instance to the optional url.
2. Maximize Browser Window – This keyword maximizes the current browser window.
3. Set Selenium Implicit Wait – This keyword sets the implicit wait value used by Selenium.
4. Close Browser – Close the current browser.
5. Input Text − This keyword is used to type the given text in the specified textbox identified by the locator name:username.
6. Input Password – This keyword is used to type the given text in the specified password identified by the locator name:password.
The difference compared to Input Text is that this keyword does not log the given password on the INFO level.
7. Click button – This keyword is used to click the button identified by the locator. In this case, it is “Login” button.
8. Element Text Should Be – This keyword is used to verify that the current page contains the exact text identified by the locator. Here, we are checking the exact text “Invalid Credentials”.
To run this script, go to the command line and go to directory tests.
Step 6 – Execute the tests
Run your tests separately for each browser (e.g., Chrome, Firefox, Edge), generating an individual output XML file for each. For example, use the below command to run the tests using the Chrome browser:
1. –outputdir Report specifies the directory where the consolidated report will be saved.
2. –report “Consolidated Report.html” sets the name of the report of the Consolidated Report.
3. The list of XML files (output_chrome.xml, output_edge, output_firefox) are the individual report files that will be merged.
Step 8 – View Report and Log
We have total 6 test cases passed (2 test case for each browser).
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
The screenshots will be included in the log.html file under the specific failed test case step. 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!!
The previous tutorial explained the How to rerun failed tests in Cucumber. There are multiple times that we need to rerun the failed tests twice to overcome the intermittent network or environment issues. This can be achieved by creating multiple TestRunner class.
In the main test runner, configure Cucumber to generate a JSON report for the initial test run and capture any failed tests in a rerun file. We are using rerun plugin to logs the paths of failed scenarios in a text file – rerun.txt that will be created inside the target folder.
Set Up a Runner for running the failed tests first time
Create a second runner that reads from the rerun.txt file and generates a new rerun1.txt file that contains the path of failed tests and create a separate JSON report for failed test reruns.
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
@CucumberOptions(tags = "",
features = "@target/rerun.txt",
glue = "com.example.definitions",
plugin = {
"pretty",
"html:target/cucumber-reports/cucumber-rerun1-report.html",
"json:target/cucumber-reports/cucumber-rerun1-report.json",
"rerun:target/rerun1.txt"
}
)
public class RunnerTestsFailed extends AbstractTestNGCucumberTests {
}
Set Up a Runner for running the failed tests second time
Create a third runner that reads from the rerun1.txt file and generates a separate JSON report for failed test reruns.
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
@CucumberOptions(tags = "",
features = "@target/rerun1.txt",
glue = "com.example.definitions",
plugin = {
"pretty",
"html:target/cucumber-reports/cucumber-rerun2-report.html",
"json:target/cucumber-reports/cucumber-rerun2-report.json"
}
)
public class RunnerTestsSecondFailed extends AbstractTestNGCucumberTests {
}
Mention all the Test Runner details in the testng.xml
We need to mention all the TestRunner class name in the testng.xml. This will run first runner that will generate a file rerun.txt which in turns contain the path of the failed scenarios. Then, second runner will use this new file rerun.txt as input to the feature file and rerun the failed tests and generate second file – rerun1.txt which is used as input to the third Test Runner file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Cucumber with TestNG Test">
<classes>
<class name="com.example.runner.RunnerTests"/>
<class name="com.example.runner.RunnerTestsFailed"/>
<class name="com.example.runner.RunnerTestsSecondFailed"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Add cucumber-reporting Plugin to pom.xml
Use the cucumber-reporting plugin by Masterthought to combine the JSON files into a single report. Configure the plugin in your pom.xml to read both the main and rerun JSON files.
Use the below command to run the tests and generate the consolidated Test Report.
mvn clean verify
RunnerTests class generates cucumber-report.json file whereas RunnerTestsFailed generates cucumber-rerun-report.json files are present in target/cucumber-reports folder.
MasterThought plugin uses these json files to generate a consolidated report in target/cucumber-html-reports.
There are different types of HTML reports gets generated as a part of the test execution cycle.
1. feature-overview – This HTML report gives an overall overview of test execution. Main HTML report which covers all different sections like Features, Tags, Steps, and Failures.
2. failures-overview – This HTML report gives an overview of all failed tests.
3. step-overview – This HTML report shows step statistics for the current cycle.
4. tag-overview – This HTML report shows passing and failing statistics for different tags used in test execution.
Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers!!
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 – Create 3 new directories in the new project
Right-Click on the project, select New->Directory, and provide the name as Tests, Drivers, and Resources
Below is the image of the new directories.
Step 3 – Download ChromeBinaries and place in Drivers directory
This directory contains the browser binary in it. As we are using Chrome, will keep chromedriver.exe here.
The tests are going to use the Chrome browser, so we need to download the ChromeBinaries to open a blank browser in Chrome.
This directory contains multiple test case files consisting of test steps.
Right-click on the new directory and select New File and provide the name as LoginPageTests.robot as shown below:
Below is the code for LoginPageTests.robot
*** Settings ***
Documentation Tests to login to Login Page
Library SeleniumLibrary
Test Setup Open the Browser with URL
Test Teardown Capture Screenshot On Failure
Suite Teardown Close Browser Session
Resource ../Resources/GenericResources.robot
Resource ../Resources/LoginResources.robot
*** Test Cases ***
Validate Unsuccessful Login using invalid credentials
LoginResources.Fill the login form ${valid_username} ${invalid_password}
LoginResources.Verify the error message is correct
Validate successful Login
LoginResources.Fill the login form ${valid_username} ${valid_password}
DashboardResources.Verify Dashboard page opens
Validate Unsuccessful Login for blank username
LoginResources.Fill the login form ${blank_username} ${valid_password}
LoginResources.Verify the error message is displayed for username
Settings
Documentation: Allows to add the description about the Login Test page.
Library: Import SeleniumLibrary for browser interactions.
Test Setup: Open the Browser with URL keyword to setup the browser before each test
Test Teardown: Capture Screenshot On Failure keyword to capture screenshots if the test fails
Suite Teardown: Close Browser Session keyword close all the browsers at the end of the test suite.
Resource: Provide the path of the resource file that contains the reusable keywords, variables and other settings.
Step 5 – Create Resources file for each page
It maintains the files which contain page elements as well as corresponding keywords.
Right-click on the new directory and select New File and provide the name as LoginResources.robot, DashboardResources.robot and GenericResources.robot as shown below:
GenericResources.robot contains the keywords that are common to all the tests, like the opening of the browser or closing of the browser.
*** Settings ***
Documentation A resource file with reusable keywords and variables.
Library SeleniumLibrary
*** Variables ***
${valid_username} Admin
${valid_password} admin123
${invalid_username} 1234
${invalid_password} 45678
${blank_username}
${url} https://opensource-demo.orangehrmlive.com/web/index.php/auth/login
${browser_name} Chrome
${output_dir} ./screenshots
*** Keywords ***
Open the Browser with URL
Open Browser ${url} ${browser_name} executable_path=C:/Users/vibha/Documents/Automation/Python/CrossBrowser_RobotFramework/Drivers/${browser_name}
Maximize Browser Window
Set Selenium Implicit Wait 5
Capture screenshot On Failure
Run Keyword If Test Failed Capture Page Screenshot ${output_dir}/${TEST NAME}.png
Close Browser
Close Browser Session
Close Browser
${browser_name}: Browser will be used to run the tests
${output_dir}: Directory where the screenshots will be saved.
Below is the code for LoginResources.robot
*** Settings ***
Documentation All the page objects and keywords of landing page
Library SeleniumLibrary
*** Variables ***
${login_error_message} css:.oxd-alert-content--error
${dashboard_title} css:.oxd-topbar-header-breadcrumb-module
${missing_username_error_message} xpath://*[@class='oxd-form']/div[1]/div/span
*** Keywords ***
Fill the login form
[Arguments] ${username} ${password}
Input Text css:input[name=username] ${username}
Input Password css:input[name=password] ${password}
Click Button css:.orangehrm-login-button
Verify the error message is correct
Element Text Should Be ${login_error_message} Invalid credentials
Verify the error message is displayed for username
Element Text Should Be ${missing_username_error_message} Required
Below is the code for DashboardResources.robot
*** Settings ***
Documentation All the page objects and keywords of Dashboard page
Library SeleniumLibrary
*** Variables ***
${dashboard_title} css:.oxd-topbar-header-breadcrumb-module
*** Keywords ***
Verify Dashboard page opens
Element Text Should Be ${dashboard_title} Dashboard
All the below-mentioned keywords are derived from SeleniumLibrary. The functionality of keywords mentioned above:
1. Open Browser − The keyword opens a new browser instance to the optional url.
2. Maximize Browser Window – This keyword maximizes the current browser window.
3. Set Selenium Implicit Wait – This keyword sets the implicit wait value used by Selenium.
4. Run Keyword If Test Failed – Runs the given keyword with the given argument (Capture Page Screenshot), if the test failed.
5. Close Browser – Close the current browser.
6. Input Text − This keyword is used to type the given text in the specified textbox identified by the locator name:username.
7. Input Password – This keyword is used to type the given text in the specified password identified by the locator name:password.
The difference compared to Input Text is that this keyword does not log the given password on the INFO level.
8. Click button – This keyword is used to click the button identified by the locator. In this case, it is “Login” button.
9. Element Text Should Be – This keyword is used to verify that the current page contains the exact text identified by the locator. Here, we are checking the exact text “Invalid Credentials”.
To run this script, go to the command line and go to directory tests. We need the below command to run the Robot Framework script.
robot .
The output of the above program is
Step 7 – View Screenshots of the failed tests
Screenshots of the failed tests will be saved in screenshots folder with the name of failed test as shown in the below image.
Step 8 – View Report and Log
We have 2 test cases passed and 1 failed. 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
The screenshots will be included in the log.html file under the specific failed test case step. 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).
Points to Consider
Path to Screenshots: By default, screenshots are saved in the same directory as the test files. We can customize the path in the Capture Screenshot On Failure keyword. Here, we have used screenshot folder to save the screenshots in it.
Browser Compatibility: Make sure that we have the correct WebDriver for the browser as well as compatible version of the driver (e.g., chromedriver for Chrome, geckodriver for Firefox, msedgedriver for Edge).
Failure Scenarios: This setup captures screenshots only when a test fails, making it easier to debug issues.
That’s it! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!
1) c) Organized collection of data or information that can be accessed, updated, and managed
2) c) Table
3) a) All Correct
4) c) WHERE clause
The WHERE clause is incomplete and needs a condition to specify which records to update.
5) a) True
6) a) SELECT * FROM Employees WHERE FirstName=’Peter’ AND LastName=’Jackson’
7) a) All Correct
8) b) >= ‘2023-06-01’
The OR operator should be followed by a complete condition, including the column name. SELECT * FROM Orders WHERE OrderDate >= ‘2023-01-01’ OR OrderDate >= ‘2023-06-01’;
9) c) HAVING
10) c) No error
11) a) SELECT * FROM Employees WHERE LastName BETWEEN ‘Hansen’ AND ‘Pettersen’
12) a) SELECT DISTINCT
13) a) ORDER BY
14) a) SELECT * FROM Employees ORDER BY FirstName DESC
15) a) INSERT INTO Employees VALUES (‘Jimmy’, ‘Jackson’)
16) a) INSERT INTO Persons (LastName) VALUES (‘Olsen’)
17) c) To give users access privileges
18) b) Removes specific access privileges from users
19) d) All Correct
20) c) ON Database
This is because the REVOKE statement usually specifies the type of object (such as a) specific table or schema) with tables). Just mentioning Database without specifying an object within it is incorrect. The corrected syntax typically needs to look like:
REVOKE INSERT, UPDATE ON Database.* FROM user123;
21) a) UPDATE Employees SET LastName=’Nilsen’ WHERE LastName=’Hansen’
22) a) DELETE FROM Employees WHERE FirstName = ‘Peter’
Welcome to the SQL Quiz! This blog post features 25 multiple-choice questions that explore essential concepts of SQL.
1. What is a database?
Select the best answer
a) Organized collection of information that cannot be accessed, updated, and managed b) Collection of data or information without organizing c) Organized collection of data or information that can be accessed, updated, and managed d) Organized collection of data that cannot be updated
6. With SQL, how do you select all the records from a table named “Employees” where the “FirstName” is “Peter” and the “LastName” is “Jackson”?
Choose one option
a) SELECT * FROM Employees WHERE FirstName='Peter' AND LastName='Jackson'
b) SELECT FirstName='Peter', LastName='Jackson' FROM Employees
c) SELECT * FROM Employees WHERE FirstName<>'Peter' AND LastName<>'Jackson'
d) SELECT * FROM Employees WHERE FirstName='Jackson' AND LastName='Peter'
11. With SQL, how do you select all the records from a table named “Employees” where the “LastName” is alphabetically between (and including) “Hansen” and “Pettersen”?
Choose one option
a) SELECT * FROM Employees WHERE LastName BETWEEN 'Hansen' AND 'Pettersen'
b) SELECT * FROM Employees WHERE LastName>'Hansen' AND LastName<'Pettersen'
c) SELECT LastName>'Hansen' AND LastName<'Pettersen' FROM Employees
d) None
14. With SQL, how can you return all the records from a) table named “Employees” sorted descending by “FirstName”?
Choose one option
a) SELECT * FROM Employees ORDER BY FirstName DESC
b) SELECT * FROM Employees SORT 'FirstName' DESC
c) SELECT * FROM Employees SORT BY 'FirstName' DESC
d) SELECT * FROM Employees ORDER FirstName DESC
15. With SQL, how can you insert a new record into the “Employees” table?
Choose one option
a) INSERT INTO Employees VALUES ('Jimmy', 'Jackson')
b) INSERT VALUES ('Jimmy', 'Jackson') INTO Employees
c) INSERT ('Jimmy', 'Jackson') INTO Employees
d) INSERT INTO Table Employees VALUES ('Jimmy', 'Jackson')
16. With SQL, how can you insert “Olsen” as the “LastName” in the “Persons” table?
Choose one option
a) INSERT INTO Persons (LastName) VALUES ('Olsen')
b) INSERT ('Olsen') INTO Persons (LastName)
c) INSERT INTO Persons ('Olsen') INTO LastName
d) All incorrect
21. How can you change “Hansen” into “Nilsen” in the “LastName” column in the Employees table?
Choose one option
a) UPDATE Employees SET LastName='Nilsen' WHERE LastName='Hansen'
b) MODIFY Employees SET LastName='Nilsen' WHERE LastName='Hansen'
c) UPDATE Employees SET LastName='Hansen' INTO LastName='Nilsen'
d) MODIFY Employees SET LastName='Hansen' INTO LastName='Nilsen
22. With SQL, how can you delete the records where the “FirstName” is “Peter” in the Employees Table?
Choose one option
a) DELETE FROM Employees WHERE FirstName = 'Peter'
b) DELETE FirstName='Peter' FROM Employees
c) DELETE ROW FirstName='Peter' FROM Employees
d) All are incorrect