Skip to content

Commit

Permalink
refactoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jmateusribeiro committed Jun 2, 2024
1 parent 39c79a3 commit 5efa752
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 75 deletions.
2 changes: 1 addition & 1 deletion resources/config/config.resource
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ${REGISTRATION_ENDPOINT} api/register
*** Keywords ***
Load Environment Variables
[Documentation] Load environment variables from a .env file
File Should Exist ${PROJECT_DIR}/credentials.env
File Should Exist ${PROJECT_DIR}/credentials.env
... msg=The file 'credentials.env' was not found in the root dir of the project

Load Dotenv ${PROJECT_DIR}/credentials.env
3 changes: 2 additions & 1 deletion resources/pages/base_page.resource
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Documentation Base page
Library Collections
Library SeleniumLibrary
Resource resources/config/config.resource
Resource ../config/config.resource


*** Keywords ***
Expand All @@ -15,4 +15,5 @@ Open Browser Webpage
Maximize Browser Window

Default Teardown
[Documentation] keyword to close all browsers
Close All Browsers
18 changes: 10 additions & 8 deletions resources/pages/data_tables_page.resource
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ Resource base_page.resource


*** Variables ***
${data_tables_title} Data Tables
${email_table_1} //table[@id='table1']//tr/td[3]
${email_table_2} //table[@id='table2']//td[@class='email']
${DATA_TABLES_TITLE} Data Tables
${EMAIL_TABLE_1} //table[@id='table1']//tr/td[3]
${EMAIL_TABLE_2} //table[@id='table2']//td[@class='email']


*** Keywords ***
Go Direct To Data Tables Page
[Documentation] Opens the data tables page directly.
Open Browser Webpage ${HEROKU_TABLES_PAGE} ${BROWSER}
Wait Until Page Contains ${data_tables_title}
Wait Until Page Contains ${DATA_TABLES_TITLE}

Verify ${expectedEmails} From Table ${table}

[Documentation] Verifies the emails from a specific table.
Wait Until Page Contains ${table} 2 Available tables: 'Example 1'; 'Example 2'

${savedEmails}= Save Emails From Table ${table}

Log Lista de emails: ${savedEmails}
Lists Should Be Equal ${savedEmails} ${expectedEmails} Incorrect email list; expected emails: @{expectedEmails} ignore_order=True
Lists Should Be Equal ${savedEmails} ${expectedEmails}
... Incorrect email list; expected emails: @{expectedEmails} ignore_order=True
Capture Page Screenshot

Save Emails From Table
Expand All @@ -32,9 +34,9 @@ Save Emails From Table
@{savedEmails}= Create List

IF $table == 'Example 1'
${elements}= Get WebElements ${email_table_1}
${elements}= Get WebElements ${EMAIL_TABLE_1}
ELSE IF $table == 'Example 2'
${elements}= Get WebElements ${email_table_2}
${elements}= Get WebElements ${EMAIL_TABLE_2}
END

FOR ${element} IN @{elements}
Expand Down
20 changes: 11 additions & 9 deletions resources/pages/the_internet_homepage.resource
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ Resource base_page.resource


*** Variables ***
${page_title} The Internet
${page_intro_text} Welcome to the-internet
${data_tables_function} //a[text()='Sortable Data Tables']
${PAGE_TITLE} The Internet
${PAGE_INTRO_TITLE} Welcome to the-internet
${DATA_TABLES_FUNCTION} //a[text()='Sortable Data Tables']


*** Keywords ***
Open The Internet Homepage
Open The Heroku Homepage
[Documentation] Opens the homepage of the Heroku.
Open Browser Webpage ${HEROKU_HOMEPAGE} ${BROWSER}
Wait Until Page Contains ${page_intro_text}
Title Should Be ${page_title} Page title should be: ${page_title}
Wait Until Page Contains ${PAGE_INTRO_TITLE}
Title Should Be ${PAGE_TITLE} Page title should be: ${PAGE_TITLE}

Naviagte To Data Tables Page
Wait Until Element Is Enabled ${data_tables_function}
Click Element ${data_tables_function}
Navigate To Data Tables Page
[Documentation] Navigates to the data tables page and waits until the element is enabled.
Wait Until Element Is Enabled ${DATA_TABLES_FUNCTION}
Click Element ${DATA_TABLES_FUNCTION}
14 changes: 12 additions & 2 deletions resources/services/api_base.resource
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ Documentation base api
Library Collections
Library RequestsLibrary
Resource resources/config/config.resource
Resource ../config/config.resource


