Package: testproject-robot-library
TestProject Library for the Robot FrameworkWhat is the Robot frameworkRobot Framework is a generic open source automation framework. It can be used for test automation and robotic process automation (RPA).Robot Framework has easy syntax, utilizing human-readable keywords.Its capabilities can be extended by libraries implemented with Python or Java.The framework has a rich ecosystem around it, consisting of libraries and tools that are developed as separate projects.Why use the TestProject Library For RobotTestProject offers a set of tools for creating end-to-end Tests.TestProject Agent handles the deployment and configuration of Selenium/Appium.Keeps you up to date with the latest stable versions of Selenium/Appium drivers.Cloud team collaboration and automatic test reports (HTML/PDF/JSON).Scriptless test recorder allows creating and running tests without a single line of code.Code extract feature, which allows you to generate Selenium/Appium code to from your scripless tests.By integrating this library with your Robot tests, you can enjoy all these advantagesas well as fully automated reports (with screenshots) hosted free on the TestProject platform.Combining the TestProject Library with Robot is as simple as using the Selenium Library.It's implementing the same syntax, replacing only the "Open Browser" keyword.PrerequisitesBefore starting, please make sure to complete the following:Login to or create a new (FREE) TestProject Account:https://testproject.io/Download and Install the TestProject Agent.Register the Agent, and get your developer token from here:https://app.testproject.io/#/integrations/sdkInstall the Robot Framework:pip3 install robotframeworkOr following the installation instructionshere.Install the TestProject Library for Robot:pip3 install testproject-robot-libraryCreate a new test using the TestProject Library for RobotNow we will create a simple Robot test with two different "Login" flows.The first will be a valid flow and the second will use an incorrect password.First we need to create a new Robot test file. Let's call this fileMyRobotTest.robotSince we're going to use the TestProject Library for Robot, we must declare it inside the test:***Settings***LibraryTestProjectLibraryOnce the TestProject Library for Robot is declared, we can use its full functionality.Next we create aSuite Setupsection for initializing the TestProject Driver:SuiteSetupInitTestProject***Keywords***InitTestProjectInitTestprojectDriverchromejob_name=TestProjectRobotOpenBrowserhttps://example.testproject.io/web/In this snippet, we declare a custom Keyword namedInitTestProjectwhich creates a new sessionwith the TestProject Agent, requesting to open a Selenium session on a Chrome browser.Under the*** Keywords ***section we can put all of ourcustom keywords.Init TestProject Driveris the most important part of the TestProject Library for Robot.It communicates with the TestProject Agent and passed any Desired capabilities, browser type, timeouts and additional data that is required by the TestProject Agent.This method replaces theCreate WebdriverandOpen Browserkeywords, and is the only difference between the SeleniumLibrary and the TestProject Library for Robot.Since the TestProject Library for Robot was created as a wrapper for the SeleniumLibrary, you can simplytake your existing Robot tests, replace the import of theSeleniumLibrarywithTestProjectLibrary,call theInit TestProject Driverkeyword and you are good to go!The follow Selenium test:LibrarySeleniumLibraryOpenBrowserbrowser=Chromeurl=https://example.testproject.io/web/CreateWebdriverdriver_name=ChromeChanges to:LibraryTestProjectLibraryInitTestprojectDriverbrowser=Chromeurl=https://example.testproject.io/web/That's it!New Test Suite Using the TestProject Library for RobotIn this section, we will create a simple test suite with 4 tests:Login with an incorrect passwordLogin with a correct passwordFilling in a form with some detailsSubmitting the formThe suite is built to run on TestProject's example website:https://example.testproject.io/webHere is the complete Robot test:***Settings***LibraryTestProjectLibrarySuiteSetupInitSessionSuiteTeardownCloseSession***TestCases***SetSession${previouskw}=RegisterKeywordToRunOnFailureNoneLoginWithIncorrectPasswordBaseLogin${INCORRECT_PASSWORD}LoginWithCorrectPasswordBaseLogin${CORRECT_PASSWORD}FillFormSelectFromListByLabelcss:#country    AustraliaFOR${input}IN@{INPUT_ELEMENTS}InputText${input}${INPUT_VALUES}[${INDEX}]${INDEX}=Evaluate${INDEX}+1ENDStaticSleepSubmitFormClickButtoncss:#saveClickButtoncss:#logout***Keywords***InitSession${options}=HeadlessChromeInitTestprojectDriverchromejob_name=TestProjectRoboturl=https://example.testproject.io/web/desired_capabilities=${options}CloseSessionCloseAllBrowsersEquals[Arguments]${x}${y}ShouldBeEqualAsStrings${x}${y}ClearFieldsClearElementTextcss:#nameClearElementTextcss:#passwordHeadlessChrome${chrome_options}=Evaluatesys.modules['selenium.webdriver'].ChromeOptions()sys,selenium.webdriverCallMethod${chrome_options}add_argumentheadlessCallMethod${chrome_options}add_argumentdisable-gpu[Return]${chrome_options}BaseLogin[Arguments]${input_password}PressKeyscss:#name                       ${EMAIL}InputTextcss:#password                   ${input_password}${password}=GetValuecss:#password${result}=RunKeywordAndReturnStatusEquals${password}${CORRECT_PASSWORD}RunKeywordIf"${result}"=="True"RunKeywordsTrue...ELSEClearFieldsRunKeywordsTrueClickButtoncss:#loginSleep3sStaticSleepSleep3s***Variables***${EMAIL}test@testproject.io${INCORRECT_PASSWORD}67890${CORRECT_PASSWORD}12345${INDEX}0${CAPABILITIES}${EMPTY.join(${_tmp})}@{INPUT_ELEMENTS}css:#address    css:#email    css:#phone@{INPUT_VALUES}Melbournetest@test.io7521234545@{_tmp}...browserName:chrome,...version:86,...name:RobotFrameworkTestUnderstanding the Test Suite StructureIn the*** Test Cases ***section we declare our test cases and their steps/keywords.***TestCases***SetSession${previouskw}=RegisterKeywordToRunOnFailureNoneLoginWithIncorrectPasswordBaseLogin${INCORRECT_PASSWORD}LoginWithCorrectPasswordBaseLogin${CORRECT_PASSWORD}The first command sets the keyword which should run on Failure toNone. This means that no keyword will be executed if a step fails.It can be set to any keyword of your choice, by default it is set to take a screenshot.Next we declare two test cases with the namesLogin With Incorrect PasswordandLogin With Correct Password.Both tests have a single Custom Keyword step calledBase Loginwhich takes a password as an argument, attempts to login and validates the result.TheBase Logindeclarated in the*** Keywords ***section:BaseLogin[Arguments]${input_password}PressKeyscss:#name                       ${EMAIL}InputTextcss:#password                   ${input_password}${password}=GetValuecss:#password${result}=RunKeywordAndReturnStatusEquals${password}${CORRECT_PASSWORD}RunKeywordIf"${result}"=="True"RunKeywordsTrue...ELSEClearFieldsIf the login fails, we execute another custom Keyword,Clear Fields, which is also defined in the*** Keywords ***section:ClearFieldsClearElementTextcss:#nameClearElementTextcss:#passwordIf the password was correct, we run theRun Keywords Truekeyword to finilize the login process:RunKeywordsTrueClickButtoncss:#loginSleep3sNext, we fill in the form fields, click on Submit and Logout:FillFormSelectFromListByLabelcss:#country    AustraliaFOR${input}IN@{INPUT_ELEMENTS}InputText${input}${INPUT_VALUES}[${INDEX}]${INDEX}=Evaluate${INDEX}+1ENDStaticSleepSubmitFormClickButtoncss:#saveClickButtoncss:#logoutThis also shows how to implement a simple for loop with an Index increment in Robot framework.Init TestProject DriverThis is the entrypoint of the TestProject Library for Robot.This method instructs the TestProject Agent on how to start and execute our test.It's possible run Regular or Headless browsers, for example, using the Desired Capabilities.The method is defined with the following arguments:@keyworddefinit_testproject_driver(self,browser:str="firefox",url:Optional[str]=None,project_name:Optional[str]="TestProject Robot",job_name:Optional[str]="Robot Job",desired_capabilities:Union[str,dict,None]=None,disable_reports:Optional[bool]=False,dev_token:Optional[str]=os.environ["TP_DEV_TOKEN"],):browser: The name of the browser for the session.url: The initial URL to navigate to.project_name: The project name where the reports of the Jobs will show.job_name: The job name which all the tests will appear under.desired_capabilities: The capabilities to supply to the driver, for example to run on Headless chrome you can do the following:\Additional information about supported capabilities can be foundHere.disable_reports- If set to True, no reports will be generated and sent to the TestProject platform.dev_token- The development token, which by default is read from the environment variableTP_DEV_TOKEN.you can get your token at:https://app.testproject.io/#/integrations/sdk.You can set the driver to be a generic driver as well by passing "generic" in the browser argument.