python -m venv venv
venv\Scripts\activate- Open File → Settings (or Ctrl + Alt + S).
- Navigate to Project: Robot_Framework → Python Interpreter
- Add Interpreter -> Add Local Interpreter
- Choose 'Select existing' option -> OK -> OK
- Restart PyCharm
- Open File -> Settings -> Plugins -> Marketplace
- Search for 'IntelliBot #Update' -> Install
- Restart PyCharm
Robot Framework Official Documentation
SeleniumLibrary Official Documentation
pip install robotframework
robot --version
Robot Framework 7.2.2 (Python 3.13.1 on win32)
pip install robotframework-seleniumlibrary
python -c "import SeleniumLibrary; print(SeleniumLibrary.__version__)"
6.7.0
python -c "import selenium; print(selenium.__version__)"
4.29.0
REM Allure Library
pip install allure-robotframework
allure --version
2.32.0
REM Data Driver - Excel
pip install robotframework-datadriver
pip install pandas openpyxl
OR
- Open File → Settings (or Ctrl + Alt + S).
- Navigate to Project: Robot_Framework → Python Interpreter
- Click '+'
- robotframework -> Install Package
- robotframework-SeleniumLibrary -> Install Package
- Close -> OK
robot first_demo.robotreport.html -> Open In -> Browser -> Chrome
https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Set%20Selenium%20Implicit%20Wait
...
Open Browser ${URL} ${BROWSER}
Set selenium implicit wait ${TIMEOUT}
...
robot -d reports first_demo.robothttps://github.com/mozilla/geckodriver/releases
robot -d reports first_demov2.robot
REM Change config.robot => ${BROWSER_TYPE} = Firefox or Chromerobot -d tests test_variables.robot
REM ${env}= uat or qa
robot -d tests -v env:qa test_variables.robot
robot -d reports first_demov2.robot
REM Change config.robot => ${BROWSER_TYPE} = 1 for Chrome or 2 for Firefox
REM ${BROWSER} ${browsers["${BROWSER_TYPE}"]}
robot -d reports -v BROWSER_TYPE:1 first_demov2.robot
robot -d reports -v BROWSER_TYPE:2 first_demov2.robotrobot -d tests test_keywords.robot
robot -d tests -v browser:firefox test_keywords.robot
robot -d tests -v browser:chrome test_keywords.robot
REM Resource file Resource\commons.robot
REM Resource file Resource\common.robot
robot -d reports -v BROWSER_TYPE:1 first_demov2.robot
robot -d reports -v BROWSER_TYPE:2 first_demov2.robothttps://www.way2automation.com/ https://www.way2automation.com/way2auto_jquery/index.php
robot -d tests test_registration.robot
robot -d reports -v BROWSER_TYPE:1 first_demov2.robot
robot -d reports -v BROWSER_TYPE:2 first_demov2.robot- Xpath Format ...
//tagname[@attribute='value']
//id[@id='username']
//input[@name='username']- Test xPath in Chrome Console
- https://www.way2automation.com/way2auto_jquery/index.php => Developer Tools => Console
$x("(//input[@name='username'])")
$x("(//input[@name='username'])[1]")
$x("(//input[@name='username'])[2]")- Dynamic element https://www.way2automation.com/way2auto_jquery/automation-practice-site.html https://www.way2automation.com/way2auto_jquery/submit_button_clicked.php#load_box
REM Starts with subxxx
$x('//*[starts-with(@id, "sub")]')
$x('//*[starts-with(@id, "111")]')
$x('//*[starts-with(@id, "iden")]')[0]
REM Contains xxxsubxxx
$x('//*[contains(@id, "sub")]')
REM Gmail contains
$x('//*[contains(@id, "fierId")]')
$x('//*[contains(@id, "fierId")]/..')
$x('//*[contains(@id, "fierId")]/parent::div')
$x('//*[contains(@id, "fierNext")]')
$x('//input[contains(@id, "fierId")]')
REM Following sibling
$x('//*[contains(@id, "fierId")]/following-sibling::input')
- Following sibling: 在 XPath 中用于选择当前节点之后的同级元素(即具有相同父节点的元素)。 它用于选择当前元素的下一个兄弟节点。
<div>
<p id="first">这是第一个段落。</p>
<p id="second">这是第二个段落。</p>
<p id="third">这是第三个段落。</p>
</div>$x('//p[@id="first"]/following-sibling::p')
(2) [p#second, p#third]
$x('//p[@id="first"]/following-sibling::p')[0]
<p id="second">这是第二个段落。</p>
- Xpath Format ...
//tagName[@attribute='value']
//tagName[@attribute='value'][@attribute='value']
//tagName[starts-with(@attribute,'value')]
//tagName[contains(@attribute,'value')]
//tagName[text()='value']
//tagName[contains(text(),'partialvalue')]
//tagName[@attribute='value']/..
//tagName[@attribute='value']/parent::tagname
//tagName[@attribute='value']/following-sibling::tagname
//tagName[@attribute='value']/preceding-sibling::tagname[1]
- CSS Format ...
$$('body > form > input[type=text]:nth-child(1)')
REM Gmail
$$('#yDmH0d > c-wiz > div > div.UXFQgc > div > div > div.AcKKx > form > span > section > div > div > div.AFTWye.vEQsqe >) div > div.aCsJod.oJeWuf > div > div.Xb9hP > div'
$$("input[id='identifierId']")
$$("input[id='identifierId'][type='email']")
$$("input[id^='identif']")
$$("input[id$='fierId']")
$$("input[id*='dentif']")
$$('#identifierId')
$$('input#identifierId')
$$("input.whsOnd.zHQkBf")[0]
$$("div.rFrNMe.X3mtXb.UOsO2.ToAxb.zKHdkd.sdJrJc.Tyc9J")
document.querySelector("#identifierId")robot -d tests test_registration.robot
robot -d tests test_windowHandling.robotrobot -d tests test_if_else.robot
robot -d tests -v num1:15 test_if_else.robot
robot -d tests -v num1:8 test_if_else.robotrobot -d tests test_loops.robot
robot -d tests test_dropdown.robot
robot -d tests -v LANG:zh test_dropdown.robot
robot -d tests -v LANG:en test_dropdown.robot
robot -d tests -v LANG:hi test_dropdown.robot
robot -d tests -v LANG:ja test_dropdown.robot
robot -d tests test_checkboxes.robot
robot -d tests test_frames.robot
- https://way2automation.com/way2auto_jquery/index.php
- https://www.way2automation.com/way2auto_jquery/automation-practice-site.html
Alert Page (via Window Handling)
robot -d tests test_alerts.robot
robot -d tests test_mouseover.robot
- https://jqueryui.com/resources/demos/slider/default.html
- https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Drag%20And%20Drop%20By%20Offset
robot -d tests test_slider.robot
robot -d tests -v OFFSET_X:700 test_slider.robot
robot -d tests test_calendar.robot
robot -d tests test_calendar_jq.robot
robot -d tests DataDrivenTest\test_datadriven.robotrobot -d tests test_resizable.robot
robot -d tests -v OFFSET_X:700 test_resizable.robot
robot -d tests test_drag_and_drop.robot
- https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Open%20Context%20Menu
- https://deluxe-menu.com/popup-mode-sample.html
robot -d tests test_right_click.robot
robot -d tests test_javascript.robot
https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Capture%20Element%20Screenshot
robot -d tests test_javascript.robot
robot -d tests test_javascript2.robot
- headlesschrome
launching browser https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_submit_get headlesschrome
robot -d tests test_webtables.robot
- https://www.way2automation.com/way2auto_jquery/datepicker.php#load_box
- Custom Python Library -> Built_In/CustomLib.py
robot -d tests test_calendar.robot
pip install -U robotframework-tidy
robotidy test_calendar.robotrobot -d tests test_exception.robot
robot -d tests -v DIVISOR:4 test_try_except.robot
robot -d tests -v DIVISOR:0 test_try_except.robot
robot -d tests test_try_except2.robot
robot -d tests -v email_id:email test_try_except2.robot
pip install allure-robotframework- NodeJS
npm install -g allure-commandline --save-devrobot -d tests --listener allure_robotframework test_try_except2.robot
REM output\allure folder
robot -d tests --listener allure_robotframework:Allure_Report test_try_except2.robot
robot -d tests -v email_id:email --listener allure_robotframework:Allure_Report test_try_except2.robot
REM Failed Test Case
robot -d tests --listener allure_robotframework:Allure_Report test_calendar.robot
- Open Allure Report - last one Only
allure serve Allure_Report
REM 2 Test Cases ONLY...
REM Timeline will show the 3 runs- Edit test_try_except2.robot
Library BuiltIn
Library SeleniumLibrary
Library AllureLibrary
Library Built_In/CustomLib.py
...
FINALLY
Capture Screenshot
close browser
...
Divide
[Arguments] ${a} ${b}
TRY
${result}= Evaluate ${a} / ${b}
RETURN PASS ${result}
EXCEPT
RETURN FAIL 0
END
- Edit CustomLib.py
# Use -d tests from the Command Line ...
...
import os
...
def capture_screenshot():
lib = get_selenium_lib()
randomNum = random.randint(0, 9999)
fileName = f"seleniumLib-{randomNum}.png"
# Get the output directory from Robot Framework
output_dir = BuiltIn().get_variable_value('${OUTPUT_DIR}', 'tests1')
# Construct absolute path for the screenshot
file_path = os.path.join(output_dir, fileName)
# Capture screenshot
lib.capture_page_screenshot(file_path)
# Attach file to Allure report if Allure is available
allure = get_allure_lib()
if allure:
allure.attach_file(file_path)
return file_pathrobot -d tests test_try_except2.robot
robot -d tests -v email_id:email test_try_except2.robotrobot -d tests -v email_id:email --listener allure_robotframework:Allure_Report test_try_except2.robot
robot -d tests --listener allure_robotframework:Allure_Report test_try_except2.robot
robot -d tests --listener allure_robotframework:Allure_Report test_calendar.robot- test_calendar.robot
Teardown
run keyword if test failed Capture Screenshot
allure serve --port 2666 Allure_Report
pip install -U robotframework-pabot
robot -d tests --listener allure_robotframework:Allure_Report DataDrivenTest\test_datadriven.robot
pabot --processes 2 -d tests --listener allure_robotframework:Allure_Report DataDrivenTest\test_datadriven.robot
...
Robot Framework remote server at 127.0.0.1:8270 started.
Storing .pabotsuitenames file
2025-03-11 14:47:52.104115 [PID:6764] [0] [ID:0] EXECUTING Test Datadriven
2025-03-11 14:48:07.381371 [PID:6764] [0] [ID:0] still running Test Datadriven after 15.0 seconds
2025-03-11 14:48:27.715000 [PID:6764] [0] [ID:0] still running Test Datadriven after 35.0 seconds
2025-03-11 14:48:53.116358 [PID:6764] [0] [ID:0] still running Test Datadriven after 60.0 seconds
2025-03-11 14:49:07.098242 [PID:6764] [0] [ID:0] PASSED Test Datadriven in 73.8 seconds
4 tests, 4 passed, 0 failed, 0 skipped.
===================================================
Output: C:\Users\samfi\PycharmProjects\Robot_Framework\tests\output.xml
Log: C:\Users\samfi\PycharmProjects\Robot_Framework\tests\log.html
Report: C:\Users\samfi\PycharmProjects\Robot_Framework\tests\report.html
...
Total testing: 1 minute 13.80 seconds
Elapsed time: 1 minute 15.82 seconds
- Test all robots in the folder Parallel
REM All folders and subfolders
pabot --processes 3 -d tests --listener allure_robotframework:Allure_Report .
REM Only the current folder
pabot --processes 3 -d tests --listener allure_robotframework:Allure_Report test*.robot
...
34 tests, 34 passed, 0 failed, 0 skipped.
...
Total testing: 6 minutes 36.30 seconds
Elapsed time: 2 minutes 24.37 seconds
allure serve --port 2666 Allure_Report- Test Subfolder
pabot --processes 3 -d tests --listener allure_robotframework:Allure_Report .\DataDrivenTest
...
4 tests, 4 passed, 0 failed, 0 skipped.
...
Total testing: 52.50 seconds
Elapsed time: 54.19 seconds
- test_try_except.robot
- test_try_except2.robot
Sample Try / Except
[tags] try_except
pabot -d tests --processes 2 --listener allure_robotframework:Allure_Report --include try_except .
...
2 tests, 2 passed, 0 failed, 0 skipped.
...
pabot -d tests --processes 3 --listener allure_robotframework:Allure_Report --exclude try_except test*.robot
...
32 tests, 32 passed, 0 failed, 0 skipped.
...
-
Test Setup (Each Test Case)
-
Test Teardown (Each Test Case)
-
Suite Setup (Only Once)
-
Suite Teardown (Only Once)
robot -d tests --listener allure_robotframework:Allure_Report Fixtures\LoginTest.robot
...
Create DB Connection
Login Test Launching Browser
.Executing Login Test
.Closing Browser
Login Test | PASS |
------------------------------------------------------------------------------
User reg Test Launching Browser
.Executing User reg test
.Closing Browser
User reg Test | PASS |
...
------------------------------------------------------------------------------
Close DB Connection
...- https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html
- Alert Should Be Present
- Element Attribute Value Should Be
- Page Should Contain
• Business Elements (Locators) provide UI locators for interaction.
• Common Resources include reusable utilities.
• The Page Objects Specification includes business keywords and references elements in the Locators,
which are then saved in the 'PageObjects' folder.
• Test Cases use Page Objects for structured test cases in folder 'PomTestCases'.
• Data Driven supplies test data for automation.
- PageObjects\HomePage.robot
robot -d tests PageObjects\HomePage.robot
[ ERROR ] Suite 'HomePage' contains no tests or tasks. (Alright)
REM pabot ... --exclude PageObjects\ ...- PomTestCases\FindNewCarsTest.robot
robot -d tests PomTestCases\FindNewCarsTest.robot
robot -d tests -v Brand:BMW PomTestCases\FindNewCarsTest.robot
robot -d tests -v Brand:Kia PomTestCases\FindNewCarsTest.robot
- PomTestCases\FindNewCarsTestDataDriven.robot
...
Test Template Find New Cars Test # Ensure this matches the keyword name
...
*** Test Cases ***
Find New Cars Data Driven Test ${browser} ${brandname} ${carheading}
*** Keywords ***
Find New Cars Test
[Arguments] ${browser} ${brandname} ${carheading}
launching browser ${TestSiteUrl} ${browser}
...
robot -d tests PomTestCases\FindNewCarsTestDataDriven.robot
robot -d tests PomTestCases\GetCarNameTest.robot
pabot -d tests --processes 3 --listener allure_robotframework:Allure_Report PomTestCases\.
allure serve --port 2666 Allure_Report
java -jar jenkins.war
...
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
b3554df7bbeb4dabb8be33b4d8839226
This may also be found at: C:\Users\samfi\.jenkins\secrets\initialAdminPassword
...
2025-03-13 11:56:09.548+0000 [id=26] INFO hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running
2025-03-13 11:56:11.838+0000 [id=69] INFO h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
2025-03-13 11:56:11.843+0000 [id=69] INFO hudson.util.Retrier#start: Performed the action check updates server successfully at the attempt #1
type C:\Users\samfi\.jenkins\secrets\initialAdminPassword
-
http://localhost:8080/ => Install Suggested Plugins
-
New Item => RobotFramework Project => Freestyle project => OK
-
Build Steps => Add build step => Execute Windows batch command => Save
cd C:\Users\samfi\PycharmProjects\Robot_Framework
robot -d tests PomTestCases\FindNewCarsTestDataDriven.robot- Dashboard => RobotFramework Project => Build Now
- Dashboard => RobotFramework Project => Last build => Console Output
- Dashboard => Manage Jenkins => Plugins => Available plugins => HTML Publisher => Install
- Dashboard => RobotFramework Project => Configure => Post-build Actions => Add post-build action => Publish HTML reports =>
- HTML directory to archive => C:\Users\samfi\PycharmProjects\Robot_Framework\tests
- Index page[s] => report.html
- Report title => Robot Framework Report => Save => Build Now
java -Dhudson.model.DirectoryBrowserSupport.CSP="" -jar jenkins.war
- Dashboard => RobotFramework Project => Build Now => Robot Framework Report
REM RestAPI sample
java -jar way2automation-restapi.jar
...
2025-03-16 11:11:03.226 INFO 372 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2025-03-16 11:11:03.233 INFO 372 --- [ main] c.w.testapi.TestapiApplication : Started TestapiApplication in 10.902 seconds (JVM running for 12.3)
pip install robotframework-requests
robot -d tests test_api_request.robot
pip install robotframework-databaselibrary
pip install PyMySQLrobot -d tests test_mysql_connection.robot