Creating Robot Framework file:
# After doing all the setup, our PyCharm will be ready to create the robot file.
# Every robot test case file has the extension '.robot'.
# Every robot test case file has the extension '.robot'.
- Steps for creating a robot file:
> Right-Click on your Project/Package/Directory(based on where we need to create a robot file), select New then click on File.> Give the name of the robot file with an extension .robot> Example: form.robot (filename.robot)
Components of Robot Framework:
Robot Framework scripts are mainly divided into four sections/components. By this, we can systematically arrange our script. The starting and ending names of every component must be *** (3 asterisks).
1. *** Settings ***2. *** Variables ***3. *** Test Cases ***4. *** Keywords ***
*** Settings ***
In this Settings section, we can add libraries and resources.
*** Variables ***
In this Variables section, we will define variables that are commonly used in test cases.
*** Test Cases ***
In this Test Cases section, we write multiple test cases with test scripts/keywords.
*** Keywords ***
In this Keywords section, we create user define keywords.
------- *** -------
Example:
User story:
1. As a user, I want to access the Facebook login page using the Chrome browser.2. I will input my username and password as abcd@gmail.com, followed by 123456.3. I will click on the Login Button.4. And then Close the browser.
Programs:
1. *** Settings ***
2. Library SeleniumLibrary
3.
4. *** Variables ***
5. ${username} abcd@gmail.com
6. ${password} 123456
7.
8. *** Test Cases ***
9. LoginTest
10. Open Browser https://www.facebook.com/ Chrome
11. loginToApplication
12. Close Browser
13.
14. *** Keywords ***
15. loginToApplication
16. Input Text xpath://input[@id='email'] ${username}
17. Input Text xpath://input[@id='pass'] ${password}
18. Click Button Log in
2. Library SeleniumLibrary
3.
4. *** Variables ***
5. ${username} abcd@gmail.com
6. ${password} 123456
7.
8. *** Test Cases ***
9. LoginTest
10. Open Browser https://www.facebook.com/ Chrome
11. loginToApplication
12. Close Browser
13.
14. *** Keywords ***
15. loginToApplication
16. Input Text xpath://input[@id='email'] ${username}
17. Input Text xpath://input[@id='pass'] ${password}
18. Click Button Log in
We will learn all the above keywords in the coming sessions, now just try to understand the program.
# In the *** Settings *** section, we imported a library called SeleniumLibrary. SeleniumLibrary contains a lot of keywords in the above programme we use some of the keywords supported by this library - Open Browser, Input Text, Click Button, Close Browser.# In the *** Variable *** section, we define 2 variables.
- username = abcd@gmail.com- password = 123456
# In the *** Keywords *** section, we created a user define keyword called loginToApplication. and that keyword has some actions to input a username and password and then click the login button.
- Here instead of giving username and password values directly, we give variables names with are declared in the *** Variables *** section.- By using that variable names we can get their values here.
# In the *** Test Cases *** section, we created a test case with the name LoginTest.
- Here first it will open the Chrome browser then it will navigate to the Facebook login page.- Then it calls the loginToApplication keyword. Whatever action is inside that keyword they will be run here.- Finally, Browser will Close.
No comments:
Post a Comment