*** Variables ***
&{CONTENT_TYPE} Content-Type=application/json


*** Keywords ***
Run Post Request
[Documentation] Runs a POST request to the specified URL with the provided body data.
[Arguments] ${host} ${url} ${body}
Create Session session ${host}
${resp}= POST On Session session ${url} data=${body} expected_status=any headers=${contentType} verify=${False}
${resp}= POST On Session session
... ${url}
... data=${body}
... expected_status=any
... headers=${CONTENT_TYPE}
... verify=${False}
Status Should Be 200 ${resp} ${resp.reason}
Log resposta: ${resp.json()}
RETURN ${resp.json()}
15 changes: 6 additions & 9 deletions resources/services/regres_registration_API.resource
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,23 @@ Documentation registration api
Resource api_base.resource


*** Variables ***
&{contentType} Content-Type=application/json


*** Keywords ***
Email And Password Are Definied As ${email} And ${password}
Email And Password Are Defined As ${email} And ${password}
[Documentation] Keyword to generate body with email and password
${body}= Set Variable {"email": "${email}", "password": "${password}"}
Set Test Variable ${email} ${email}
Set Test Variable ${body} ${body}
Set Test Variable ${EMAIL}
Set Test Variable ${BODY}

Registration Is Executed
[Documentation] Keyword to generate body with email and password
${resp}= Run Post Request ${API_HOST} ${REGISTRATION_ENDPOINT} ${body}
Set Test Variable ${resp} ${resp}
Set Test Variable ${RESP}

The Correct Token Is Returned
[Documentation] Keyword to validate login token
Set Log Level NONE
${token}= Get Environment Variable ${email}
Set Log Level INFO
Should Be Equal ${resp}[token] ${token} Token returned '${resp}[token]' isn't the expected values=${False}
Should Be Equal ${resp}[token] ${token}
... Token returned '${resp}[token]' isn't the expected values=${False}
21 changes: 12 additions & 9 deletions tests/API_BDD_with_csv.robot
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
*** Settings ***
Documentation Robot API BDD with csv test example
Documentation Robot API BDD with CSV test example
Resource resources/services/regres_registration_API.resource
Resource ../resources/services/regres_registration_API.resource

Library DataDriver file=data_files\\users_data.csv dialect=unix
Suite Setup Load Environment Variables
Library DataDriver file=data_files\\users_data.csv dialect=unix
Suite Setup Load Environment Variables


*** Test Cases ***
Scenario: Successful Registration With ${email}
[Template] Scenario Outline: Successful Registration
[Documentation] Tests successful registration with different email addresses from a CSV file.
[Template] Scenario Outline: Successful Registration
Log Test Executed from csv


*** Keywords ***
Scenario Outline: Successful Registration
[Arguments] ${email} ${password}
Given email and password are definied as ${email} and ${password}
When registration is executed
Then the correct token is returned
[Documentation] Registers a user with the given email and password, then verifies the correct token is returned.
[Arguments] ${email} ${password}
Given Email And Password Are Defined As ${email} And ${password}
When Registration Is Executed
Then The Correct Token Is Returned
18 changes: 10 additions & 8 deletions tests/API_BDD_with_table.robot
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
*** Settings ***
Documentation Robot API bdd with example table test example
Documentation Robot API BDD with example table test example
Resource resources/services/regres_registration_API.resource
Suite Setup Load Environment Variables
Resource ../resources/services/regres_registration_API.resource
Suite Setup Load Environment Variables


*** Test Cases ***
Feature: Registration
[Template] Scenario Outline: Successful Registration
[Documentation] Tests the registration feature with different email and password combinations.
[Template] Scenario Outline: Successful Registration
eve.holt@reqres.in pistol
michael.lawson@reqres.in xpto
lindsay.ferguson@reqres.in xpto


*** Keywords ***
Scenario Outline: Successful Registration
[Arguments] ${email} ${password}
Given email and password are definied as ${email} and ${password}
When registration is executed
Then the correct token is returned
[Documentation] Registers a user with the given email and password, then verifies the correct token is returned.
[Arguments] ${email} ${password}
Given Email And Password Are Defined As ${email} And ${password}
When Registration Is Executed
Then The Correct Token Is Returned
44 changes: 30 additions & 14 deletions tests/API_keyword_driven.robot
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
*** Settings ***
Documentation Robot API keyword driven test example
Documentation Robot API keyword driven test example
Resource resources/services/regres_registration_API.resource
Suite Setup Load Environment Variables
Resource ../resources/services/regres_registration_API.resource

