Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 31, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 31, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 31, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 31, 2025

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025

      Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

      May 31, 2025

      I love Elden Ring Nightreign’s weirdest boss — he bargains with you, heals you, and throws tantrums if you ruin his meditation

      May 31, 2025

      How to install SteamOS on ROG Ally and Legion Go Windows gaming handhelds

      May 31, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Oracle Fusion new Product Management Landing Page and AI (25B)

      May 31, 2025
      Recent

      Oracle Fusion new Product Management Landing Page and AI (25B)

      May 31, 2025

      Filament Is Now Running Natively on Mobile

      May 31, 2025

      How Remix is shaking things up

      May 30, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025
      Recent

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025

      Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

      May 31, 2025

      I love Elden Ring Nightreign’s weirdest boss — he bargains with you, heals you, and throws tantrums if you ruin his meditation

      May 31, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»A Beginner’s Guide to Running Selenium Tests on BrowserStack using Pytest

    A Beginner’s Guide to Running Selenium Tests on BrowserStack using Pytest

    December 31, 2024

    In today’s world, testing web applications across multiple browsers and devices is essential. One of the best tools for this is BrowserStack, a cloud-based platform that allows you to run Selenium tests on various real browsers and devices. In this blog, we will walk you through the process of integrating BrowserStack with Python Selenium and running tests using Pytest.

    What is BrowserStack?

    BrowserStack is a cloud-based testing platform that allows you to run automated tests on real browsers and devices, without needing to set up the infrastructure yourself. It supports various browsers like Chrome, Firefox, Safari, Edge, and even mobile devices like iPhones and Android phones.

    Browserstack

    Why Use BrowserStack with Selenium?

    Selenium is a widely used tool for automating browsers, and with BrowserStack, you can run your Selenium tests on a wide range of browsers and operating systems. This ensures your application works seamlessly across different environments without needing to maintain your own testing infrastructure.

    In this guide, we will use Pytest—a popular testing framework for Python—to run tests. This combination provides an efficient and flexible way to conduct cross-browser testing.

    Prerequisites

    Before you begin, ensure you have the following installed:

    1. Python (Version 3 or above)
    2. Selenium: Install it via pip
      pip install selenium
    3. Pytest: Install it via pip
      pip install pytest
    4. BrowserStack Account: Sign up at BrowserStack and get your username and access key.

    Step 1: Set Up BrowserStack

    Once you have an account on BrowserStack, you can find your username and access key from the BrowserStack dashboard.

    You’ll use these credentials to authenticate your Selenium tests on BrowserStack.

    Step 2: Configure Selenium to Use BrowserStack

    To configure your Selenium WebDriver to run on BrowserStack, you need to specify BrowserStack’s remote URL, your credentials, and the desired capabilities of the browser or device you wish to test on.

    Here is how to set it up:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    import pytest
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    
    # BrowserStack credentials
    username = "your_browserstack_username"
    access_key = "your_browserstack_access_key"
    
    # Desired capabilities to run the test
    desired_cap = {
        'browser': 'Chrome',
        'browser_version': 'latest',
        'os': 'Windows',
        'os_version': '10',
        'name': 'Python Selenium BrowserStack Test'  # Test name
    }
    
    # BrowserStack URL
    url = f"https://{username}:{access_key}@hub-cloud.browserstack.com/wd/hub"
    
    # Pytest Fixture to initialize the driver
    @pytest.fixture(scope="function")
    def driver():
        driver = webdriver.Remote(
            command_executor=url,
            desired_capabilities=desired_cap
        )
        yield driver
        driver.quit()
    
    # Sample Test Case using Pytest
    def test_browserstack(driver):
        driver.get("https://www.browserstack.com")
        assert "BrowserStack" in driver.title
    
        # Example of interaction
        search_box = driver.find_element(By.NAME, "q")
        search_box.send_keys("Selenium Python")
        search_box.send_keys(Keys.RETURN)
    
        # Assert something to validate test
        assert "Selenium" in driver.page_source
    

    Key Points:

    • username and access_key: These values authenticate your test on BrowserStack.
    • desired_cap: This dictionary defines the configuration for the browser and OS you want to test on.
      • browser: The browser you want to test (Chrome, Firefox, etc.).
      • browser_version: Version of the browser (e.g., ‘latest’ or ’90’).
      • os: Operating system you want to run the tests on (Windows, macOS, Linux).
      • os_version: Version of the OS.
      • name: A custom name for the test.

    Step 3: Running the Test with Pytest

    To run the tests with Pytest, simply use the following command in your terminal:

    pytest test_browserstack.py

    This will trigger the test on BrowserStack, and you can view the results directly on the BrowserStack dashboard.

    Step 4: Viewing Test Results on BrowserStack

    Once your tests complete, you can visit the BrowserStack Dashboard to view detailed logs, screenshots, and videos of the tests. This can help in debugging any issues with your application.

    Conclusion

    Integrating BrowserStack with Python Selenium and Pytest is a powerful way to ensure your web application works across different browsers and devices. By using the cloud-based BrowserStack platform, you can avoid the hassle of setting up multiple testing environments and focus on writing effective tests. With Pytest’s simple yet effective testing capabilities, you can execute your cross-browser tests smoothly and efficiently.

    If you run into any issues during the setup or execution, make sure to check the BrowserStack documentation for troubleshooting and advanced configuration options.

    Happy testing!

    Source: Read More 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleBuilding Azure DevOps CD Processes for SPFx
    Next Article From Code to Cloud: AWS Lambda CI/CD with GitHub Actions

    Related Posts

    Artificial Intelligence

    Markus Buehler receives 2025 Washington Award

    May 31, 2025
    Artificial Intelligence

    LWiAI Podcast #201 – GPT 4.5, Sonnet 3.7, Grok 3, Phi 4

    May 31, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    My journey from Webpack to Vite and finally Rsbuild

    Development

    3AM ransomware: what you need to know

    Development

    Microsoft is launching its first ever Surface Laptop with 5G connectivity, but you’ll have to wait for it

    News & Updates

    CVE-2025-3053 – “UiPress Lite WordPress Remote Code Execution Vulnerability”

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    CVE-2025-4430 – EZD RP File Manipulation Remote Code Execution

    May 14, 2025

    CVE ID : CVE-2025-4430

    Published : May 14, 2025, 11:16 a.m. | 51 minutes ago

    Description : Unauthorized access to “/api/Token/gettoken” endpoint in EZD RP allows file manipulation.This issue affects EZD RP in versions before 20.19 (published on 22nd August 2024).

    Severity: 0.0 | NA

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    This AI Paper from Menlo Research Introduces AlphaMaze: A Two-Stage Training Framework for Enhancing Spatial Reasoning in Large Language Models

    February 25, 2025

    API with NestJS #182. Storing coordinates in PostgreSQL with Drizzle ORM

    January 6, 2025

    Cyberattack Targets Swiss Schlatter Industries’ IT Network

    August 12, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.