0% found this document useful (0 votes)
4 views

Robot Framework

Robot Framework is an open-source automation framework for test automation and RPA, utilizing a keyword-driven approach. It supports various libraries for web, API, and database testing, and allows for detailed logging and reporting. The framework includes features like test suites, custom keywords, setup and teardown processes, and integration with CI tools like Jenkins.

Uploaded by

devendergoude6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Robot Framework

Robot Framework is an open-source automation framework for test automation and RPA, utilizing a keyword-driven approach. It supports various libraries for web, API, and database testing, and allows for detailed logging and reporting. The framework includes features like test suites, custom keywords, setup and teardown processes, and integration with CI tools like Jenkins.

Uploaded by

devendergoude6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Robot Framework

What is Robot Framework?

Robot Framework is an open-source automation framework used for test


automation and RPA (Robotic Process Automation). It uses a keyword-driven
testing approach and supports various test libraries to perform automation for
web, APIs, databases, files, etc.

What are the features of Robot Framework?

 Open-source and platform-independent.


 Keyword-driven testing.
 Supports tabular test data syntax.
 Extensible with Python and Java libraries.
 Built-in support for test case tagging.
 Generates detailed HTML logs and reports.

How do you install Robot Framework?

You can install Robot Framework using pip

pip install robotframework

What are test suites and test cases in Robot Framework?

 Test Suite: A collection of test cases grouped in a single .robot file or


multiple .robot files.
 Test Case: An individual test that verifies a specific functionality.

Explain the syntax structure of a Robot Framework test case.

The syntax is tabular and uses sections like:

 Settings: Includes libraries, resource files, and variables.


 Test Cases: Defines the test cases.
 Keywords: User-defined keywords.
 Variables: Defines reusable variables.
*** Settings ***

Library SeleniumLibrary

*** Test Cases ***

Login Test

Open Browser https://example.com Chrome

Input Text username_field admin

Input Text password_field admin123

Click Button login_button

Close Browser

What is a keyword in Robot Framework?

A keyword is a reusable block of code that performs a specific operation.


Keywords can be built-in (provided by libraries), custom (user-defined), or library-
specific.

What are the different variable types supported by Robot Framework?

 Scalar Variables: ${variable} (e.g., ${name} = John)


 List Variables: @{variable} (e.g., @{names} = John Jane Doe)
 Dictionary Variables: &{variable} (e.g., &{person} = name=John
age=30)

How do you execute a Robot Framework test suite?

Using the robot command:

robot test_suite.robot

You can also specify tags:

robot --include TAG_NAME test_suite.robot


How do you debug a Robot Framework test case?

 Use the --loglevel DEBUG option during execution.


 Add Log To Console or Log keywords for debugging messages.
 Use breakpoints by adding BuiltIn.Pause.

How to Count & Extract Link Texts in Robot Framework?

*** Settings ***

Library SeleniumLibrary

*** Test Cases ***

Extract All Link Texts

Open Browser https://example.com chrome

${count} = Get Element Count xpath=//a

FOR ${i} IN RANGE 1 ${count+1}

