Package: robotframework-RobotOil
RobotOilRobotOilIntroductionDependenciesInstallationImporting RobotOilImporting into RobotImporting into PythonFeatures and ExamplesSmart BrowserSmart Browser ExampleSmart KeywordsSmart Click ExampleSmart Keywords from PythonConclusionIntroductionRobotOil is a library of quality-of-life features for automated test case development withRobot FrameworkandSeleniumLibrary.Enhancements include the option of persistent browser sessions to assist with debugging your scripts and "Smart" versions of common-use SeleniumLibrary Keywords to make navigating your web application even easier. Additionally, everything within RobotOil may be executed from either a Robot Test Suite OR the execution of a Python file.Grease the gears of your next automation project withRobotOil!DependenciesRequires RobotFramework and SeleniumLibrary.
Use these commands to stay up to date with the latest versions.pip install robotframework -U
pip install robotframework-seleniumlibrary -UInstallationRecommend using pip to install RobotOil.pip install robotframework-RobotOil -UIf usingGitHub, copy the RobotOil folder from the src folder to anywhere in your PATH.
Ideally, to the (your Python library)/Lib/site-packages folder.Importing RobotOilRobotOil and all Keywords within may be executed from either a Robot Test Suite or a Python module.Importing into RobotSimply call RobotOil as Library within your Test Suite or Resource file of choice.*** Settings ***
Library    RobotOilImporting into PythonImport the RobotOil module and class into a Python file.
All RobotOil Keywords/methods may be called from this class.from RobotOil import RobotOil

oil_can = RobotOil()Features and ExamplesSmart BrowserIf you've worked with Selenium, you've likely noticed how every automated test needs to begin with the creation of a new browser session.
Even with debugging tools native to many IDE's, automated test cases with traditional browser sessions can become incredibly time-consuming to maintain when needing to, say, correct step 48 of a 50 step test case but needing to execute steps 1-47 everytime you try a new fix.By contast, Smart Browser sessions provide the option to remain open after a Robot or Python test execution has finished allowing them to be reusable for additonal sessions as long as the browser remains open and no new sessions are created.Smart Browser ExampleCreate a file namedoil_test.robotanywhere on your machine and enter the following code:*** Settings ***
Library           SeleniumLibrary
Library           RobotOil

*** Test Cases ***
Begin Session
    Open Smart Browser    https://phptravels.com/demo    chrome    persistIn a console, run the commandrobot -t "Begin Session" PATH_TO_TEST_SUITE\oil_test.robot.
A chrome browser session is started and the test site is navigated to.
Leave this browseropenbefore beginning the next step.In the sameoil_test.robotTest Suite, add this Test Case:Continue Session
    Use Current Smart Browser
    Maximize Browser WindowRun this Test Case viarobot -t "Continue Session" PATH_TO_TEST_SUITE\oil_test.robot.
If all goes well, you should see the same browser session you opened earlier become maximized.You may continue to send commands to Smart Browser Sessions viaUse Current Smart Browseruntil either closing the browser or
creating a new Smart Browser.When it's actually time to close up the browser and any webdrivers that may be hanging around, simply call theCleanup Smart BrowserKeyword.Smart KeywordsTheSeleniumLibrarypackage features a wide variety of powerful Keywords for interacting with web elements.
Keywords like Click Element, Input Text, and so forth probably make up the bulk of most web automation projects usingRobot Framework.However, these Keywords are often limited when dealing with the unpredictability of page load times and elements appearing asynchronously on a given web page.
These limitations cause unexpected failures and sometimes require complex or time-consuming workarounds.Smart Keywords offer enhanced versions of these SeleniumLibrary Keywords that account for this unpredictability and provide additonal quality-of-life improvements by:Automatically waiting for targeted elements to be visible before attempting to interactAllowing for the "time to wait" to be established per Keyword callBeing accessible from a Python method as well as a Robot Test CaseSmart Click ExampleIn the sameoil_test.robotTest Suite from earlier, copy the following code:Text Retrieval Test
    Open Smart Browser    https://the-internet.herokuapp.com/dynamic_loading/2    chrome
    Maximize Browser Window
    Click Element   css:#start > button
    ${hello_text}    Get Text    css:#finishRun usingrobot -t "Text Retrieval Test" PATH_TO_TEST_SUITE\oil_test.robot.This test ends up failing because the Get Text keyword gives up looking for the #finish id before this element can become available.A typical workaround to this issue might include having to write in aWait For Page to Contain Elementor worse, a call to the dreadedSleepKeyword. Static waits like Sleep and the variability of internet connections and server responses do NOT mix well and having to write out aWait For...Keyword before nearly every test step is a chore.Instead, simple add the wordSmartto theGet Textkeyword so the last line looks like this:${hello_text}    Smart Get Text    css:#finishAnd run the test again. The test passes due toSmart Get Textunderstanding that it has to wait until the "finish" element is visible before attempting to retrieve its text.If you want to ensure that the finish element, or any element you want to interact with using a Smart Keyword, becomes visible within a known time limit, you may simply give thetimeoutparameter a specific argument like so:${hello_text}    Smart Get Text    css:#finish    timeout=120This will makeSmart Get Textwait forup to2 minutes for the finish element to become visible before attempting to click the button.Note: Not all SeleniumLibrary Keywords are available by simply addingSmartas a prefix. If a keyword has not been explicitly added to theSmart Keywordsclass, you may addSmart Keywordto a SeleniumLibrary keyword and receive the same benefits. For example:${hello_text}    Smart Keyword    Get Text    css:#finish    timeout=120With this enhancement, you'll never have to explicitly call anotherSleeporWait For...Keyword in your test cases again!Smart Keywords from PythonOne of RobotFramework's greatest advantages is the ease of creating custom Python libraries and methods and being able to execute these directly from a Robot Test Case.
This is especially useful when needing to write out a more complex set of actions from Python where features like nested for loops, while loops, etc, are available.
To further facilitate this capability, Smart Keywords are also accessible from your extended Python libraries and methods.Create a file namedclick_test.pyanywhere on your machine, copy the following example code, and execute the file:from RobotOil import RobotOil

oil_can = RobotOil()

oil_can.open_smart_browser('https://phptravels.com/', 'chrome', 'persist')
oil_can.browser.maximize_window()
oil_can.smart_click_element('link:Features')
oil_can.smart_click_element('link:Main Features')
oil_can.smart_click_element('link:Demo')To move this functionality back into your established Robot Test Cases, simply wrap this code in a method:from RobotOil import RobotOil

oil_can = RobotOil()

def python_clicking():
    oil_can.open_smart_browser('https://phptravels.com/', 'chrome', 'persist')
    oil_can.browser.maximize_window()
    oil_can.smart_click_element('link:Features')
    oil_can.smart_click_element('link:Main Features')
    oil_can.smart_click_element('link:Demo')And import the file into youroil_test.robotTest Suite:*** Settings ***
Library           SeleniumLibrary
Library           RobotOil
Library           PATH_TO_CLICK_TEXT/click_test.pyFrom there, simply callPython Clickingfrom a Test Case of your choice:*** Test Cases ***
Python Example
    Python ClickingYou may now leverage the already powerful SeleniumLibrary Keywords, with Smart Keyword enhancements, DIRECTLY from Python, and back into your Robot Test Cases!ConclusionI hope you enjoy the additional capabilities and ease-of-use that RobotOil brings to automated web testing with RobotFramework.Please don't hesitate to reach out with questions or suggestions onGitHub