Contexts automation testing framework index.

Test More In Less Time

Run Automation Testing In Parallel On The LambdaTest Cloud

Start for free

Description

Contexts is a 'Context-Specification'-style test framework for Python. Simple descriptive testing with no custom decorators, context managers or .feature file.

Support and updates

  • Contexts has 57 stars, 5 forks.
  • It has 0 major releases in the past 6 months.
  • It has 0 commits and there are 0 open pull requests.
  • It has 5 open issues and 11 have been closed.

Code statistics

  • Contexts has 17 methods.

Blogs

Check out the latest blogs from LambdaTest on this topic:

Continuous Integration explained with jenkins deployment

Continuous integration is a coding philosophy and set of practices that encourage development teams to make small code changes and check them into a version control repository regularly. Most modern applications necessitate the development of code across multiple platforms and tools, so teams require a consistent mechanism for integrating and validating changes. Continuous integration creates an automated way for developers to build, package, and test their applications. A consistent integration process encourages developers to commit code changes more frequently, resulting in improved collaboration and code quality.

Why does DevOps recommend shift-left testing principles?

Companies are using DevOps to quickly respond to changing market dynamics and customer requirements.

Top 22 Selenium Automation Testing Blogs To Look Out In 2020

If you are a web tester then somewhere down the road you will have to come across Selenium, an open-source test automation framework that has been on boom ever since its launch in 2004.

How To Get Started With Cypress Debugging

One of the most important tasks of a software developer is not just writing code fast; it is the ability to find what causes errors and bugs whenever you encounter one and the ability to solve them quickly.

Feeding your QA Career – Developing Instinctive & Practical Skills

The QA testing profession requires both educational and long-term or experience-based learning. One can learn the basics from certification courses and exams, boot camp courses, and college-level courses where available. However, developing instinctive and practical skills works best when built with work experience.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

License

Contexts is lincensed under the MIT License

LambdaTest Community Discussions

Questions
Discussion

Pytest Setup and Teardown for Selenium Testing

I've never understood why there was ever a need to put CSS inside JS

Exit Nested Loops in Python

Understanding return True and False in Python

Python Truthy and Falsy Values

What is the correct way to set up and tear down resources for a pytest class when using Selenium for end-to-end testing?

I need to initialize the browser in the setup_class method, perform several tests defined as class methods, and then quit the browser in the teardown_class method. However, I’m struggling to understand how to properly use setup_class and teardown_class methods in this context.

It seems like a bad solution logically, because my tests will work with the instance, not the class. Since I pass the self parameter inside every test method, I can access instance variables, but I can’t access cls variables in the same way.

Here’s the structure of my current code:

class TestClass:
  
    def setup_class(cls):
        pass
        
    def test_buttons(self, data):
        # self.$attribute can be used, but not cls.$attribute?  
        pass
        
    def test_buttons2(self, data):
        # self.$attribute can be used, but not cls.$attribute?
        pass
        
    def teardown_class(cls):
        pass

This approach doesn’t feel right for creating the browser instance at the class level. Shouldn’t the browser instance be created for each object separately instead of for the whole class?

Would it be better to use __init__ and __del__ methods instead of setup_class and teardown_class for managing browser initialization and cleanup in pytest setup?

https://community.lambdatest.com/t/35259

Instead of using setup_class and teardown_class, you can use setup_method and teardown_method to manage resources on an instance level. This means each test runs in complete isolation with its own browser instance, ensuring test independence and avoiding shared state issues.

import pytest
from selenium import webdriver

class TestClass:

    def setup_method(self):
        # Setup browser instance for each test
        self.browser = webdriver.Chrome()
    
    def test_buttons(self):
        # Use self.browser here to interact with the browser
        self.browser.get('http://example.com')
        assert self.browser.title == 'Example Domain'
    
    def test_buttons2(self):
        # Another test using its own browser instance
        self.browser.get('http://anotherexample.com')
        assert self.browser.title == 'Another Example'
    
    def teardown_method(self):
        # Teardown browser instance after each test
        if hasattr(self, 'browser'):
            self.browser.quit()

:white_check_mark: Why this works?

  • Each test runs in isolation, preventing state leakage.
  • If one test fails or crashes, it doesn’t affect others.
  • Ideal for independent, repeatable, and parallelized tests.