${link_text} = Get Text xpath=(//a)[${i}]

Log Link ${i}: ${link_text}

END

Close Browser

Extract All Link URLs

*** Settings ***

Library SeleniumLibrary

*** Test Cases ***

Extract All Link URLs

Open Browser https://example.com chrome


${count} = Get Element Count xpath=//a

FOR ${i} IN RANGE 1 ${count+1}

${link_url} = Get Element Attribute xpath=(//a)[${i}] href

Log Link ${i} URL: ${link_url}

END

Close Browser

How do you handle APIs in Robot Framework?

By using the RequestsLibrary.

*** Settings ***

Library RequestsLibrary

*** Test Cases ***

API Test

Create Session my_session https://jsonplaceholder.typicode.com

${response}= Get Request my_session /posts/1

Should Be Equal ${response.status_code} 200

Log ${response.json()}

What is a Setup and Teardown in Robot Framework?

Setup: The Setup is used to define tasks that need to be performed before a test
case, test suite, or keyword is executed.

Examples of Setup Tasks:

 Establishing a database connection.


 Opening a browser and navigating to a specific URL.
 Initializing variables or test data.
 Starting a server or application.

Teardown The Teardown is used to define tasks that need to be performed after
a test case, test suite, or keyword is executed, regardless of whether the test
passes or fails.

Examples of Teardown Tasks:

 Closing a database connection.


 Closing a browser or cleaning up cookies.
 Deleting temporary test data.
 Stopping a server or application.

Types of Setup and Teardown

1. Test Setup and Teardown:


o Defined at the test case level.
o Runs before and after each individual test case.

2. Suite Setup and Teardown:


o Defined at the suite level.
o Runs once before the entire test suite starts and after the entire test
suite completes.

3. Keyword Setup and Teardown:


o Runs before and after a keyword.

*** Settings ***

Suite Setup Open Browser

Suite Teardown Close Browser

Library SeleniumLibrary

*** Variables ***


${BROWSER} Chrome

${URL} https://example.com

*** Test Cases ***

Verify Page Title

Title Should Be Example Domain

Search Functionality

Input Text id:search Robot Framework

Click Button id:searchButton

Page Should Contain Results for Robot Framework

*** Keywords ***

Open Browser

Open Browser ${URL} ${BROWSER}

Maximize Browser Window

Close Browser

Close All Browsers

How do you integrate Jenkins with Robot Framework?

 Install the Robot Framework plugin in Jenkins.


 Add the command to execute Robot tests in the Jenkins job configuration.
 Use the post-build step to publish Robot Framework test results.

How do you create custom keywords in Robot Framework?

Custom keywords can be defined in the *** Keywords *** section or a


Python library.

*** Keywords ***


Login To Application

Input Text username_field ${USERNAME}

Input Text password_field ${PASSWORD}

Click Button login_button

What are tags, and how are they useful?

Tags are labels assigned to test cases to organize and filter them during execution.

*** Test Cases ***

Login Test

[Tags] smoke

Perform Login

Run specific tagged tests using:

robot --include smoke tests.robot

What are some commonly used Robot Framework libraries?

 SeleniumLibrary: For web automation.


 RequestsLibrary: For API testing.
 StringLibrary: For string manipulation.
 OperatingSystem: For file and system operations.
 BuiltIn: For built-in functionalities.

How do you install additional libraries for Robot Framework, such as


SeleniumLibrary?

You can install libraries using pip

pip install robotframework-seleniumlibrary

What is the difference between Setup and Teardown?

 Setup: Tasks executed before a test case, suite, or keyword starts.


 Teardown: Cleanup tasks executed after a test case, suite, or keyword finishes.

*** Test Cases ***

My Test Case

[Setup] Open Browser https://example.com Chrome

Perform Test Steps

[Teardown] Close Browser

How can you skip a test case in Robot Framework?

Use the Skip Execution keyword from the BuiltIn library:

*** Test Cases ***

Skipped Test

Skip Execution This test is skipped for demonstration.

How do you execute multiple test cases from different suites?

You can pass multiple test suite paths in the robot command

robot testsuite1.robot testsuite2.robot

What is the purpose of the --dryrun option?

The --dryrun option validates the test suite syntax without executing the test
cases. It ensures the test cases are written correctly.

robot --dryrun testsuite.robot

How can you speed up test execution in Robot Framework?

 Use parallel execution with tools like Pabot.


 Avoid unnecessary browser restarts.
 Optimize Selenium locators.
 Use headless browsers where possible.
pabot --processes 4 tests

What is a resource file in Robot Framework?

A resource file is a reusable file that stores keywords, variables, or settings. It is


imported using the Resource keyword.

Example (resources.robot):

*** Variables ***

${URL} https://example.com

*** Keywords ***

Login To Application

Input Text username_field admin

Input Text password_field password

Click Button login_button

Usage in test file:

*** Settings ***

Resource resources.robot

How do you pass arguments to a keyword?

Use the [Arguments] setting in the keyword definition.

*** Keywords ***

Add Numbers

[Arguments] ${a} ${b}

${sum}= Evaluate ${a} + ${b}

Log The sum is ${sum}


Usage in test case:

*** Test Cases ***

Test Addition

Add Numbers 5 10

How can you reuse SeleniumLibrary keywords?

Import SeleniumLibrary and directly call its keywords in test cases. For
example:

*** Test Cases ***

Verify Page Title

Open Browser https://example.com Chrome

Title Should Be Example Domain

Close Browser

How do you handle errors in Robot Framework?

 Use Run Keyword And Expect Error to catch specific errors.


 Use Run Keyword And Return Status to continue execution even if a
keyword fails.

*** Test Cases ***

Handle Error

${status}= Run Keyword And Return Status Click Button


nonexistent_button

Run Keyword If not ${status} Log Button not found, continuing execution

How do you take a screenshot in Robot Framework?

Use the Capture Page Screenshot keyword from SeleniumLibrary:


Capture Page Screenshot

What is the significance of the output.xml file?

The output.xml file is a detailed log of the test execution. It is used to


generate the HTML report and log files.

How can you integrate Robot Framework with a database?

Use the DatabaseLibrary for database operations.

*** Settings ***

Library DatabaseLibrary

*** Test Cases ***

Database Query Test

Connect To Database pymysql db_name username password


host=127.0.0.1

${result}= Query SELECT * FROM users WHERE id=1

Log ${result}

Disconnect From Database

How do you handle dynamic element locators in SeleniumLibrary?

Use variables to create dynamic XPath or CSS locators.

*** Variables ***

${DYNAMIC_BUTTON} //button[text()='${BUTTON_TEXT}']

*** Test Cases ***

Click Dynamic Button

${locator}= Set Variable ${DYNAMIC_BUTTON}


Click Element ${locator.replace('${BUTTON_TEXT}', 'Submit')}

How do you generate custom reports in Robot Framework?

 Use the --listener option to hook into execution and generate reports.
 Use external tools like Robot Framework ReportPortal for advanced
reporting.

robot --listener MyListener.py tests.robot

How do you integrate Robot Framework with version control systems like Git?

 Store test suites in the repository.


 Use Git for version control.
 Configure Jenkins or any CI tool to fetch the latest code from the repository and
execute the tests.

How can you run Robot Framework tests in Docker?

 Create a Docker image with Robot Framework and necessary libraries.


 Mount the test files into the container.
 Run tests using a command like:

docker run -v $(pwd):/tests robotframework/rfdocker robot


/tests/testsuite.robot

How can you use tags for test prioritization in CI pipelines?

Tags help to categorize tests into smoke, regression, critical, etc. CI


pipelines can execute specific tags based on priority:

robot --include smoke tests.robot

You might also like