<?xml version="1.0" encoding="UTF-8" ?><!-- generator=Zoho Sites --><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><atom:link href="https://www.topgrep.com/blogs/test-automation-python/feed" rel="self" type="application/rss+xml"/><title>Topgrep - Blog , Test Automation Python</title><description>Topgrep - Blog , Test Automation Python</description><link>https://www.topgrep.com/blogs/test-automation-python</link><lastBuildDate>Thu, 26 Mar 2026 14:00:31 +0530</lastBuildDate><generator>http://zoho.com/sites/</generator><item><title><![CDATA[Integrating Selenium Grid to Python Framework]]></title><link>https://www.topgrep.com/blogs/post/integrating-selenium-grid-to-python-framework</link><description><![CDATA[<img align="left" hspace="5" src="https://www.topgrep.com/co Experts.png"/>Please note the code snippet, for an example of how to integrate Selenium Grid into your Python framework using the selenium package PS: Refer the arti ]]></description><content:encoded><![CDATA[<div class="zpcontent-container blogpost-container "><div data-element-id="elm_fAVO8STqQkSniIb-vbPS1g" data-element-type="section" class="zpsection "><style type="text/css"></style><div class="zpcontainer-fluid zpcontainer"><div data-element-id="elm_MYFIukqxTd2owwjkPqP2Tw" data-element-type="row" class="zprow zprow-container zpalign-items- zpjustify-content- " data-equal-column=""><style type="text/css"></style><div data-element-id="elm_zdGF46b1TQ6GeeGbDcqBsg" data-element-type="column" class="zpelem-col zpcol-12 zpcol-md-12 zpcol-sm-12 zpalign-self- "><style type="text/css"></style><div data-element-id="elm_l9nMrjlpRFu6O4rC72H8ZA" data-element-type="text" class="zpelement zpelem-text "><style> [data-element-id="elm_l9nMrjlpRFu6O4rC72H8ZA"].zpelem-text { border-radius:1px; } </style><div class="zptext zptext-align-center " data-editor="true"><div></div><p style="text-align:left;"><span style="color:rgb(0, 74, 173);"><span style="font-size:16px;font-weight:400;text-indent:0px;">Please note the code snippet, for an example of how to integrate Selenium Grid into your Python framework using the </span><code style="font-weight:600;text-indent:0px;">selenium</code><span style="font-size:16px;font-weight:400;text-indent:0px;"> package</span></span></p><p style="text-align:left;"><span style="color:rgb(0, 74, 173);"><span style="font-size:16px;font-weight:400;text-indent:0px;">PS: Refer the article on Python framework to get the codesnippet for the framework<br></span></span></p><div><p style="font-size:16px;text-align:left;text-indent:0px;"><span style="font-weight:bold;"><span style="color:rgb(0, 74, 173);">Update WebDriver initialization:</span></span></p><ul style="text-align:left;"><li><span style="color:rgb(0, 74, 173);">Modify your <code style="font-weight:600;">webdriver_factory.py</code> module to include the following code</span></li></ul><p style="text-align:left;"><span style="color:rgb(0, 74, 173);">from selenium import webdriver</span></p><p style="text-align:left;"><span style="color:rgb(0, 74, 173);">def create_remote_driver(browser_name, platform):</span></p><p style="text-align:left;"><span style="color:rgb(0, 74, 173);">&nbsp; capabilities = {</span></p><p style="text-align:left;"><span style="color:rgb(0, 74, 173);">&nbsp; &quot;browserName&quot;: browser_name,</span></p><p style="text-align:left;"><span style="color:rgb(0, 74, 173);">&nbsp; &quot;platform&quot;: platform</span></p><p style="text-align:left;"><span style="color:rgb(0, 74, 173);">&nbsp; }</span></p><p style="text-align:left;"><span style="color:rgb(0, 74, 173);">&nbsp; return webdriver.Remote(</span></p><p style="text-align:left;"><span style="color:rgb(0, 74, 173);">&nbsp; command_executor='http://localhost:4444/wd/hub',</span></p><p style="text-align:left;"><span style="color:rgb(0, 74, 173);">&nbsp; desired_capabilities=&quot;capabilities</span></p><p style="text-align:left;"><span style="color:rgb(0, 74, 173);">&nbsp; )</span></p><div><p style="font-size:16px;text-align:left;text-indent:0px;"><span style="font-weight:bold;"><span style="color:rgb(0, 74, 173);">Modify test configuration:</span></span></p><ul style="text-align:left;"><li><span style="color:rgb(0, 74, 173);">Update your test configuration in the <code style="font-weight:600;">config.py</code> module to include the desired browser and platform information for the Selenium Grid node</span></li></ul><p style="text-align:left;"><span style="color:rgb(0, 74, 173);">GRID_BROWSER = 'chrome'&nbsp; # The desired browser (e.g., 'chrome', 'firefox')<br>GRID_PLATFORM = 'PLATFORM'&nbsp; # The desired platform (e.g., 'WINDOWS', 'LINUX')<br></span></p><div><p style="font-size:16px;font-weight:400;text-align:left;text-indent:0px;"><span style="color:rgb(0, 74, 173);">Update test scripts:</span></p><ul style="text-align:left;"><li><span style="color:rgb(0, 74, 173);">Update your test scripts in the <code style="font-weight:600;">tests/</code> directory to use the remote driver created by the <code style="font-weight:600;">webdriver_factory.py</code> module:</span></li></ul><p style="font-size:16px;font-weight:400;text-indent:0px;text-align:left;"><span style="color:rgb(0, 74, 173);">from utils.webdriver_factory import create_remote_driver<br>from utils.config import GRID_BROWSER, GRID_PLATFORM<br><br>def test_example():<br>&nbsp; driver = create_remote_driver(GRID_BROWSER, GRID_PLATFORM)<br>&nbsp; # Rest of your test code using the remote driver<br>&nbsp; driver.quit()<br></span></p><p style="font-size:16px;font-weight:400;text-indent:0px;text-align:left;"><span style="color:rgb(0, 74, 173);">With these changes, your framework will utilize the Selenium Grid infrastructure for distributed and parallel testing across multiple browsers and platforms.</span></p><div><p style="font-size:16px;text-align:left;text-indent:0px;"><span style="font-weight:bold;"><span style="color:rgb(0, 74, 173);">Start the Selenium Grid hub:</span></span></p><ul style="text-align:left;"><li><span style="color:rgb(0, 74, 173);">Open a terminal or command prompt and run the following command:</span></li></ul><p style="text-align:left;"><span style="color:rgb(0, 74, 173);">selenium-server-standalone -role hub</span></p><ul style="text-align:left;"><li><div><p><span style="color:rgb(0, 74, 173);">This command starts the Selenium Grid hub.</span></p><p><span style="color:rgb(0, 74, 173);">Start Selenium Grid nodes:</span></p><ul><li><span style="color:rgb(0, 74, 173);">Open separate terminals or command prompts for each desired browser and platform combination.</span></li><li><span style="color:rgb(0, 74, 173);">In each terminal, run the following command for each node:</span></li><li><span style="color:rgb(0, 74, 173);">selenium-server-standalone -role node -hub http://localhost:4444/grid/register<br></span></li></ul></div></li></ul></div></div></div></div></div>
</div></div></div></div></div></div> ]]></content:encoded><pubDate>Thu, 01 Jun 2023 09:23:15 +0000</pubDate></item><item><title><![CDATA[Create Python Framework - Code Snippets]]></title><link>https://www.topgrep.com/blogs/post/create-python-framework-code-snippets</link><description><![CDATA[<img align="left" hspace="5" src="https://www.topgrep.com/images/g99fda9d3d3e7993ad8daf401ddafeab977ef623a785aabfa3506ad6d1ec1ccabad1d1f7b5010adc9fddab781753b88854a35c23c8207f99e4172bfd5061a7d8f_1280.jpg"/>Initializing the Selenium WebDriver from selenium import webdriver # Initialize the WebDriver for Chrome driver = webdriver.Chrome(executable_path='path/ ]]></description><content:encoded><![CDATA[<div class="zpcontent-container blogpost-container "><div data-element-id="elm_NrtJD_aNRrWi_KTRd2wPMg" data-element-type="section" class="zpsection "><style type="text/css"></style><div class="zpcontainer-fluid zpcontainer"><div data-element-id="elm_RlkxkQ5-SXmHoIYGkgE_DQ" data-element-type="row" class="zprow zprow-container zpalign-items- zpjustify-content- " data-equal-column=""><style type="text/css"></style><div data-element-id="elm_Kgv7FNvlQVKObU9YP6-6kg" data-element-type="column" class="zpelem-col zpcol-12 zpcol-md-12 zpcol-sm-12 zpalign-self- "><style type="text/css"></style><div data-element-id="elm_F4UGwWltSvGYfUYzmGn2fg" data-element-type="text" class="zpelement zpelem-text "><style> [data-element-id="elm_F4UGwWltSvGYfUYzmGn2fg"].zpelem-text { border-radius:1px; } </style><div class="zptext zptext-align-center " data-editor="true"><div style="text-align:left;"><ol><li><span style="color:rgb(0, 74, 173);">Initializing the Selenium WebDriver</span></li></ol><p style="margin-left:160px;"><span style="color:rgb(0, 74, 173);">from selenium import webdriver<br># Initialize the WebDriver for Chrome<br>driver = webdriver.Chrome(executable_path='path/to/chromedriver.exe')<br># Initialize the WebDriver for Firefox<br>driver = webdriver.Firefox(executable_path='path/to/geckodriver.exe')<br></span></p><div><ol start="2"><li><span style="color:rgb(0, 74, 173);">Creating a Page Object</span></li></ol></div><p style="margin-left:160px;"><span style="color:rgb(0, 74, 173);">from selenium.webdriver.common.by import By<br>from selenium.webdriver.support import expected_conditions as EC<br>from selenium.webdriver.support.ui import WebDriverWait<br><br>class LoginPage:<br>&nbsp; def __init__(self, driver):<br>&nbsp; self.driver = driver<br>&nbsp; self.username_field = (By.ID, 'username')<br>&nbsp; self.password_field = (By.ID, 'password')<br>&nbsp; self.login_button = (By.ID, 'login-button')<br><br>&nbsp; def enter_username(self, username):<br>&nbsp; self.driver.find_element(*self.username_field).send_keys(username)<br><br>&nbsp; def enter_password(self, password):<br>&nbsp; self.driver.find_element(*self.password_field).send_keys(password)<br><br>&nbsp; def click_login_button(self):<br>&nbsp; self.driver.find_element(*self.login_button).click()<br><br>&nbsp; def wait_for_login_page(self):<br>&nbsp; WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.login_button))<span style="font-size:16px;font-weight:400;text-indent:0px;"><br></span></span></p><p><span style="color:rgb(0, 74, 173);"><span style="font-size:16px;font-weight:400;text-indent:0px;">3. Writing a Test Case using pytest</span></span></p><p style="margin-left:160px;"><span style="color:rgb(0, 74, 173);"><span style="font-size:16px;font-weight:400;text-indent:0px;">import pytest<br></span><span style="font-size:16px;font-weight:400;text-indent:0px;">@pytest.mark.smoke</span><br><span style="font-size:16px;font-weight:400;text-indent:0px;">def test_successful_login(driver):</span><br><span style="font-size:16px;font-weight:400;text-indent:0px;">&nbsp; login_page = LoginPage(driver)</span><br><span style="font-size:16px;font-weight:400;text-indent:0px;">&nbsp; login_page.enter_username('testuser')</span><br><span style="font-size:16px;font-weight:400;text-indent:0px;">&nbsp; login_page.enter_password('password')</span><br><span style="font-size:16px;font-weight:400;text-indent:0px;">&nbsp; login_page.click_login_button()</span><br><span style="font-size:16px;font-weight:400;text-indent:0px;">&nbsp; # Add assertions to verify successful login</span><br><span style="font-size:16px;font-weight:400;text-indent:0px;"></span></span></p><div><ol start="4"><li><span style="color:rgb(0, 74, 173);">Setting up Fixtures in pytest</span></li></ol><div style="margin-left:160px;"><span style="color:rgb(0, 74, 173);">import pytest<br>from selenium import webdriver<br><br>@pytest.fixture(scope='session')<br>def driver():<br>&nbsp; # Initialize the WebDriver<br>&nbsp; driver = webdriver.Chrome(executable_path='path/to/chromedriver.exe')<br>&nbsp; # Alternatively, use Firefox driver: webdriver.Firefox(executable_path='path/to/geckodriver.exe')<br><br>&nbsp; # Set up any additional configurations or capabilities<br>&nbsp; driver.maximize_window()<br><br>&nbsp; # Yield the driver instance to the test<br>&nbsp; yield driver<br><br>&nbsp; # Teardown - quit the driver after all tests have finished<br>&nbsp; driver.quit()<br></span></div><div><ol start="5"><li><span style="color:rgb(0, 74, 173);">Capturing Screenshots</span></li></ol><div style="margin-left:160px;"><span style="color:rgb(0, 74, 173);">import os<br>import datetime<br><br>def capture_screenshot(driver, screenshot_dir):<br>&nbsp; timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')<br>&nbsp; screenshot_name = f'screenshot_{timestamp}.png'<br>&nbsp; screenshot_path = os.path.join(screenshot_dir, screenshot_name)<br>&nbsp; driver.save_screenshot(screenshot_path)<br></span></div><span style="color:rgb(0, 74, 173);"><span style="font-size:16px;font-weight:400;text-indent:0px;">These are just a few examples of code snippets that can be used in a Selenium framework. Remember to adapt them to your specific project structure and requirements.</span></span></div></div></div></div>
</div><div data-element-id="elm_f9EdGW0BRBqW_YKLFUPhVQ" data-element-type="button" class="zpelement zpelem-button "><style> [data-element-id="elm_f9EdGW0BRBqW_YKLFUPhVQ"].zpelem-button{ border-radius:1px; } </style><div class="zpbutton-container zpbutton-align-center "><style type="text/css"></style><a class="zpbutton-wrapper zpbutton zpbutton-type-primary zpbutton-size-md zpbutton-style-none " href="javascript:;" target="_blank"><span class="zpbutton-content">Get Started Now</span></a></div>
</div></div></div></div></div></div> ]]></content:encoded><pubDate>Fri, 26 May 2023 04:53:07 +0000</pubDate></item><item><title><![CDATA[Selenium Python - Framework]]></title><link>https://www.topgrep.com/blogs/post/selenium-python-framework</link><description><![CDATA[<img align="left" hspace="5" src="https://www.topgrep.com/co Experts.png"/>In today's fast-changing digital world, web testing plays a crucial role in ensuring top-notch software applications. Python Selenium has become a pop ]]></description><content:encoded><![CDATA[<div class="zpcontent-container blogpost-container "><div data-element-id="elm_7K-6M3YpQ5SvNaK-PFU2QA" data-element-type="section" class="zpsection "><style type="text/css"></style><div class="zpcontainer-fluid zpcontainer"><div data-element-id="elm_Ccl6dZkzSv6umDWRhyYS7w" data-element-type="row" class="zprow zprow-container zpalign-items- zpjustify-content- " data-equal-column=""><style type="text/css"></style><div data-element-id="elm_h7Ke--SFSxeHBbY0l4HjFQ" data-element-type="column" class="zpelem-col zpcol-12 zpcol-md-12 zpcol-sm-12 zpalign-self- "><style type="text/css"></style><div data-element-id="elm_aB5NTAZjTOyHt8vbQq6wiA" data-element-type="text" class="zpelement zpelem-text "><style> [data-element-id="elm_aB5NTAZjTOyHt8vbQq6wiA"].zpelem-text { border-radius:1px; } </style><div class="zptext zptext-align-center " data-editor="true"><div style="text-align:left;"><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);">In today's fast-changing digital world, web testing plays a crucial role in ensuring top-notch software applications. Python Selenium has become a popular choice for web testing due to its simplicity and powerful capabilities. To take your web testing to the next level, integrating screen and video capture features into your framework can offer valuable insights, streamline bug reporting, and drive excellence in quality engineering. This article will walk you through the process of building a comprehensive Python Selenium framework that incorporates quality engineering principles and includes screen and video capture functionalities. With this framework, you'll be able to create robust, maintainable, and visually enriched test reports.</span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);"><strong>Understanding the Basics:</strong></span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);">Let's start by getting familiar with Python Selenium and its core functionalities for web testing. We'll also cover the setup requirements for screen and video capture, ensuring you have everything you need. Additionally, we'll provide an overview of the essential components that make up a comprehensive testing framework.</span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);"><strong>Test Organization and Structure</strong></span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);">Step -1: we'll make sure you understand how to prune your test suite so that it is latest, optimised and prioritised. To make your tests scalable, maintainable, and user-friendly, we'll explore effective strategies for structuring your tests. We'll discuss the importance of separating test logic from test data to promote reusability. Furthermore, we'll show you how to seamlessly integrate screen and video capture into your test structure, making it an integral part of your testing process.</span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);"><strong>Configuration Management</strong></span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);">Managing different test configurations and environment settings is crucial for handling various scenarios. We'll discuss techniques for externalizing configuration parameters using files or databases, allowing flexibility and easy maintenance across different environments, such as development, staging, and production.</span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);"><strong>Test Data Management</strong></span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);">Efficiently managing test data is key to covering various test scenarios. We'll explore methods for storing test data in external files or databases, enabling flexibility and reusability. Additionally, we'll delve into the implementation of data-driven testing, which allows you to handle multiple test cases effectively.</span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);"><strong>Logging, Reporting, and Documentation</strong></span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);">To gain better visibility into test execution, implementing logging mechanisms is essential. We'll guide you through capturing screenshots at critical points and recording videos of test executions. Furthermore, we'll show you how to generate comprehensive reports that include embedded screenshots and video links. These detailed and visual reports will facilitate communication with stakeholders.</span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);"><strong>Error Handling and Debugging</strong></span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);">Implementing robust error handling mechanisms will help you capture failures effectively. We'll explore techniques for automatically capturing screenshots or videos when a test fails. Leveraging these captured media assets will greatly assist in issue reproduction and debugging.</span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);"><strong>Test Execution and Parallelization</strong></span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);">Optimizing the flow and order of test execution is crucial for efficiency. We'll demonstrate how to implement test suites and test runners to streamline the execution process. Moreover, we'll explore the benefits of parallel execution, which can significantly accelerate your testing cycles.</span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);"><strong>Integration with Continuous Integration (CI) Systems</strong></span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);">To seamlessly integrate your framework with popular CI systems like Jenkins or Travis CI, we'll cover the necessary steps. You'll learn how to automate test execution, result reporting, and capture management, leveraging CI pipelines to seamlessly fit into your development workflow.</span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);"><strong>Best Practices and Performance Optimization</strong></span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);">Following coding standards and best practices ensures maintainable code. We'll provide guidelines for configuring capture settings to achieve optimal performance and file size. Additionally, we'll discuss techniques for optimizing test execution speed and efficiency.</span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);"><strong>Summary</strong></span></p><p style="font-weight:400;text-indent:0px;"><span style="color:rgb(0, 74, 173);">Building a comprehensive framework for web testing with Python Selenium empowers you to drive excellence in quality engineering while capturing screens and recording videos. These features offer valuable insights for bug reporting and analysis. By embracing the principles and practices outlined in this article, you'll streamline your testing efforts, improve the quality of your web applications, and achieve efficient and reliable test automation. Harness the power of Python Selenium and the benefits of screen and video capture to elevate your web testing capabilities and deliver exceptional software applications in today's competitive digital landscape.</span></p></div><p style="text-align:left;"></p></div>
</div></div></div></div></div></div> ]]></content:encoded><pubDate>Thu, 25 May 2023 05:22:44 +0000</pubDate></item></channel></rss>