https://community.lambdatest.com/t/35259

If opening a new browser for every test is too slow, you might want to set up the browser once per test class. This reduces overhead but comes with a risk: tests could interfere with each other.

import pytest
from selenium import webdriver

class TestClass:

    @classmethod
    def setup_class(cls):
        # Setup browser instance once for the entire class
        cls.browser = webdriver.Chrome()
    
    def test_buttons(self):
        # Use cls.browser here, shared across tests
        self.browser.get('http://example.com')
        assert self.browser.title == 'Example Domain'
    
    def test_buttons2(self):
        # Another test using the same browser instance
        self.browser.get('http://anotherexample.com')
        assert self.browser.title == 'Another Example'
    
    @classmethod
    def teardown_class(cls):
        # Teardown browser instance once after all tests
        if hasattr(cls, 'browser'):
            cls.browser.quit()

:white_check_mark: Why this works?

  • Faster since you don’t have to create and close a browser for every test.
  • Useful when tests depend on a shared session (e.g., logging in once and running multiple tests).

:warning: Potential Issue:

  • If one test modifies the browser state (e.g., navigating to a different page), it may affect the next test.
  • Harder to parallelize tests.
https://community.lambdatest.com/t/35259

Instead of relying on pytest’s built-in setup methods, you can manage resources within the test class using __init__ and __del__.

import pytest
from selenium import webdriver

class TestClass:

    def __init__(self):
        # Initialize browser for each test instance
        self.browser = webdriver.Chrome()

    def test_buttons(self):
        # Use self.browser here to interact with the browser
        self.browser.get('http://example.com')
        assert self.browser.title == 'Example Domain'

    def test_buttons2(self):
        # Another test using the same browser instance
        self.browser.get('http://anotherexample.com')
        assert self.browser.title == 'Another Example'

    def __del__(self):
        # Cleanup browser instance when the test object is deleted
        if hasattr(self, 'browser'):
            self.browser.quit()

:white_check_mark: Why this works?

  • A clean, object-oriented approach to managing resources.
  • The browser instance exists as long as the test object is alive.
  • Automatic cleanup when the object is deleted.

:warning: Potential Issue:

  • __del__ is not always called immediately (Python’s garbage collection is unpredictable).
  • Less explicit than pytest’s built-in setup/teardown methods.
https://community.lambdatest.com/t/35259

Test case code snippets

General webpage functionality - Test page text justification

Description:

Page text should be left-justified.

API Testing - Check locale-based representation

Description:

Verify that the API response contains the correct resource representation based on the specified locale (e.g. en-US, fr-FR).

API Testing - Check CORS preflight

Description:

Verify that the API correctly handles CORS preflight requests and returns the correct HTTP status code and error message.

General webpage functionality - Test broken links check

Description:

Check all pages for broken links.

Downloads

Contexts can be downloaded from it’s GitHub repository - https://github.com/benjamin-hodgson/Contexts

Method index

Other similar frameworks

hypothesis

Hypothesis is a family of testing libraries which let you write tests parametrized by a source of examples. Generates simple and comprehensible examples that make your tests fail.

SeleniumLibrary

SeleniumLibrary is a web testing library for Robot Framework that utilizes the Selenium tool. It is hosted on GitHub and downloads can be found from PyPI.

tox

CLI driven CI frontend and automation tool.

Radish

radish is a Behavior Driven Development tool completely written in python. It supports all gherkin language features. radish is available as pip package.

Pytest

The pytest an open-source framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries.

Frameworks to try

Rod

Tool for scraping and web automation using devtools driver

Selenoid

Selenoid is a powerful implementation of Selenium hub using Docker containers to launch browsers

Spinach_ruby

Spinach is a BDD framework on top of Gherkin.

Atata

Atata is a C#/.NET web UI test automation full featured framework based on Selenium WebDriver. It uses fluent page object pattern.

Mockingbird

Mockingbird makes it easy to mock, stub, and verify objects in Swift unit tests. You can test both without writing any boilerplate or modifying production code.

Run Contexts scripts on 3000+ browsers online

Perform automation testing with Contexts on LambdaTest, the most powerful, fastest, and secure cloud-based platform to accelerate test execution speed.

Test Now