Suite Setup Load Environment Variables


*** Variables ***
${EMAIL_EVE} eve.holt@reqres.in
${PASSWORD_EVE} pistol
${EMAIL_MICHAEL} michael.lawson@reqres.in
${PASSWORD_MICHAEL} xpto
${EMAIL_LINDSAY} lindsay.ferguson@reqres.in
${PASSWORD_LINDSAY} xpto


*** Test Cases ***
Successful Registration
email and password are definied as eve.holt@reqres.in and pistol
registration is executed
the correct token is returned
Successful Registration As Eve
[Documentation] Registers a user with email eve.holt@reqres.in and password pistol,
... then verifies the correct token is returned.
Email And Password Are Defined As ${EMAIL_EVE} And ${PASSWORD_EVE}
Registration Is Executed
The Correct Token Is Returned

Successful Registration
email and password are definied as michael.lawson@reqres.in and xpto
Successful Registration As Michael
[Documentation] Registers a user with email michael.lawson@reqres.in and password xpto,
... then verifies the correct token is returned.
Email And Password Are Defined As ${EMAIL_MICHAEL} And ${PASSWORD_MICHAEL}
Registration Is Executed
the correct token is returned
The Correct Token Is Returned

Successful Registration
email and password are definied as lindsay.ferguson@reqres.in and xpto
registration is executed
the correct token is returned
Successful Registration As Lindsay
[Documentation] Registers a user with email lindsay.ferguson@reqres.in and password xpto,
... then verifies the correct token is returned.
Email And Password Are Defined As ${EMAIL_LINDSAY} And ${PASSWORD_LINDSAY}
Registration Is Executed
The Correct Token Is Returned
13 changes: 7 additions & 6 deletions tests/web_test_direct_url.robot
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
*** Settings ***
Documentation Robot web test examples with direct url
Resource resources/pages/data_tables_page.resource
Test Teardown Default Teardown
Resource ../resources/pages/data_tables_page.resource
Test Teardown Default Teardown


*** Variables ***
@{emails}= tconway@earthlink.net jsmith@gmail.com fbach@yahoo.com jdoe@hotmail.com
@{EMAILS} tconway@earthlink.net jsmith@gmail.com fbach@yahoo.com jdoe@hotmail.com


*** Test Cases ***
Verify Emails From Table 'Example 1'
[Documentation] Verifies that EMAILS from the table 'Example 1' match the expected list.
Go Direct To Data Tables Page
Verify ${emails} From Table Example 1
Verify ${EMAILS} From Table Example 1

Verify Emails From Table 'Example 2'
[Documentation] Verifies that EMAILS from the table 'Example 2' match the expected list.
Go Direct To Data Tables Page
Verify ${emails} From Table Example 2
Verify ${EMAILS} From Table Example 2
18 changes: 10 additions & 8 deletions tests/web_test_navigate_menus.robot
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
*** Settings ***
Documentation Robot web test examples with menu navegation
Resource resources/pages/data_tables_page.resource
Resource resources/pages/the_internet_homepage.resource
Test Teardown default teardown
Resource ../resources/pages/data_tables_page.resource
Resource ../resources/pages/the_internet_homepage.resource
Test Teardown Default Teardown


*** Variables ***
@{emails}= tconway@earthlink.net jsmith@gmail.com fbach@yahoo.com jdoe@hotmail.com
@{EMAILS}= tconway@earthlink.net jsmith@gmail.com fbach@yahoo.com jdoe@hotmail.com


*** Test Cases ***
Verify Emails From Table 'Example 1'
Open The Internet Homepage
Naviagte To Data Tables Page
[Documentation] Verifies that emails from the table 'Example 1' match the expected list.
Open The Heroku Homepage
Navigate To Data Tables Page
Verify ${emails} From Table Example 1

Verify Emails From Table 'Example 2'
Open The Internet Homepage
Naviagte To Data Tables Page
[Documentation] Verifies that emails from the table 'Example 2' match the expected list.
Open The Heroku Homepage
Navigate To Data Tables Page
Verify ${emails} From Table Example 2

0 comments on commit 5efa752

Please sign in to comment.