Skip to main content

The extension enables easy execution of pytest tests within the Robot Framework environment.

Project description

pytest-in-robotframework

pytest-in-robotframework enables the running of pytest within the Robot Framework, allowing users to leverage the advantages of both frameworks.

To achieve this integration, simply add the decorator '@pytest_execute' above all the PyTest fixtures within your Python tests/keywords in Python libraries.

At present, this code serves as a proof of concept but is alrady usable.

Pytest's console logs are captured as informational messages in Robot Framework logs. If any test in pytest fails, the entire keyword in Robot Framework fails.

It works with functions and methods too, as long as they follow the naming conventions required by pytest.

Example

Robot Framework file:

#The Example of usage  - suite_name.robot file

*** Settings ***
Documentation     Proof of Concept integration pytest under the hood of Robot Framework
Library  TestExperiment.py


*** Test Cases ***
Login User with Password
    Open Web Page  https://www.saucedemo.com/
    Test Login As  user  password  #the user and password is here only for Robot Framework checks (is not used)

Python File:

#The Example of usage  - TestExperiment.py file
from selenium import webdriver
from selenium.webdriver.common.by import By
import time

from pytest_in_robotframework import pytest_execute #EXAMPLE USAGE - must import!



class TestExperiment: #EXAMPLE USAGE - must have this name!
    options = webdriver.ChromeOptions()
    options.add_experimental_option('excludeSwitches', ['enable-logging'])
    driver = webdriver.Chrome(options=options)

    def open_web_page(self,page): 
        self.driver.get(page)

    @pytest_execute #EXAMPLE USAGE - this is the new decorator that execute the keyword in PyTest instead Robot Framework!
    #@pytest.mark.parametrize("user,password", [("standard_user", "secret_sauce"),("locked_out_user", "secret_sauce"),("problem_user", "secret_sauce")]) #failing example
    @pytest.mark.parametrize("user,password", [("standard_user", "secret_sauce"),("problem_user", "secret_sauce")]) #passing example
    def test_login_as(self,user,password):
        #assert False
        print("vykonal jsem prvni radek test_login_as...")
        time.sleep(1)
        username = self.driver.find_element(By.ID,'user-name')
        username.clear()
        username.send_keys(user)
        my_password = self.driver.find_element(By.ID,'password')
        my_password.clear()
        my_password.send_keys(password)
        time.sleep(1)
        login_button = self.driver.find_element(By.ID, 'login-button')
        login_button.click()
        print(__name__)
        time.sleep(1)
        button = self.driver.find_element(By.ID, 'react-burger-menu-btn')
        button.click()
        time.sleep(1)
        button = self.driver.find_element(By.ID, 'logout_sidebar_link')
        button.click()
        time.sleep(1)
        self.driver.close()

Future planed Improvments

Enhance pytest logging experiance within Robot Framework (similar structure to pytest_robotframework / pytest-robotframework)

Ensure compatibility with the Hypothesis package.

Add posibility to rename keyword for Robot Framework (RF supports this, but it may not currently work with Pytest)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-in-robotframework-0.0.9.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

pytest_in_robotframework-0.0.9-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest-in-robotframework-0.0.9.tar.gz.

File metadata

File hashes

Hashes for pytest-in-robotframework-0.0.9.tar.gz
Algorithm Hash digest
SHA256 cc525cb23099d454f09ba0e544001685e707041f0586944fdc0f4969e4c6d040
MD5 c6944ba49747f080ea261748ab05f89c
BLAKE2b-256 b1bf308d913482c5b8026ad4055bba5ea476844c70637a0c56eb76a5c4c936c7

See more details on using hashes here.

File details

Details for the file pytest_in_robotframework-0.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_in_robotframework-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 b97fa3d88c5843e1b4d8b137984dd4db4e1284e5ee79744793dbae349d0d082d
MD5 35da133a3276bbbd606949c34d1872c1
BLAKE2b-256 2bd2554f22920b37eada5b8d928d9b2ddd48e95b1f7697a0430c9fe48d5e36de

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page