<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: JoliveHodehou</title>
    <description>The latest articles on Forem by JoliveHodehou (@jolivehodehou_84).</description>
    <link>https://forem.com/jolivehodehou_84</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F996915%2Ffe8ece78-feb6-4072-a89e-a522ce301876.png</url>
      <title>Forem: JoliveHodehou</title>
      <link>https://forem.com/jolivehodehou_84</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jolivehodehou_84"/>
    <language>en</language>
    <item>
      <title>Python ConfigParser Tutorial – Comprehensive Guide To Working With Configuration Files With Python</title>
      <dc:creator>JoliveHodehou</dc:creator>
      <pubDate>Wed, 02 Aug 2023 14:55:26 +0000</pubDate>
      <link>https://forem.com/testmuai/python-configparser-tutorial-comprehensive-guide-to-working-with-configuration-files-with-python-1jo5</link>
      <guid>https://forem.com/testmuai/python-configparser-tutorial-comprehensive-guide-to-working-with-configuration-files-with-python-1jo5</guid>
      <description>&lt;p&gt;As a QA Engineer, one of the common tasks is &lt;a href="https://www.lambdatest.com/learning-hub/software-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;software testing&lt;/a&gt; that relies on various configuration settings. These settings can include URLs, database connection strings, authentication credentials, and more. These configuration settings can be stored in various file formats, such as .ini, .csv, .json, etc., and can be read using different libraries in Python.&lt;/p&gt;

&lt;p&gt;The challenge is that these configuration settings can change over time, and it can be tedious and error-prone to hard-code these values directly into the code. For example, if the URL of the service changes, all instances of that URL would need to be updated in the codebase.&lt;/p&gt;

&lt;p&gt;Furthermore, if there are multiple environments (such as development, testing, and production), these configuration settings may differ between them. For instance, a development database may use a different connection string than a production database. These differences can lead to bugs and errors that are difficult to detect and resolve.&lt;/p&gt;

&lt;p&gt;Python is one of the most popular programming languages in the world, especially in the automation field. According to the statistics, 824,793 are Python customers. Due to its simple and easy-to-learn syntax, it has become the go-to language for many developers. This popularity has led to the development of a vast array of modules and libraries that make Python an excellent choice for automation tasks.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;This smoke testing tutorial covers what &lt;a href="https://www.lambdatest.com/learning-hub/smoke-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;smoke testing&lt;/a&gt; is, its importance, benefits, and how to perform it with real-time examples.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2508%2F0%2AD4npG5gIAMo6Zcbc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2508%2F0%2AD4npG5gIAMo6Zcbc.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Source- Trends.builtwith&lt;/p&gt;

&lt;p&gt;One such module is the Python ConfigParser module, which allows developers to read, modify, and write configuration files in a standardized way. The Python ConfigParser module supports various configuration file formats, including INI-style files, which are commonly used in many applications.&lt;/p&gt;

&lt;p&gt;By using Python ConfigParser, developers can store configuration settings separately in configuration files, making it easy to manage settings for different environments. This separation makes the code modular, maintainable, and easier to change. Additionally, Python ConfigParser provides a simple and consistent API for working with configuration files, making it easy to read and modify configuration settings from within the code.&lt;/p&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/selenium-python-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium Python testing&lt;/a&gt; tutorial, let’s explore the usage of Python ConfigParser to read and write configuration parameters from/into an INI file and a practical example where we automate a website login feature. Throughout the tutorial, let us leverage the &lt;a href="https://www.lambdatest.com/blog/11-best-unit-testing-frameworks-for-selenium-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;unit testing framework&lt;/a&gt; and the &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; library and demonstrate the power of Python ConfigParser in managing login credentials in a separate configuration file. Additionally, it showcases the flexibility of Python ConfigParser in handling multiple browsers and its usefulness in &lt;a href="https://www.lambdatest.com/blog/cloud-testing-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cloud testing&lt;/a&gt; scenarios.&lt;/p&gt;

&lt;p&gt;With this approach, we can easily update our configuration settings without changing our code, making it more modular and maintainable.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A complete &lt;a href="https://www.lambdatest.com/learning-hub/manual-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Manual testing&lt;/a&gt; tutorial covering all aspects of Manual testing, including strategies and best practices.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is Python ConfigParser?
&lt;/h2&gt;

&lt;p&gt;ConfigParser is a Python standard library module that allows parsing configuration files in INI format. INI stands for initialization, a simple and common file format used to store configuration data, such as application settings, database credentials, or API keys.&lt;/p&gt;

&lt;p&gt;Here’s an example of how an INI-style configuration file looks.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Release1]
url = http://api.release1.com
port = 8080
timeout = 10
debug = false


[Release2]
url = http://api.release2.com
port = 8081
timeout = 20
debug = true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this example, there are two sections: &lt;strong&gt;[Release1]&lt;/strong&gt; and &lt;strong&gt;[Release2]&lt;/strong&gt;. Each section defines the configuration settings for a specific release. The &lt;strong&gt;[Release1]&lt;/strong&gt; section contains a URL, port, timeout, and debug flag for Release 1, while the &lt;strong&gt;[Release2]&lt;/strong&gt; section contains the same configuration settings for Release 2 with different values.&lt;/p&gt;

&lt;p&gt;Using separate values for each release allows for easier management of configurations for different environments. For instance, if we need to change the URL or port for one of the releases, we can modify the corresponding section in the configuration file without affecting the other releases.&lt;/p&gt;

&lt;p&gt;The Python ConfigParser module provides a way to read and write configuration files using a hierarchical structure of sections and options. A name in square brackets identifies sections, and options are defined as key-value pairs within each section.&lt;/p&gt;

&lt;p&gt;The module provides a convenient and robust interface for parsing configuration files, handling errors and exceptions, and interpolating values from other sections or environment variables.&lt;/p&gt;

&lt;p&gt;Let’s cover the basics of working with configuration files using the Python ConfigParser.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A comprehensive User &lt;a href="https://www.lambdatest.com/learning-hub/user-acceptance-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Acceptance Testing &lt;/a&gt;(UAT) tutorial that covers what User Acceptance Testing is, its importance, benefits, and how to perform it with real-time examples.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Installing ConfigParser
&lt;/h2&gt;

&lt;p&gt;ConfigParser is a built-in module in Python, so there is no need to install it separately. However, we will need to import it before we can use it in our code with the below command.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import configparser
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Creating a Configuration File
&lt;/h2&gt;

&lt;p&gt;To create a new configuration file, we can use the &lt;em&gt;ConfigParser()&lt;/em&gt; constructor to create a new instance of the &lt;em&gt;ConfigParser&lt;/em&gt; class. We can then use the &lt;em&gt;write()&lt;/em&gt; method to write the configuration to a file.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import configparser


config = configparser.ConfigParser()
config['Section 1'] = {'key1': 'value1', 'key2': 'value2'}
config['Section 2'] = {}
config['Section 2']['key3'] = 'value3'
config['Section 2']['key4'] = 'value4'


with open(test_config.ini, 'w') as configfile:
   config.write(configfile)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will create a new configuration file called test_config.ini in the current directory with the following content:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Section 1]
key1 = value1
key2 = value2


[Section 2]
key3 = value3
key4 = value4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Reading a Configuration File
&lt;/h2&gt;

&lt;p&gt;To read a configuration file, we can use the &lt;em&gt;read()&lt;/em&gt; method of the Python ConfigParser object. This method takes the filename of the configuration file as its argument.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import configparser


config = configparser.ConfigParser()
config.read(test_config.ini')


print(config.sections())
# Output: ['Section 1', 'Section 2']


print(config['Section 1']['key1'])
# Output: 'value1'


print(config['Section 2']['key3'])
# Output: 'value3'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Deleting a Section or Key
&lt;/h2&gt;

&lt;p&gt;To delete a section or key in a configuration file, we can use the &lt;em&gt;remove_section()&lt;/em&gt; and &lt;em&gt;remove_option()&lt;/em&gt; methods, respectively.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import configparser


config = configparser.ConfigParser()
config.read(test_config.ini')


config.remove_section('Section 2')
config.remove_option('Section 1', 'key1')


with open(test_config.ini', 'w') as configfile:
   config.write(configfile)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will remove Section 2 and the key1 from Section 1 of the test_config.ini file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of using ConfigParser
&lt;/h2&gt;

&lt;p&gt;While we have established the key benefits that ConfigParser offers to developers, we can summarize them for your configuration management needs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simple to use:&lt;/strong&gt; Python ConfigParser is a user-friendly module that makes it easy to handle configurations in a test automation project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supports multiple configuration file formats:&lt;/strong&gt; It supports multiple configuration file formats like .ini, .conf, and .cfg files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Allows the use of sections and keys:&lt;/strong&gt; Python ConfigParser allows the use of sections and keys to organize configuration data, making it easy to read and update the configuration files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;**Flexible: **ConfigParser is flexible and allows developers to choose the data types for values in configuration files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supports interpolation:&lt;/strong&gt; It supports interpolation, which is the ability to use values from one section in another section.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Python standard library:&lt;/strong&gt; Python ConfigParser is readily available and does not require additional installation or setup.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cross-platform:&lt;/strong&gt; ConfigParser is cross-platform and can be used on any operating system that supports Python. This makes it a versatile tool for automation tasks that need to run in different environments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic configuration support:&lt;/strong&gt; Python ConfigParser allows us to define different key-value pairs and sections for different releases of the application. This makes it easy to manage and deploy different configurations across different environments, such as development, testing, and production.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;In this Ad hoc testing tutorial, let’s deep dive into what &lt;a href="https://www.lambdatest.com/learning-hub/ad-hoc-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Ad hoc testing&lt;/a&gt; is, its advantages, disadvantages, types, characteristics, and their best practices.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Write your first tests using Python ConfigParser
&lt;/h2&gt;

&lt;p&gt;Using ConfigParser is one way to write tests for configuration files. It is a module that allows you to read and write configuration files using a simple syntax. Let’s get started with writing tests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Check if Python is installed&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To begin, ensure the below to get Python installed on your machine.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open a terminal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type the following command and press enter:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If Python is not installed or the version displayed is not the desired version, proceed to install it.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Install Python (if necessary)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To install Python on macOS using Homebrew, follow the below steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Type brew install python on the terminal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once the installation is completed, verify the installation again using the command python --version. This time, the installed Python version should be displayed.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Install Selenium&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Follow the below pointers to install Selenium using pip:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open a terminal on your macOS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type the following command and press Enter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you are using Python 3, use pip3 instead of pip:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Getting started with ConfigParser
&lt;/h2&gt;

&lt;p&gt;In this section of the Python ConfigParser blog, we will look at the following &lt;a href="https://www.lambdatest.com/learning-hub/test-case?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test case&lt;/a&gt; for a login feature:&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Case 1: Storing URL and Login Credentials
&lt;/h2&gt;

&lt;p&gt;Let’s explore how to leverage ConfigParser to store URL and login credentials securely.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to &lt;a href="https://ecommerce-playground.lambdatest.io/index.php?route=account/login" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.io/index.php?route=account/login&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter your email in the E-Mail Address field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter your password in the Password field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the Login button to connect.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is what the structure of our project should look like.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A6X-obTGREx_G6d7m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A6X-obTGREx_G6d7m.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;config folder:&lt;/strong&gt; Contains the test_config.ini file, which stores the configuration settings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;pages folder:&lt;/strong&gt; Contains the login_page.py file, which contains the &lt;a href="https://www.lambdatest.com/blog/page-object-model-in-selenium-python/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Page Object Model (POM)&lt;/a&gt; for the login page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;tests folder:&lt;/strong&gt; Contains the test files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;utils folder:&lt;/strong&gt; Contains the config_reader.py file, which contains a function to read the configuration settings from the test_config.ini file.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;File: test_config.ini&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The test_config.ini file stores the URL and login credentials for the website.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[WEBSITE]
url = https://ecommerce-playground.lambdatest.io/index.php?route=account/login
[LOGIN]
email = test@test.lambdatest.com
password = lambdatest_password
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;File: config_reader.py&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The config_reader.py file contains a function to read the configuration settings from the test_config.ini file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import configparser

def read_config(section, key):
   config = configparser.ConfigParser()
   config.read('config/test_config.ini')
   return config[section][key]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This function takes two arguments: &lt;em&gt;section&lt;/em&gt; and &lt;em&gt;key&lt;/em&gt;, which correspond to the section and key in the test_config.ini file. It returns the value of the specified key in its specified section.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;File: login_page.py&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The login_page.py file contains the Page Object Model (POM) for the login page.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from utils.config_reader import read_config


class LoginPage:
   def __init__(self, driver):
       self.driver = driver
       self.wait = WebDriverWait(self.driver, 10)


   @property
   def email(self):
       return self.wait.until(EC.presence_of_element_located((By.ID, 'input-email')))


   @property
   def password(self):
       return self.wait.until(EC.presence_of_element_located((By.ID, 'input-password')))


   @property
   def submit_button(self):
       return self.wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@value='Login']")))


   def login(self):
       self.email.send_keys(read_config('LOGIN', 'email'))
       self.password.send_keys(read_config('LOGIN', 'password'))
       self.submit_button.click()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;In this Appium tutorial, learn about &lt;a href="https://www.lambdatest.com/appium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Appium&lt;/a&gt; and its benefits for mobile automation testing. Take a look at how Appium works and see how to perform Appium testing of your mobile applications.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This class defines the elements and actions for the login page. The class contains methods to interact with the page elements, such as the E-Mail input field, Password input field, and Submit button, as shown in Fig. 1, Fig. 2, and Fig. 3, respectively.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2076%2F0%2AptICNt_cftHdjIrb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2076%2F0%2AptICNt_cftHdjIrb.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Fig. 1&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2024%2F0%2AhC4XvwqE5FkVEU48.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2024%2F0%2AhC4XvwqE5FkVEU48.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Fig. 2&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2052%2F0%2AZ6SX3kELu7Lf8D-I.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2052%2F0%2AZ6SX3kELu7Lf8D-I.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Fig. 3&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It uses the &lt;a href="https://www.lambdatest.com/blog/webdriverwait-in-selenium-c-sharp/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriverWait &lt;/a&gt;class to wait for the page elements to be present and clickable before interacting with them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F0%2A-RiASwOOdbAKva5B.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F0%2A-RiASwOOdbAKva5B.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;@property&lt;/em&gt; decorator is used to define methods that behave like properties. In this case, the properties &lt;em&gt;email&lt;/em&gt;, &lt;em&gt;password&lt;/em&gt;, and &lt;em&gt;submit_button&lt;/em&gt; are defined using the &lt;em&gt;@property&lt;/em&gt; decorator. These properties are then used in the &lt;em&gt;login()&lt;/em&gt; method to interact with the page elements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2356%2F0%2AiElpRzMuTgPlrGYo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2356%2F0%2AiElpRzMuTgPlrGYo.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;login()&lt;/em&gt; method uses the &lt;em&gt;read_config()&lt;/em&gt; function from the &lt;em&gt;config_reader&lt;/em&gt; module to read the login credentials from the test_config.ini file. It then sends the email and password values to the respective input fields using the &lt;em&gt;send_keys()&lt;/em&gt; method and clicks the submit button using the &lt;em&gt;click()&lt;/em&gt; method.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Run your &lt;a href="https://www.lambdatest.com/puppeteer?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Puppeteer testing&lt;/a&gt;  scripts instantly on 50+ browser and OS combinations using the LambdaTest cloud.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;File: test_login.py&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The test_login.py file contains the test that tests the login feature using &lt;a href="https://www.lambdatest.com/learning-hub/python-unittest?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Python unittest&lt;/a&gt; and Selenium.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import unittest
from selenium import webdriver
from pages.login_page import LoginPage
from utils.config_reader import read_config
import time


class TestLogin(unittest.TestCase):
   def setUp(self):
       self.driver = webdriver.Firefox()
       self.driver.get(read_config('WEBSITE', 'url'))
       self.driver.maximize_window()


   def tearDown(self):
       self.driver.quit()


   def test_login(self):
       login_page = LoginPage(self.driver)
       login_page.login()
       time.sleep(5)


if __name__ == '__main__':
      unittest.main()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AIZNidF9aFxZSBd1B.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AIZNidF9aFxZSBd1B.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we import the necessary modules, including the unittest module for creating tests, the &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; module for controlling the browser, the LoginPage class from the login_page file, and the read_config function from the config_reader file in utils for reading configuration data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2040%2F0%2AC95Bvoa7UZEc8zGI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2040%2F0%2AC95Bvoa7UZEc8zGI.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This class defines a test that uses &lt;em&gt;setUp()&lt;/em&gt; to initialize the Firefox driver, open the website URL and maximize the window. &lt;em&gt;tearDown()&lt;/em&gt; is used to close the driver after the test has run.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AZJXoZOEz8q42nI4v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AZJXoZOEz8q42nI4v.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;test_login()&lt;/em&gt; method instantiates the &lt;em&gt;LoginPage&lt;/em&gt; class and logs in using the &lt;em&gt;login()&lt;/em&gt; method.&lt;/p&gt;

&lt;p&gt;Now we can run our test using the command in our terminal.&lt;/p&gt;

&lt;p&gt;python3 -m unittest&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the tests are executed, the login instantiates the &lt;em&gt;LoginPage&lt;/em&gt; class and logs in. Have a quick glimpse.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AU29JuwCDjG8bXGCr.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AU29JuwCDjG8bXGCr.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;In this Selenium with Java tutorial, you will learn everything you need to know to kick start your journey in Selenium &lt;a href="https://www.lambdatest.com/blog/selenium-with-java/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing Java&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Use Case 2: Managing testing on different environments
&lt;/h2&gt;

&lt;p&gt;QA Engineer, working on a web application with different environments for development, staging, and production, has different URLs and API keys. To perform the application testing, we need to execute tests on all three environments.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[DEV]
url = https://dev.lambdatest.com
api_key = abcdef123456


[STAGING]
url = https://staging.lambdatest.com
api_key = abcdef123456


[PROD]
url = https://lambdatest.com
api_key = abcdef123456
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We use the environment name as a section header and list the key-value pairs specific to each environment under it. When we need to run tests in a specific environment, we can load the appropriate section and use the values in our test scripts.&lt;/p&gt;

&lt;p&gt;For example, in our use case 1, if we wanted to use the URL of our website in the staging environment, we would modify our setUp method as follows.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class TestLogin(unittest.TestCase):
   def setUp(self):
       self.driver = webdriver.Firefox()
       self.driver.get(read_config(STAGING, 'url'))
       self.driver.maximize_window()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can modify it depending on the environment in which we want to run our tests. We can also modify the &lt;em&gt;setUp&lt;/em&gt; method to run the test in several environments using a loop.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class TestLogin(unittest.TestCase):
   def setUp(self):
      self.driver = webdriver.Firefox()
      self.driver.maximize_window()


      environments = ['TEST', 'STAGING', 'PROD']
      for env in environments:
          self.driver.get(read_config(env, 'url'))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this modified &lt;em&gt;setUp&lt;/em&gt; method, first initialize the driver and maximize the window.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Aqr2qOyhJtJ4IsY2a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Aqr2qOyhJtJ4IsY2a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, we define a list of environments in which we want to run the test.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AJCVEMDykfYb0vkY8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AJCVEMDykfYb0vkY8.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;React is a javascript-based mobile app development framework. Learn how to use Appium and Jest for &lt;a href="https://www.lambdatest.com/blog/test-react-native-apps-on-ios-and-android/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;react native automation testing tools&lt;/a&gt; for apps on iOS and Android.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We loop over each environment and call the &lt;em&gt;read_config&lt;/em&gt; function with the current environment and the key URL to get the corresponding URL value from the Python config file. Finally, we call self.driver.get with the URL value to navigate to the corresponding page in the current environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Au9ddQhNlqqDtDWNU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Au9ddQhNlqqDtDWNU.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This way, the test will run in each of the specified environments, and the URL value will be read from the corresponding Python config file for each environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Case 3: Browser Management through Configuration
&lt;/h2&gt;

&lt;p&gt;Let’s try to get more out of the Python ConfigParser library by using it for an even more interesting use case. We will add a new configuration that will allow us to switch our tests from one browser to another or to run them in the main browsers without having to change them each time.&lt;/p&gt;

&lt;p&gt;To add a new configuration to change the browser, we can modify the test_config.ini file to include a new section for BROWSER with a key-value pair for the browser to be used:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[WEBSITE]
url = https://ecommerce-playground.lambdatest.io/index.php?route=account/login


[LOGIN]
email = test@test.lambdatest.com
password = lambdatest_password


[BROWSER]
name = Edge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can then modify the setUp() method in &lt;em&gt;test_login.py&lt;/em&gt; to read the browser name from the test_config.ini file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   def setUp(self):
       browser_name = read_config('BROWSER', 'name')
       if browser_name.lower() == 'chrome':
           self.driver = webdriver.Chrome()
       elif browser_name.lower() == 'firefox':
           self.driver = webdriver.Firefox()
       elif browser_name.lower() == 'edge':
           self.driver = webdriver.Edge()
       else:
           raise ValueError('Invalid browser name')
       self.driver.get(read_config('WEBSITE', 'url'))
       self.driver.maximize_window()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This modification allows us to specify which browser to use in the test_config.ini file and then use that value to initialize the appropriate driver in the &lt;em&gt;setUp()&lt;/em&gt; method.&lt;/p&gt;

&lt;p&gt;With these modifications, we can run our tests in different browsers by simply changing the value of the name key in the BROWSER section of the test_config.ini file.&lt;/p&gt;

&lt;p&gt;Note that we can also use this approach to run the tests in multiple browsers by reading a list of browser names from the test_config.ini file and then initializing the corresponding drivers in a loop.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;In this Selenium with Java tutorial, you will learn everything you need to know to kick start your journey in Selenium &lt;a href="https://www.lambdatest.com/blog/selenium-with-java/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing using java.&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Test Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here is a GIF that showcases how tests are executed in multiple browsers by reading a list of browser names from the test_config.ini file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A8AjzeFU5OIo_xINo.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A8AjzeFU5OIo_xINo.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Case 4: Parallel Testing on LambdaTest
&lt;/h2&gt;

&lt;p&gt;Digital experience platforms like LambdaTest facilitate automated Selenium testing using Python on an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online browser farm&lt;/a&gt; of 3000+ real browsers and OS combinations, enabling developers and QA teams to carry out &lt;a href="https://www.lambdatest.com/python-web-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Python web automation&lt;/a&gt; at scale. The platform supports various &lt;a href="https://www.lambdatest.com/blog/top-python-frameworks-for-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Python testing frameworks&lt;/a&gt; such as pytest, Robot, and Behave, providing flexibility to the users.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/SqQ8SugRDos"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can also Subscribe to the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=video" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automated browser testing,&lt;/a&gt; &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing,&lt;/a&gt; &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress E2E testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;Visit our support documentation to &lt;a href="https://www.lambdatest.com/support/docs/python-with-selenium-running-python-automation-scripts-on-lambdatest-selenium-grid/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=support_doc" rel="noopener noreferrer"&gt;get started with Selenium Python testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To run tests on LambdaTest, we need to add the LambdaTest credentials to our configuration file. We can add a new section for LAMBDATEST with keys for the username and access_key. You can find the same from the &lt;a href="https://accounts.lambdatest.com/dashboard?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Automation Dashboard.&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, learn what is &lt;a href="https://www.lambdatest.com/learning-hub/regression-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Regression testing&lt;/a&gt;, its importance, types, and how to perform it.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AYStGlj28na3z5H05.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AYStGlj28na3z5H05.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We also need to add the browser &amp;amp; OS combinations we want to run our parallel tests to our configuration file. To do this, we add a BROWSER_OS_LIST section.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[BROWSER_OS_LIST]
safari_latest_mac = {"browserName": "safari", "browser_Version": "latest", "platformName": "macOS Catalina"}
edge_latest_win10 = {"browserName": "MicrosoftEdge", "browser_Version": "latest", "platformName": "Windows 10"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let’s also modify our config_reader.py file by adding a new function that can take a section as an argument and return all the key-value pairs in that section as a dictionary.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def read_config_section(section):
   config = configparser.ConfigParser()
   config.read('config/test_config.ini')
   return config[section]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now we need to modify our test_login.py file to be able to run our test in the browser and OS combinations defined in our configuration file.&lt;/p&gt;

&lt;p&gt;Here is what the code should look like now:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import unittest
from selenium import webdriver
from pages.login_page import LoginPage
from utils.config_reader import read_config, read_config_section
import time , json
from selenium.webdriver.edge.options import Options as EdgeOptions




class TestLogin(unittest.TestCase):
   def setUp(self):
      browser_os_list = read_config_section('BROWSER_OS_LIST')
      self.drivers = []
      for browser_os in browser_os_list.values():




          lt_options = {
          "user": read_config('LAMBDATEST', 'username'),
          "accessKey": read_config('LAMBDATEST', 'access_key'),
          "build": "Python Configparser Tutorial",
          "name": "Python Configparser Tutorial",
          "platformName": json.loads(browser_os)["platformName"],
          "w3c": True,
          "browserName": json.loads(browser_os)["browserName"],
          "browserVersion": json.loads(browser_os)["browser_Version"],
          "selenium_version": "4.8.0"
          }




          browser_options = EdgeOptions()
          browser_options.set_capability('LT:Options', lt_options)

          driver = webdriver.Remote(
              command_executor="http://hub.lambdatest.com:80/wd/hub",
              options=browser_options)




          driver.get(read_config('WEBSITE', 'url'))
          driver.maximize_window()
          self.drivers.append(driver)




   def tearDown(self):
      for driver in self.drivers:
          driver.quit()




  def test_login(self):
      for driver in self.drivers:
          login_page = LoginPage(driver)
          login_page.login()
          time.sleep(10)




if __name__ == '__main__':
  unittest.main()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, learn &lt;a href="https://www.lambdatest.com/learning-hub/regression-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;what is Regression testing&lt;/a&gt;, its importance, types, and how to perform it.&lt;/strong&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; We imported the &lt;em&gt;read_config_section&lt;/em&gt; function that we had defined in the config_reader module and then imported JSON, a built-in Python library for working with JSON data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2068%2F0%2ADmXsrQELzVwgSJEa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2068%2F0%2ADmXsrQELzVwgSJEa.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; In the setUp method, we initialize the test environment. We start by reading the configuration section named ‘BROWSER_OS_LIST’ using the &lt;em&gt;read_config_section&lt;/em&gt; function. This section contains a dictionary of operating systems and browsers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2328%2F0%2ArswzYxGplzU-eGF5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2328%2F0%2ArswzYxGplzU-eGF5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We then initialize an empty list called self.drivers to store the WebDriver instances for each browser. Next, we iterate through each value (browser operating system) in the browser_os_list dictionary.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; lt_options = {
          "user": read_config('LAMBDATEST', 'username'),
          "accessKey": read_config('LAMBDATEST', 'access_key'),
          "build": "Python Configparser Tutorial",
          "name": "Python Configparser Tutorial",
          "platformName": json.loads(browser_os)["platformName"],
          "w3c": True,
          "browserName": json.loads(browser_os)["browserName"],
          "browserVersion": json.loads(browser_os)["browser_Version"],
          "selenium_version": "4.8.0"
          }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Inside the loop, we create a dictionary called lt_options. This dictionary contains the configuration options required for running tests on the LambdaTest platform. The values for &lt;em&gt;“user”&lt;/em&gt; and &lt;em&gt;“accessKey”&lt;/em&gt; are read from the configuration using the read_config function.&lt;/p&gt;

&lt;p&gt;Other values such as &lt;em&gt;“platformName”&lt;/em&gt;, &lt;em&gt;“browserName”&lt;/em&gt;, and &lt;em&gt;“browserVersion”&lt;/em&gt; are extracted from the &lt;em&gt;browser_os variable&lt;/em&gt;, which is expected to be a JSON string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2328%2F0%2AKR_zW_mrl6mLIVFp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2328%2F0%2AKR_zW_mrl6mLIVFp.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We create an instance of &lt;em&gt;EdgeOptions&lt;/em&gt; and assign it to the *browser_options *variable. We then set the capability named ‘LT:Options’ with the lt_options dictionary.&lt;/p&gt;

&lt;p&gt;Next, we create a webdriver.Remote instance, which represents a &lt;a href="https://www.lambdatest.com/blog/selenium-remotewebdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;remote WebDriver&lt;/a&gt;. The &lt;em&gt;command_executor *parameter specifies the URL of the Selenium hub provided by LambdaTest, and the options parameter is set to the *browser_options&lt;/em&gt; we created earlier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AGD1iYcFG0vkMAJtV.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AGD1iYcFG0vkMAJtV.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We use the get method of the driver instance to navigate to the URL of the website under test. The URL is retrieved from the configuration using the &lt;em&gt;read_config&lt;/em&gt; function.&lt;/p&gt;

&lt;p&gt;Then, we maximize the browser window using the &lt;em&gt;maximize_window&lt;/em&gt; method of the driver. Finally, we add the driver instance to the self.drivers list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;em&gt;tearDown()&lt;/em&gt; method, we have added a loop that goes through the list of WebDriver instances and calls the &lt;em&gt;quit()&lt;/em&gt; method for each of them to close the browser window and free up system resources.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AatoIRZHTmhjnUPVL.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AatoIRZHTmhjnUPVL.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finally, in our test case, we have added another for loop, which is used to iterate on the self.drivers list for each instance of webdriver, an instance of the &lt;em&gt;LoginPage&lt;/em&gt; class is created.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def test_login(self):
      for driver in self.drivers:
          login_page = LoginPage(driver)
          login_page.login()
          time.sleep(10)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Test Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Attached are the screenshots where a test case loop is added to iterate on the self-driver list.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2506%2F0%2Ahoec0FLau51Dpuiy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2506%2F0%2Ahoec0FLau51Dpuiy.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2516%2F0%2ARm5RN7zeCw86-UMb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2516%2F0%2ARm5RN7zeCw86-UMb.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Are you eager to master &lt;a href="https://www.lambdatest.com/python-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Python automation testing?&lt;/a&gt; Embarking on a &lt;a href="https://www.lambdatest.com/certifications/selenium-python-101?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=certification" rel="noopener noreferrer"&gt;Selenium Python 101 certification&lt;/a&gt; program is an excellent choice to jumpstart your journey towards becoming an automation testing expert while enhancing your Python skills. By enrolling in this program, you’ll lay a strong foundation for effectively harnessing Selenium Python in your testing endeavors.&lt;/p&gt;

&lt;p&gt;This certification program not only equips you with essential knowledge but also paves the path toward a prosperous career in the dynamic field of automation testing. Get ready to establish a solid groundwork and unlock endless possibilities in the world of Selenium Python.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Which are the most wanted &lt;a href="https://www.lambdatest.com/blog/automation-testing-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated testing tools&lt;/a&gt; in 2023 that have climbed the top of the ladder so far?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, the Python ConfigParser module is a powerful tool that allows developers to read and write configuration files easily. It provides a simple and intuitive interface for parsing and accessing the configuration values and supports various file formats, such as .ini and .cfg.&lt;/p&gt;

&lt;p&gt;With Python ConfigParser, developers can easily customize their applications and make them more flexible and adaptable to various scenarios. By following best practices like separating the configuration data from the application code and encrypting sensitive information, developers can ensure the security and robustness of their applications.&lt;/p&gt;

&lt;p&gt;Overall, Python ConfigParser is a valuable tool for any developer and is a great way to streamline the process of managing application configurations. Using Python ConfigParser to read configuration settings from an external file can make &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug_01&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt;more efficient, flexible, and secure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions (FAQs)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is the best way to write Python config file?
&lt;/h3&gt;

&lt;p&gt;Writing a separate file with Python code is the simplest way to create configuration files. You could choose to name it databaseconfig.py. Then, to prevent unintentionally uploading it, you might add the line *config.py to your. gitignore file.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to use config YAML file in Python?
&lt;/h3&gt;

&lt;p&gt;The &lt;em&gt;yaml.dump()&lt;/em&gt; method, which takes a Python object and a file reference as inputs, can be used to write data to the YAML file.&lt;/p&gt;

</description>
      <category>python</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>OKRs for QA : How Objectives and Key Results Can Help Improve Quality and Collaboration</title>
      <dc:creator>JoliveHodehou</dc:creator>
      <pubDate>Wed, 03 May 2023 08:27:21 +0000</pubDate>
      <link>https://forem.com/testmuai/okrs-for-qa-how-objectives-and-key-results-can-help-improve-quality-and-collaboration-54n1</link>
      <guid>https://forem.com/testmuai/okrs-for-qa-how-objectives-and-key-results-can-help-improve-quality-and-collaboration-54n1</guid>
      <description>&lt;p&gt;In today’s fast-paced software development environment, quality assurance (QA) teams are under immense pressure to ensure that the software products they release meet the highest quality standards.&lt;/p&gt;

&lt;p&gt;However, many QA teams struggle to keep up with this demand, leading to a decrease in product quality and a breakdown in collaboration between teams. This is where Objectives and Key Results (OKRs) come into play. OKRs are a powerful tool that can help QA teams focus on what’s important and align their efforts with the overall goals of the organization.&lt;/p&gt;

&lt;p&gt;By setting clear and measurable objectives, and tracking progress towards those objectives through key results, QA teams can improve their performance, increase collaboration with other teams, and ultimately deliver higher-quality software products.&lt;/p&gt;

&lt;p&gt;In this article, we will explore the benefits of OKRs for QA teams and provide practical tips for implementing OKRs to improve quality and collaboration in your organization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Get a head start on your&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/cicd-test-case-template?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may03_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;CI/CD test cases&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;with our pre-built template for automated testing. Explore this comprehensive list of test cases and scenarios.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is an OKR and how does it work?
&lt;/h3&gt;

&lt;p&gt;Key Objectives and Results (OKR) is a management approach that defines objectives and tracks the results or key outcomes of those objectives to assess progress. It is often used in companies to align teams and individuals with the organization’s goals.&lt;br&gt;&lt;br&gt;
The framework is designed to promote transparency, accountability, and continuous improvement by regularly reviewing progress toward objectives and adjusting as necessary.&lt;/p&gt;

&lt;p&gt;This framework is widely used across various teams and departments, including Quality Assurance (QA) teams. Defining effective OKRs for QA teams is crucial for ensuring that the team is aligned with the overall company goals and is working towards improving the quality of the product or service being offered.&lt;/p&gt;

&lt;p&gt;Typically, OKRs are defined over a period of time, such as a quarter or a year. However, in this article, we will focus on OKRs per sprint. This variation of the OKR framework is specifically designed for agile teams that work in sprints. It involves setting goals and measuring progress against those goals in a shorter time frame, typically a one- to four-week sprint.&lt;/p&gt;

&lt;p&gt;Here is an overview of how OKRs per sprint works :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sprint Planning&lt;/strong&gt;: At the beginning of each sprint, the team sets specific high-level goals for the sprint that are aligned with the overall organizational strategy. These goals should be ambitious, achievable, and measurable within the sprint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Define Key Results&lt;/strong&gt;: For each objective, the team defines specific, measurable key results that will indicate progress toward the objective. The key results must be quantitative, achievable, and measurable within the sprint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Assign responsibilities&lt;/strong&gt;: Team members assign responsibilities for each objective and key result. This ensures that everyone knows their responsibilities and can work together to achieve the desired results.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Progress Tracking&lt;/strong&gt;: Throughout the sprint, the team monitors progress on key objectives and outcomes. Weekly check-ins and progress reports ensure that everyone is on track and adjust the focus if necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sprint Review&lt;/strong&gt;: At the end of the sprint, the team evaluates the results and reflects on what went well and what didn’t. This allows for future goal-setting and continuous improvement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Discover the top 50+ essential&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/flutter-testing-test-case-template?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may03_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Flutter test cases&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;to ensure your mobile applications are bug free prior to their release. Download our comprehensive template now.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The importance of OKRs for QA teams
&lt;/h3&gt;

&lt;p&gt;OKRs can be a vital tool for QA teams looking to improve their performance and deliver greater value to the organization. By setting specific and measurable objectives, QA teams can focus their efforts on the most critical areas, such as process optimization, bug detection, timing, quality, and communication.&lt;/p&gt;

&lt;p&gt;OKRs help to promote transparency and collaboration, which is essential for QA teams working closely with product developers and other stakeholders. By measuring progress towards their objectives, QA teams can identify areas for improvement, make adjustments to their approach, and ensure that they are making a meaningful contribution to the organization’s success. Additionally, OKRs provide a framework for accountability, as each objective is assigned to a team member who is responsible for its delivery.&lt;/p&gt;

&lt;p&gt;This accountability ensures that each member of the team is focused on achieving the goals that are most important to the organization, leading to greater alignment and improved performance.&lt;/p&gt;

&lt;p&gt;OKRs can be a powerful tool for QA teams looking to optimize their processes, improve the quality of their work, and ensure that they are delivering value to the organization.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting effective OKRs for QA teams
&lt;/h3&gt;

&lt;p&gt;Setting effective OKRs for QA is critical to ensuring that the team’s efforts align with the organization’s overall strategy and are focused on delivering high-quality products or services.&lt;/p&gt;

&lt;p&gt;Defining OKRs for QA teams by sprint can help teams focus on specific goals, increasing their chances of achieving them. We will discuss best practices for defining effective OKRs for sprint QA teams.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Align with the sprint goal&lt;/strong&gt;: The QA team’s objectives should be aligned with the sprint goal. The objectives should support the sprint’s mission and contribute to the sprint’s success.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Be specific and measurable&lt;/strong&gt;: The objectives should be specific and measurable, with clear key results that can be tracked and evaluated. This allows the team to assess their progress towards achieving their objectives within the sprint and make adjustments as necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Be challenging yet achievable&lt;/strong&gt;: The objectives should be challenging enough to motivate the team but achievable enough to avoid demotivation due to unrealistic goals within the sprint time frame.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Involve the team in the process&lt;/strong&gt;: Involving the team in the process of defining the objectives can increase their buy-in and commitment toward achieving the objectives per sprint. It also helps ensure that the objectives are realistic and achievable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Learn 43 excellent&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/salesforce-test-cases?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may03_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;salesforce test cases&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;by reading this guide. Every significant test case will be covered in detail in this guide, along with how to set up your Salesforce testing.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Implementing OKRs for QA teams
&lt;/h3&gt;

&lt;p&gt;Implementing OKRs for sprint-based QA teams is a strategic approach that can help align the team’s efforts with the organization’s overall goals and increase their chances of delivering high-quality products or services in a short time frame. However, integrating OKRs into existing QA processes and workflows can be challenging. Successful implementation of OKRs for QA teams by sprint requires starting small with a pilot project, tying the goals to sprint-specific QA metrics, aligning them with existing QA processes, communicating them to the team and stakeholders, reviewing and adjusting them at the end of each sprint, and providing the necessary resources.&lt;/p&gt;

&lt;p&gt;To begin, it is essential to start small and pilot the approach before expanding it. This can be done by setting up OKRs for a small team or a specific project within a sprint, which allows for testing the approach and making adjustments before rolling it out to the entire QA team. In addition, linking goals to sprint-specific QA metrics, such as the number of test cases executed, the percentage of bugs identified and resolved, and the time to complete the test phase, helps track progress toward the goals and identify areas for improvement.&lt;/p&gt;

&lt;p&gt;It is also critical to align OKRs with existing QA processes and workflows to ensure that they are seamlessly integrated and do not disrupt existing processes during the sprint. This can be accomplished by working with QA teams to identify existing processes, understand how they work within the sprint, and link goals to those processes. In addition, communication is essential to ensure that everyone is aligned with the sprint goals and values and understands how OKRs contribute to the success of the sprint. Finally, reviewing and adjusting the OKRs at the end of each sprint based on the performance achieved, as well as providing the necessary resources, such as time, tools, and training, can increase the chances of achieving the goals within the sprint timeframe.&lt;/p&gt;

&lt;p&gt;Implementing OKR for sprint QA teams is a strategic approach that requires careful planning and execution to ensure success. Starting small, linking objectives to sprint-specific QA metrics, aligning them with existing QA processes, communicating them to the team and stakeholders, reviewing and adjusting them at the end of each sprint, and providing the necessary resources are essential steps to integrating OKRs into existing QA processes and workflows.&lt;br&gt;&lt;br&gt;
By following these steps, QA teams can successfully meet their sprint goals, improve the quality of their work, and contribute to the overall strategy of the organization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Read this tutorial about&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/servicenow-test-case-template?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may03_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;ServiceNow Test cases&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;, to know what it is, it’s benefits, types and test cases.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Examples of effective OKRs for QA teams
&lt;/h3&gt;

&lt;p&gt;OKRs can be defined at both the team and individual levels, allowing each team member to contribute to the overall goals. In this section, we will provide examples of effective OKRs for sprint quality assurance teams, focusing on both team and individual goals.&lt;/p&gt;

&lt;h3&gt;
  
  
  Team-level examples of effective OKRs for sprint quality assurance teams include:
&lt;/h3&gt;

&lt;p&gt;1. Validate all critical flows of the new payment gateway in staging&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A9Alf5Aqva04vvXeY.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A9Alf5Aqva04vvXeY.png" alt="image" width="800" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Key Result 1: Execute 100% of the payment gateway test cases in staging within sprint W1&lt;br&gt;&lt;br&gt;
Key Result 2: Ensure all identified bugs in the payment gateway are fixed before the end of sprint W1&lt;/p&gt;

&lt;p&gt;2. Increase automation testing coverage for the mobile app&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Ad-k9QQzVGprwsYlq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Ad-k9QQzVGprwsYlq.png" alt="image" width="800" height="196"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Key Result 1: Implement automated test scripts for all new features in the mobile app within sprint W2&lt;br&gt;&lt;br&gt;
Key Result 2: Achieve at least 70% test automation coverage for the mobile app by the end of sprint W2&lt;/p&gt;

&lt;h3&gt;
  
  
  Individual-level examples of effective OKRs for sprint quality assurance team members include:
&lt;/h3&gt;

&lt;p&gt;1. Improve manual testing efficiency&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AbQ7mzbYgzxRauh4J.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AbQ7mzbYgzxRauh4J.png" alt="image" width="800" height="174"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Key Result 1: Reduce the time taken to execute a specific manual test suite by 50% within sprint W3&lt;br&gt;&lt;br&gt;
Key Result 2: Identify and implement at least one new manual testing technique to improve overall testing efficiency within sprint W3&lt;/p&gt;

&lt;p&gt;2. Enhance exploratory testing skills&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AsKI8g8kGcb7Gvjzz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AsKI8g8kGcb7Gvjzz.png" alt="image" width="800" height="184"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Key Result 1: Conduct at least 5 successful exploratory testing sessions within sprint W4&lt;br&gt;&lt;br&gt;
Key Result 2: Share at least one new exploratory testing approach with the team during the sprint W4 retrospective meeting.&lt;/p&gt;

&lt;p&gt;By defining effective OKRs for sprint quality assurance teams, QA professionals can focus on specific goals, increase their chances of achieving them, and contribute to the overall success of the organization.&lt;/p&gt;

&lt;h3&gt;
  
  
  Impact of OKRs on QA
&lt;/h3&gt;

&lt;p&gt;OKRs can have a significant impact on the achievement of QA goals by establishing clear objectives and measurable key results that are aligned with the overall business strategy. Using OKRs in QA offers several benefits such as prioritizing and optimizing efforts, determining which resources to allocate, and measuring progress.&lt;/p&gt;

&lt;p&gt;Many companies have had success using OKRs to improve their QA processes. For example, Google has used OKRs to improve product quality, while LinkedIn has used OKRs to improve customer satisfaction. In all of these cases, OKRs helped align teams around common goals, prioritize efforts, and improve overall company performance.&lt;/p&gt;

&lt;p&gt;However, it is essential to emphasize that the use of OKRs requires a carefully developed approach that is monitored and adjusted according to the company’s overall strategy and the specific needs of the organization. OKRs must be tailored to each company or team to ensure their effectiveness.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Discover the top 45 essential&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/vercel-test-case-template?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may03_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Vercel test cases&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;along with its importance, types and usage for better understanding.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Measuring progress and success with OKRs
&lt;/h3&gt;

&lt;p&gt;To track progress and measure success with OKRs per sprint for this objective, the first step is to break down the objective into measurable key results that can be tracked throughout the sprint. The two key results for this objective are:&lt;/p&gt;

&lt;p&gt;Execute 100% of the payment gateway test cases in staging within sprint W1&lt;br&gt;&lt;br&gt;
Ensure all identified bugs in the payment gateway are fixed before the end of sprint W1&lt;/p&gt;

&lt;p&gt;Once the key results are defined, the team can start tracking their progress towards each key result throughout the sprint. To do this, they can use a spreadsheet or other tracking tool to record the current status of each key result, any updates or notes on progress, and any changes to targets or priorities.&lt;/p&gt;

&lt;p&gt;For the first key result, the team can track the percentage of payment gateway test cases that have been executed in staging during the sprint, and compare it to the target of 100%. This will help them to identify whether they are on track to meet their objective of validating all critical flows of the new payment gateway in staging. They can update their progress regularly and adjust their approach if needed to ensure that they stay on track to achieve this key result.&lt;/p&gt;

&lt;p&gt;For the second key result, the team can track the number of identified bugs in the payment gateway, and the percentage of those bugs that have been fixed before the end of the sprint. They can compare this to the target of fixing all identified bugs before the end of the sprint, and adjust their approach if needed to ensure that they meet this target. They can also prioritize bug fixes based on their impact on the critical flows of the payment gateway to ensure that the most important issues are addressed first.&lt;/p&gt;

&lt;p&gt;Throughout the sprint, it’s important to review progress toward each key result regularly (e.g. weekly or bi-weekly) to identify any areas where the team is falling behind and take action to get back on track. For example, if the team is not on track to execute 100% of the test cases in staging within the first week, they may need to adjust their testing strategy or prioritize their testing efforts differently to ensure that they meet their target.&lt;/p&gt;

&lt;p&gt;At the end of the sprint, the team can review their progress towards each key result and determine whether they have achieved their overall objective of validating all critical flows of the new payment gateway in staging. If they have met both key results, they can consider the sprint success and move on to the next set of objectives for the next sprint. If they have not met one or both key results, they can use this information to inform their approach in the next sprint and adjust their tactics or targets as needed.&lt;/p&gt;

&lt;p&gt;Overall, by breaking down objectives into measurable key results and tracking progress towards those key results throughout the sprint, teams can use OKRs to track progress and measure success per sprint. By regularly reviewing progress, adjusting their approach, and staying focused on their goals, teams can ensure that they make progress toward their objectives and continue to improve over time.&lt;/p&gt;

&lt;p&gt;It’s important to note that the follow-up process for tracking progress and measuring success with OKRs per sprint can be adjusted based on the objectives and key results being tracked. There is no universal way to do this, as different objectives may require different tracking methods or tools, and different key results may have different levels of complexity and require different levels of attention.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bonus: Tools for introducing OKRs into your QA team
&lt;/h3&gt;

&lt;p&gt;Here are some tools that can help you introduce OKRs into your QA team:&lt;/p&gt;

&lt;p&gt;Weekdone: &lt;a href="https://weekdone.com/%EF%BF%BCThis" rel="noopener noreferrer"&gt;https://weekdone.com/&lt;br&gt;&lt;br&gt;
This&lt;/a&gt; is a great tool for setting and tracking OKRs. It allows you to set goals and assign key results to individual team members. You can also monitor progress and receive weekly reports on how well your team is doing.&lt;/p&gt;

&lt;p&gt;Google Sheets: &lt;a href="https://www.google.com/sheets/about/%EF%BF%BCYou" rel="noopener noreferrer"&gt;https://www.google.com/sheets/about/&lt;br&gt;&lt;br&gt;
You&lt;/a&gt; can use Google Sheets to create a simple OKR template that your team can fill in. You can customize the template to fit your team’s specific needs and goals.&lt;/p&gt;

&lt;p&gt;Asana: &lt;a href="https://asana.com/%EF%BF%BCThis" rel="noopener noreferrer"&gt;https://asana.com/&lt;br&gt;&lt;br&gt;
This&lt;/a&gt; project management tool can be used to create OKRs for your QA team. You can assign tasks and monitor progress, and Asana also offers a variety of reporting options.&lt;/p&gt;

&lt;p&gt;Trello: &lt;a href="https://trello.com/%EF%BF%BCThis" rel="noopener noreferrer"&gt;https://trello.com/&lt;br&gt;&lt;br&gt;
This&lt;/a&gt; is another project management tool that can be used to create OKRs. You can use Trello’s boards and cards to create a simple, visual representation of your team’s OKRs and monitor progress in real-time.&lt;/p&gt;

&lt;p&gt;Jira: &lt;a href="https://www.atlassian.com/software/jira%EF%BF%BCIf" rel="noopener noreferrer"&gt;https://www.atlassian.com/software/jira&lt;br&gt;&lt;br&gt;
If&lt;/a&gt; your team already uses Jira for bug tracking and project management, you can use it to set and track OKRs as well. Jira offers various customization options, and you can create custom fields and workflows to fit your team’s needs.&lt;/p&gt;

&lt;p&gt;Remember, the tool you choose is not as important as the process you establish for setting and tracking your team’s OKRs. The key is to find a tool that works for your team and to establish a clear and consistent process for setting and tracking your goals.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Learn 37 excellent&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/wix-test-case-templates?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may03_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Wix test cases&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;for testing Wix websites by reading this guide. Every significant test case will be covered in detail in this guide, along with how to set up your Wix website testing.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Integrating objectives and key results (OKRs) into quality assurance (QA) processes can have a significant impact on improving quality and collaboration. By setting clear objectives and measurable key results, QA teams can focus on achieving specific goals that align with the overall business strategy.&lt;/p&gt;

&lt;p&gt;One of the key benefits of using OKRs in QA is that they help prioritize and streamline efforts. By setting key objectives and outcomes, QA teams can determine where to focus, where to allocate resources, and how to measure progress. This ensures that QA efforts are aligned with broader corporate goals and objectives.&lt;/p&gt;

&lt;p&gt;Another benefit of using OKRs in QA is that they promote collaboration and transparency. By setting common goals and key outcomes, QA teams can work together toward a common goal and ensure that everyone is on the same page. This breaks down silos and promotes a culture of teamwork and accountability.&lt;/p&gt;

&lt;p&gt;However, it is important to note that OKRs are not a quick fix. To be effective, OKRs must be carefully developed, monitored and adjusted over time. Quality assurance teams must also ensure that their OKRs are aligned with the overall business strategy and that they measure the right things.&lt;/p&gt;

&lt;p&gt;In summary, integrating OKRs into QA can be an effective way to improve quality and collaboration. By setting clear goals and measurable key outcomes, QA teams can focus their efforts and ensure that they are aligned with broader business goals. However, it is important to approach OKRs with caution and ensure they are tailored to your organization’s specific needs and context.&lt;/p&gt;

</description>
      <category>improvequality</category>
      <category>collaboration</category>
      <category>automationtesting</category>
    </item>
    <item>
      <title>How To Generate XML Reports In pytest?</title>
      <dc:creator>JoliveHodehou</dc:creator>
      <pubDate>Thu, 13 Apr 2023 08:38:55 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-generate-xml-reports-in-pytest-53h1</link>
      <guid>https://forem.com/testmuai/how-to-generate-xml-reports-in-pytest-53h1</guid>
      <description>&lt;p&gt;Many organizations have an automated test suite running in integration and continuous delivery systems but fail to effectively utilize the results generated at the end of the test. Without proper analysis and documentation, it becomes challenging to distinguish valuable information from irrelevant data.&lt;/p&gt;

&lt;p&gt;The true benefit of &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automating testing&lt;/a&gt; lies not only in its ability to serve as documentation in the development process but also in its ability to increase &lt;a href="https://www.lambdatest.com/learning-hub/test-coverage?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test coverage&lt;/a&gt;, ensure the quality of the software, and help identify and fix bugs early in the development cycle.&lt;/p&gt;

&lt;p&gt;Additionally, having clear and detailed test results can also aid in the overall development process by providing insight into areas of the code that may require further attention or optimization.&lt;/p&gt;

&lt;p&gt;Therefore, effective &lt;a href="https://www.lambdatest.com/learning-hub/test-reports?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test reporting&lt;/a&gt; is important and will ensure that all data at the end of your tests are properly collected and transformed into usable information. These test results can bring great benefits to a development team by providing insight into areas of the code that may require further attention or optimization. It also ensures that bugs are identified and fixed early in the development cycle, increasing the overall quality and efficiency of the software development process.&lt;/p&gt;

&lt;p&gt;In this blog on generating XML reports in pytest, we will first briefly discuss pytest, a popular &lt;a href="https://www.lambdatest.com/blog/top-5-python-frameworks-for-test-automation-in-2019/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Python testing framework&lt;/a&gt;. Pytest allows for easy and efficient testing of Python code and is widely used in the development community. After discussing pytest, we will delve into the benefits of test reporting and how to generate XML reports in pytest.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;In this &lt;a href="https://www.lambdatest.com/xcuitest" rel="noopener noreferrer"&gt;XCUITest&lt;/a&gt; tutorial, learn about XCUITest framework and its benefits for mobile automation testing. Take a look at how XCUITest works and see how to use it to test your mobile applications.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Importance of Test Reporting
&lt;/h3&gt;

&lt;p&gt;When you start to run automated tests in your pipeline daily, you encounter different challenges. This may be due to some change in product behavior or flaws. The test report is a critical component for the QA team to analyze and perform their role effectively. It helps them evaluate the testing process and identify any issues that need to be addressed.&lt;/p&gt;

&lt;p&gt;The test report is a key element of a &lt;a href="https://www.lambdatest.com/blog/automation-testing-frameworks/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation framework&lt;/a&gt;, as it plays an essential role in effectively analyzing test results. Having a test report helps you build more robust test automation suites. The efficiency with which your test report is implemented plays an important role in the overall success of your automation efforts.&lt;/p&gt;

&lt;p&gt;Test reports help better document the product under development and provide valuable information for stakeholders to make decisions. This can result in faster time-to-market, improved return on investment, faster bug resolution, faster developer velocity, and increased visibility across the board.&lt;/p&gt;

&lt;p&gt;By providing clear and detailed information about the results of automated tests, test reports can help to ensure the quality and reliability of the software while also improving the efficiency and effectiveness of the development process.&lt;/p&gt;

&lt;h3&gt;
  
  
  XML vs HTML in Test Reporting
&lt;/h3&gt;

&lt;p&gt;Test reports are an essential part of any test automation framework, providing developers with detailed information about the results of automated tests. One popular format for test reports is XML, which stands for Extensible Markup Language. XML is a markup language used to organize and label the different parts of a document, making it easy to read and understand for both humans &amp;amp; machines.&lt;/p&gt;

&lt;p&gt;Unlike HTML (Hypertext Markup Language), which is used to format and display data in a web browser, XML is designed to store and transport data. It allows for the creation of custom tags and self-describing languages, making it highly flexible and adaptable to various systems. XML also has a standard and clear structure, ensuring data integrity and exchange.&lt;/p&gt;

&lt;p&gt;When choosing a format for test reports, it is important to consider your project’s specific needs and requirements. XML is a good choice for test reports because it is easy to read and understand and can be easily integrated into other systems.&lt;/p&gt;

&lt;p&gt;Additionally, XML reports can include detailed information about test failures and errors, making it easier to identify and fix bugs. However, if you are looking for a more visual representation of your test results, &lt;a href="https://www.lambdatest.com/blog/generating-xml-and-html-report-in-pyunit-for-test-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;HTML reporting&lt;/a&gt; may be a better choice. Ultimately, the choice of format will depend on your project’s specific needs and requirements.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Get started with this complete automation testing of &lt;a href="https://www.lambdatest.com/selenium" rel="noopener noreferrer"&gt;Selenium tutorial&lt;/a&gt;. Learn what Selenium is, its architecture, advantages and more for automated cross browser testing. Read more.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is pytest?
&lt;/h3&gt;

&lt;p&gt;Although often overlooked, testing is an essential step in the &lt;a href="https://www.lambdatest.com/learning-hub/software-development-life-cycle?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Software Development Life Cycle&lt;/a&gt; (SDLC). Python comes with its built-in testing framework called unittest. However, some developers find writing tests in unittest to be complicated. In recent years, pytest, a third-party testing framework, has gained popularity among developers for its ease of use and flexibility.&lt;/p&gt;

&lt;p&gt;Pytest is a Python testing framework designed to assist developers with writing better systems and releasing them with confidence. It requires less boilerplate code, making test suites more readable and easy to maintain. A simple assert statement is used, rather than the assertSomething methods of unittest, making it easier to write and understand tests.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/_bm3wIu3xTg"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can also Subscribe to the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=youtube" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress E2E testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;The binding system simplifies the setting and removal of the test state, keeping tests organized and reliable. A functional approach allows for more modular tests, and the large ecosystem of community-maintained plugins allows for the easy addition of functionality. &lt;a href="https://www.lambdatest.com/blog/end-to-end-tutorial-for-pytest-fixtures-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Pytest Fixtures&lt;/a&gt; are also provided, which allows for shared setup and cleanup code across tests, making the tests more maintainable and efficient.&lt;/p&gt;

&lt;p&gt;Overall, its ease of use and flexibility make pytest an excellent choice for improving the quality and reliability of code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test Environment Setup
&lt;/h3&gt;

&lt;p&gt;This section of the blog on generating XML reports in pytest will cover the process of configuring a test environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up pytest
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;This section of the blog on generating XML reports in pytest is intended for readers who may not be familiar with setting up pytest. If you are already familiar with the process, feel free to skip this section.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The installation of pytest is simple. If you have cloned the repository, it is already installed, and you can skip this step. If you have not cloned the repository, follow these steps:&lt;/p&gt;

&lt;p&gt;Make sure you have Homebrew on your machine because we will use a macOS operating system in this tutorial on generating XML reports in pytest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Type the following command in your terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install pipenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The pipenv installation should look like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AadA0eaW6dkpTNfIO.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AadA0eaW6dkpTNfIO.png" alt="image" width="800" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Creation of Pipfile in an empty directory. This file is essential for using Pipenv. It tracks your project’s dependencies if you need to reinstall them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
pytest = "*"
selenium = "*"

[requires]
python_version = "*"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The python_version parameter is the version of the base interpreter you specified when creating a new pipenv environment.&lt;/p&gt;

&lt;p&gt;The packages section is where you can list the packages required for your project. “*” is for installing the latest stable versions of the packages.&lt;/p&gt;

&lt;p&gt;When writing this blog on generating XML reports in pytest, the latest versions of pytest and Selenium are pytest 7.1.2 and 4.2.2, respectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your terminal, go to the directory and install the latest stable versions of the pytest and Selenium packages with the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Pipenv Install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AzFW4FTsZuxXmzegU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AzFW4FTsZuxXmzegU.png" alt="image" width="800" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This blog post demonstrates how to run tests using pytest and the LambdaTest Selenium Grid. However, it’s possible to perform these tests locally by installing the latest WebDriver version for the desired browser or by using &lt;a href="https://www.lambdatest.com/blog/webdrivermanager-in-selenium/" rel="noopener noreferrer"&gt;WebDriverManager&lt;/a&gt;. In fact, WebDriverManager is also a thing of the past after the support for Selenium Manager was available in Selenium v4.6 (and above).&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1603288968925044737-302" src="https://platform.twitter.com/embed/Tweet.html?id=1603288968925044737"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1603288968925044737-302');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1603288968925044737&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Get started with this complete automation testing of &lt;a href="https://www.lambdatest.com/selenium" rel="noopener noreferrer"&gt;selenium guide&lt;/a&gt;. Learn what Selenium is, its architecture, advantages and more for automated cross browser testing. Read more.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now let’s add some code to demo how to find an element by index in Selenium WebDriver for Python from our Selenium-controlled browser.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to generate test reports using pytest in XML?
&lt;/h3&gt;

&lt;p&gt;Now that our project is ready let’s create our test suite. Our test suite will include three test scenarios&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/DpfLjB84EQU"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;test_cart.py for test scenario 1.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;test_cart.py for test scenario 2.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;test_cart.py for test scenario 3.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is what the structure of our project should look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AOXwx0dchzK5326hl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AOXwx0dchzK5326hl.png" alt="image" width="245" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each of our test cases will contain test scenarios.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Scenario 1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Test Case 1- View cart (PASSED)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to “&lt;a href="https://ecommerce-playground.lambdatest.io/%E2%80%9C" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.io/“&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the View Cart button.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Test Case 2: Add a product to the cart (FAILED)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to “&lt;a href="https://ecommerce-playground.lambdatest.io/%E2%80%9C" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.io/“&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on a product.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the product to the cart.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This second test case is expected to fail because of the usage of invalid locator for locating the requisite product on the page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Scenario 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Test Case 1: Login with valid credentials (PASSED)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to “&lt;a href="https://ecommerce-playground.lambdatest.io/%E2%80%9C" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.io/“&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the button My account.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the email address.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the password.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the Login button.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Test Scenario 3&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Test Case 1: Perform a search (PASSED)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to “&lt;a href="https://ecommerce-playground.lambdatest.io/%E2%80%9C" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.io/“&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the keyword “iphone” in the search field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the Search button.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Implementation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pytest
import time
from selenium import webdriver
from selenium.webdriver.common.by import By


@pytest.mark.usefixtures('driver')
class TestCart():


 def test_view_cart(self, driver):
   driver.get("https://ecommerce-playground.lambdatest.io/")
   cart_button = driver.find_element(By.XPATH, '//*[@id="entry_217825"]/a/div[1]')
   cart_button.click()


 def test_add_to_cart(self, driver):
   driver.get("https://ecommerce-playground.lambdatest.io/")
   product = driver.find_element(By.XPATH, 'INVALID XPATH')
   product.click()


   add_to_cart_button = driver.find_element(By.XPATH, '//*[@id="entry_216842"]/button')
   time.sleep(5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Code Walkthrough
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AL5vRjtIA0cB6T-0W.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AL5vRjtIA0cB6T-0W.png" alt="image" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The script contains two test methods, &lt;em&gt;test_view_cart&lt;/em&gt;, and &lt;em&gt;test_add_to_cart&lt;/em&gt;, which are decorated with the &lt;em&gt;@pytest.mark.usefixtures(‘driver’)&lt;/em&gt; decorator.&lt;/p&gt;

&lt;p&gt;This tells pytest to run the driver fixture before running these test methods.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AcQbUmOl5nnpWj858.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AcQbUmOl5nnpWj858.png" alt="image" width="800" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;test_view_cart&lt;/em&gt; method navigates to &lt;a href="https://ecommerce-playground.lambdatest.io/" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.io/&lt;/a&gt; using the &lt;em&gt;driver.get()&lt;/em&gt; method and then locates the Cart button using the &lt;em&gt;driver.find_element()&lt;/em&gt; method and the By class’s &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/" rel="noopener noreferrer"&gt;XPATH&lt;/a&gt; attribute. It then clicks on the Cart button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AbP2b5NFUqhGso_uZ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AbP2b5NFUqhGso_uZ.png" alt="image" width="800" height="293"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;test_add_to_cart&lt;/em&gt; method also goes to the &lt;a href="https://ecommerce-playground.lambdatest.io/" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.io/&lt;/a&gt; page, then tries to locate a product using an invalid XPATH. It should then locate the add to cart button and click it.&lt;/p&gt;

&lt;p&gt;It also contains a &lt;em&gt;time.sleep(5)&lt;/em&gt; statement, which pauses the execution of the script for 5 seconds before moving on to the next step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note:&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;It is also interesting to note that the script uses an invalid XPATH to locate a product, so this test case will fail because the script will not find any items with this XPATH&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test your website or web app online for iOS browser compatibility. Perform seamless cross browser testing on the latest &lt;a href="https://www.lambdatest.com/test-on-iphone-simulator" rel="noopener noreferrer"&gt;iPhone tester&lt;/a&gt; Simulator. Try for free.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pytest
import time
from selenium import webdriver
from selenium.webdriver.common.by import By


@pytest.mark.usefixtures('driver')
class TestLogin():


 def test_valid_credentials(self, driver):
   driver.get("https://ecommerce-playground.lambdatest.io/")
   account_button = driver.find_element(By.XPATH, '//*[@id="widget-navbar-217834"]/ul/li[6]/a/div/span')
   account_button.click()


   time.sleep(5)


   email_field = driver.find_element(By.NAME, "email")
   email_field.send_keys("email@email.com")


   password_field = driver.find_element(By.NAME, "password")
   password_field.send_keys("email")




   login_button = driver.find_element(By.XPATH, '//*[@id="content"]/div/div[2]/div/div/form/input[1]')
   login_button.click()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This script navigates to the &lt;a href="https://ecommerce-playground.lambdatest.io/" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.io/&lt;/a&gt; page, then it finds the account button using the provided XPATH, clicks it, and waits for 5 seconds.&lt;/p&gt;

&lt;p&gt;After that, it finds the email and password fields using their name attributes and enters the hardcoded values of &lt;a href="mailto:email@email.com"&gt;&lt;em&gt;email@email.com&lt;/em&gt;&lt;/a&gt; and &lt;em&gt;email&lt;/em&gt;, respectively.&lt;/p&gt;

&lt;p&gt;Finally, it finds the login button using the provided XPATH and clicks on it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By


@pytest.mark.usefixtures('driver')
class TestSearch():


 def test_valid_search(self, driver):
   driver.get("https://ecommerce-playground.lambdatest.io/")
   search_field = driver.find_element(By.NAME, "search")
   search_field.send_keys("iphone")
   submit_button = driver.find_element(By.XPATH, '//*[@id="search"]/div[2]/button')
   submit_button.click()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;test_valid_search&lt;/em&gt; method navigates to the &lt;a href="https://ecommerce-playground.lambdatest.io/" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.io/&lt;/a&gt; page. Then, it locates the search field using the &lt;em&gt;driver.find_element()&lt;/em&gt; method and the &lt;em&gt;By&lt;/em&gt; class’s &lt;em&gt;NAME&lt;/em&gt; attribute and sends keys “iphone” to it.&lt;/p&gt;

&lt;p&gt;After that, it locates the submit button using the &lt;a href="https://www.lambdatest.com/blog/findelement-and-findelements-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;find element method in Selenium&lt;/a&gt; and the By class’s &lt;em&gt;XPATH&lt;/em&gt; attribute. The click method in Selenium is then used to &lt;a href="https://www.lambdatest.com/blog/selenium-click-button-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;click on the button element&lt;/a&gt; on the page.&lt;/p&gt;

&lt;p&gt;Now that all our test cases are implemented let’s run our tests using LambdaTest Selenium Grid.&lt;/p&gt;

&lt;p&gt;LambdaTest is a digital experience testing platform that allows developers and QAs to perform &lt;a href="https://www.lambdatest.com/python-web-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Python web automation&lt;/a&gt; on over 3000 real browsers and platform combinations. It supports various Python-based testing frameworks, including pytest, for conducting &lt;a href="https://www.lambdatest.com/selenium-python-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium Python testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Visit our support documentation to g&lt;a href="https://www.lambdatest.com/support/docs/python-with-selenium-running-python-automation-scripts-on-lambdatest-selenium-grid/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;et started with Selenium Python testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here are steps you can follow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to the LambdaTest website and log in if you already have an account, or create one if you don’t have one yet.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AkhZGy4WKRAwI9DyR.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AkhZGy4WKRAwI9DyR.png" alt="image" width="800" height="477"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Once logged in, navigate to the automation page by clicking Automation on the left sidebar of your screen.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A6znk3JowCUo3v-Vs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A6znk3JowCUo3v-Vs.png" alt="image" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To use pytest with LambdaTest Grid, you need LambdaTest credentials (i.e., username and access key). To get the credentials, click the “Access Key” button on the right side of your screen.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AZQSNSf9N8iWoJBn0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AZQSNSf9N8iWoJBn0.png" alt="image" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s add a &lt;a href="http://conftest.py" rel="noopener noreferrer"&gt;conftest.py&lt;/a&gt; file to the root of our project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from os import environ

import pytest
from selenium import webdriver
from selenium.webdriver.remote.remote_connection import RemoteConnection

@pytest.fixture(scope='function')
def driver(request):
   desired_caps = {}

   browser = {
       "platform": "Windows 10",
       "browserName": "chrome",
       "version": "latest"
   }

   username = "YOUR_USERNAME"
   access_key = "YOUR_ACCESS_KEY"

   desired_caps.update(browser)
   test_name = request.node.name
   build = environ.get('BUILD', "Generate - Test Report")
   tunnel_id = environ.get('TUNNEL', False)

   selenium_endpoint = "@hub.lambdatest.com/wd/hub"&amp;gt;http://{}:{}@hub.lambdatest.com/wd/hub".format(username, access_key)
   desired_caps['build'] = build
   desired_caps['name'] = test_name
   desired_caps['video'] = True
   desired_caps['visual'] = True
   desired_caps['network'] = True
   desired_caps['console'] = True
   caps = {"LT:Options": desired_caps}

   executor = RemoteConnection(selenium_endpoint)
   browser = webdriver.Remote(
       command_executor=executor,
       desired_capabilities=caps
   )
   yield browser

   def fin():
       if request.node.rep_call.failed:
           browser.execute_script("lambda-status=failed")
       else:
           browser.execute_script("lambda-status=passed")
           browser.quit()

   request.addfinalizer(fin)

@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
   # this sets the result as a test attribute for LambdaTest reporting.
   # execute all other hooks to obtain the report object
   outcome = yield
   rep = outcome.get_result()

   # set a report attribute for each phase of a call, which can
   # be "setup", "call", "teardown"
   setattr(item, "rep_" + rep.when, rep)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Test Execution
&lt;/h3&gt;

&lt;p&gt;Run your pytest tests with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipenv run python -m pytest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the execution of the tests, you should have a summary in your console of the execution of your tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Ac-2trCMAy1Y5hWK0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Ac-2trCMAy1Y5hWK0.png" alt="image" width="800" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On your &lt;a href="https://accounts.lambdatest.com/dashboard/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Automation Dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A8fXI5uWh8PbwW8sS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A8fXI5uWh8PbwW8sS.png" alt="image" width="800" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;A complete tutorial on &lt;a href="https://www.lambdatest.com/learning-hub/retesting" rel="noopener noreferrer"&gt;retesting &lt;/a&gt;that sheds light on its features, importance, pros and cons, and how to perform it.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Generate an XML Report in pytest
&lt;/h3&gt;

&lt;p&gt;To generate an XML report in pytest, you can use the pytest-xml plugin. This plugin will generate an XML file containing the test results, which can be read by other tools for further analysis.&lt;/p&gt;

&lt;p&gt;Here’s how you can use the pytest-xml plugin:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First, install the plugin using pip:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipenv install pytest-xml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Next, run your pytest tests with the –junitxml flag to specify the path of the XML file where the results will be saved:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipenv run python -m pytest -v --junitxml="path/to/report.xml"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The XML report will be generated at the specified path. You can open the file in a text editor or view it using a tool capable of reading XML files, such as a web browser.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AQ1qo7S-sXvhbx200.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AQ1qo7S-sXvhbx200.png" alt="image" width="258" height="323"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s open our &lt;em&gt;result.xml&lt;/em&gt; file in a browser&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AFeGbSCIi-Drkf9-e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AFeGbSCIi-Drkf9-e.png" alt="image" width="800" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our test report in an XML file, we can find some information through tags.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;testsuite:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A4VjeuDMPcQVxvMwy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A4VjeuDMPcQVxvMwy.png" alt="image" width="800" height="586"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This tag indicates our test suite. We can find attributes such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;name: The name of the test suite&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;errors: The number of errors found after the execution of the test suite&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;failures: the number of test cases that failed after the test suite was executed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;skipped: the number of test cases that were not executed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;tests: the number of test cases that our test suite contains&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;time: the number of times the test suite was executed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;timestamp: the time at which the report was generated&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;testcase:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A3XZizZIAwJtR28Dv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A3XZizZIAwJtR28Dv.png" alt="image" width="800" height="463"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;classname: The name of the test case class&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;name: The name of the test case&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;time: The execution time of the test case&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We also have in the &lt;em&gt;failure&lt;/em&gt; tag the reason for the failure of the test case test_add_to_cart.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AuAeqZynstOyHCONs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AuAeqZynstOyHCONs.png" alt="image" width="800" height="205"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re looking to become an expert in automation testing, enrolling in a &lt;a href="https://www.lambdatest.com/certifications/selenium-python-101?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium Python 101 certification&lt;/a&gt; program is a great way to kick-start your journey toward becoming an automation testing expert and improving your Python skills. It will help you establish a solid groundwork for utilizing Selenium Python in testing and pave the way for a prosperous career in this domain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Run your &lt;a href="https://www.lambdatest.com/jestautomation" rel="noopener noreferrer"&gt;jest &lt;/a&gt;automation tests in massive parallel across multiple browser and OS combinations with LambdaTest, Read more.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/selenium-pytest-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium pytest tutorial&lt;/a&gt;, we have seen the importance of a test report in a test automation project and how to generate XML reports in pytest framework. We started by configuring the test environment in Selenium using pytest and discovered the pytest-xml plugin that permitted us to generate an XML report in pytest.&lt;/p&gt;

&lt;p&gt;We also saw the execution of the code on a Selenium cloud grid like LambdaTest.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed reading this article on how to generate XML reports in pytest?&lt;/p&gt;

</description>
      <category>xml</category>
      <category>pytest</category>
      <category>automationtesting</category>
      <category>cloudtesting</category>
    </item>
    <item>
      <title>Testing Microservices: A Quick Start Guide</title>
      <dc:creator>JoliveHodehou</dc:creator>
      <pubDate>Fri, 24 Mar 2023 04:46:20 +0000</pubDate>
      <link>https://forem.com/testmuai/testing-microservices-a-quick-start-guide-5epf</link>
      <guid>https://forem.com/testmuai/testing-microservices-a-quick-start-guide-5epf</guid>
      <description>&lt;p&gt;During the last few years, applications have grown to host millions of users and produce a large volume of data. People using these applications expect fast responses and 24/7 availability. For applications to be fast and available, they must respond quickly to the increased load.&lt;/p&gt;

&lt;p&gt;One way to do this is to use a &lt;a href="https://www.lambdatest.com/blog/design-patterns-for-micro-service-architecture/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;microservices architecture&lt;/a&gt; because, in a monolithic application, the main problem is the difficulty of scaling the application. The resulting application has a very large code base and poses maintainability, deployment, and modification problems.&lt;/p&gt;

&lt;p&gt;Testing today’s environments is more complex than a few years ago. The transition to distributed environments such as microservices has created complexity, overhead, and friction in testing. Testing requires a lot of preparation, infrastructure building, and maintenance because many services communicate asynchronously.&lt;/p&gt;

&lt;p&gt;​​In this testing microservices guide, you will learn what microservices architecture involves, how it compares to other software architecture models, and the technologies that make it possible. You’ll also learn about the challenges you’ll face when testing microservices in how best to evaluate their merits.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Microservices architecture?
&lt;/h3&gt;

&lt;p&gt;Basically, microservice architecture is a software development method that aims to break down an application to isolate key functions, each of which is called a “service”.&lt;/p&gt;

&lt;p&gt;These services are designed to be responsive to a specific and unique business need, for example, order management, shipping service, payments, or notifications. In addition, they are independent and modular, allowing each to be developed and deployed without affecting the others.&lt;/p&gt;

&lt;p&gt;This type of architecture is the opposite of monolithic architecture, built as a single autonomous unit. Microservices are more and more used in companies, including the largest ones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Which are the most wanted&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/automation-testing-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;automation testing tools&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;that have climbed the top of the ladder so far? Let’s take a look.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How does Microservices architecture work?
&lt;/h3&gt;

&lt;p&gt;Microservice applications are composed of several small applications, each of which handles an individual application function. The services communicate with other services as necessary to perform their functions.&lt;/p&gt;

&lt;p&gt;Today, most cloud applications that expose a REST/GraphQL interface are built using microservices.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AGhOm_N-XuR2aA4Mw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AGhOm_N-XuR2aA4Mw.png" alt="image" width="705" height="650"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Monolithic vs Microservices architecture
&lt;/h3&gt;

&lt;p&gt;The monolithic architecture versus the microservices architecture has two major differences at a high level:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Monolithic architecture is a single, large, executable application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Microservices is a set of loosely decoupled services to support larger application deployments.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Microservices architecture offers a different approach to software development. With cloud deployment technologies, API management, integration technologies, and microservices monitoring, microservices provide an agile and efficient way to deploy large, complex enterprise applications.&lt;/p&gt;

&lt;p&gt;The big difference is that your monolithic application is disassembled into a set of independent services, which are developed, deployed, and maintained separately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform browser testing on the most powerful t&lt;/em&gt;&lt;/strong&gt;&lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;est automation cloud&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;infrastructure. Leverage LambdaTest automation testing for faster, reliable and scalable experience on cloud.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Monolithic architecture
&lt;/h3&gt;

&lt;p&gt;When starting a project, it is easy to use this architecture because it is easy to develop. It is easy to test, and deployment can be done very simply. But this simple approach has a limit in terms of size and complexity. As the size of the application increases, there are many disadvantages.&lt;/p&gt;

&lt;p&gt;The size of the application can slow down the start-up time. You have to redeploy the whole application with each update, and continuous deployment is also difficult.&lt;/p&gt;

&lt;p&gt;As far as reliability is concerned, monolithic applications have significant problems. If one of the components has a bug, it will halt the whole application and process.&lt;/p&gt;

&lt;p&gt;As technologies develop rapidly and new technologies are invented, these applications have a high barrier to adoption. As changes in frameworks or languages affect the whole application, they are extremely costly and time-consuming.&lt;/p&gt;

&lt;h3&gt;
  
  
  Microservice architecture
&lt;/h3&gt;

&lt;p&gt;Microservices architecture represents a paradigm shift from monolithic architecture. Microservices decentralize software development and allow agile methodologies to be applied, which speeds up testing and deployment.&lt;/p&gt;

&lt;p&gt;Let’s look at the benefits of microservices to help you understand what makes microservices so attractive.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance:&lt;/strong&gt; Microservices allow for the development of language-independent applications. This means that teams can build applications in the language best suited to that type of application. One team may use a more suitable language to build an order management application’s backend, while another may use a different language for a payment microservice. This improves the performance of the whole system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Independency:&lt;/strong&gt; As each service can be built by a dedicated team, each team only has to worry about one part of the system. In a microservices architecture, teams are autonomous in building and deploying their service. This allows teams to work independently without fear that their changes will greatly impact the system’s overall state. It also fits well with the agile philosophy of &lt;a href="https://www.lambdatest.com/learning-hub/continuous-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;continuous testing&lt;/a&gt; and delivery.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reusability:&lt;/strong&gt; Microservices allow parts of the service to be reused in other applications: if a payment functionality has already been created for one application and another need this functionality, the same microservice can be used in the latter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability:&lt;/strong&gt; Microservices are infinitely scalable horizontally, and their lightweight nature allows each service to better adapt to incoming requests. As load is introduced into the system, additional servers can be added to balance the load.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Maintainability:&lt;/strong&gt; Microservices are highly fault-tolerant. Even if one service fails, the inherently isolated nature of the architecture means that other services can be largely unaffected. Because individual services are relatively small, downtime can often be remedied quickly, as it is immediately clear which part of the service is causing the problem.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Run your&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Selenium Automation&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;Testing scripts on the LambdaTest cloud grid. Test on 3000+ desktop &amp;amp; mobile environments. Try it for free.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Despite the benefits, microservices architecture has certain challenges. Let’s look at the challenges associated with microservices architecture.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; While each service is simpler, the system as a whole is more complex. As a distributed system, care must be taken to select and configure all services and databases and then deploy each of these components independently. All the challenges of a distributed system must be considered.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Testing:&lt;/strong&gt; Having many independent services can make test writing more complex, especially when there are many dependencies between services. A mock should be used for each dependent service to test a service as a unit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data integrity:&lt;/strong&gt; Microservices have a distributed database architecture, which is a challenge for data integrity. Some business transactions, which require the update of several business functions in the application, need to update several databases belonging to different services. This requires eventual data consistency, which is more complex and less intuitive for developers.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Getting started with testing Microservices
&lt;/h3&gt;

&lt;p&gt;The &lt;a href="https://www.lambdatest.com/blog/how-to-test-a-microservice-architecture-application/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;testing process of a microservice architecture&lt;/a&gt; is very different from the usual one. The particularity of a microservice architecture is that the software is provided by several services running on the backend.&lt;/p&gt;

&lt;p&gt;As a result, we need a different and broader approach to testing, as it can be challenging to perform &lt;a href="https://www.lambdatest.com/learning-hub/integration-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;integration testing&lt;/a&gt; or to walk through the main flows during development.&lt;/p&gt;

&lt;p&gt;However, we can quickly update an individual microservice and test it without affecting the others.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A5TjPU7szdoCFONQ5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A5TjPU7szdoCFONQ5.png" alt="image" width="800" height="392"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The microservices pyramid adds two new types of tests:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Component tests.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Contract tests.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The challenges of testing Microservices
&lt;/h3&gt;

&lt;p&gt;Microservices require additional steps, such as managing multiple repositories and branches, each with its database schema.&lt;/p&gt;

&lt;p&gt;But the &lt;a href="https://www.lambdatest.com/blog/testing-challenges-related-to-microservice-architecture/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;testing challenges related to microservices architecture&lt;/a&gt; can be more profound than that.&lt;/p&gt;

&lt;p&gt;Here are some key challenges associated with testing microservices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Availability&lt;/strong&gt;: Since different teams may manage their microservices, it is difficult to secure the availability of a microservice (or, worse still, to try to find a time when all microservices are available at the same time).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fragmented and holistic testing&lt;/strong&gt;: Microservices are designed to work alone and with other loosely coupled services. This means that developers must test each component in isolation, as well as test everything together.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Knowledge gaps&lt;/strong&gt;: Especially with integration testing (which we’ll discuss later in this article), whoever is doing the testing will need to understand each service well to &lt;a href="https://www.lambdatest.com/blog/17-lessons-i-learned-for-writing-effective-test-cases/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;write test cases effectively&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Types of tests while testing Microservices
&lt;/h3&gt;

&lt;p&gt;Now, let’s take a closer look at all the &lt;a href="https://www.lambdatest.com/learning-hub/microservices-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;microservices testing&lt;/a&gt; type&lt;/p&gt;

&lt;h3&gt;
  
  
  Unit tests
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/learning-hub/unit-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Unit testing&lt;/a&gt; is a type of software testing that allows you to check the accuracy of individual modules or software components. The goal is to verify that each unit of code works correctly.&lt;/p&gt;

&lt;p&gt;At the feature development stage, developers write unit tests independently because each developer knows and understands the workings of their code better and can perform this task better than the testers.&lt;/p&gt;

&lt;p&gt;This allows you to quickly check whether the next code change has led to a regression, i.e., the appearance of errors in previously tested parts of the code. It also makes it easier to detect and eliminate such defects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Contract tests
&lt;/h3&gt;

&lt;p&gt;It is a test at the border of an external service, verifying that it meets the contract expected by consumer service.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/learning-hub/contract-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Contract testing&lt;/a&gt; is a technique for testing an integration point by isolating each microservice and checking whether the &lt;a href="https://www.lambdatest.com/blog/how-to-get-response-status-code-using-apache-httpclient/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;HTTP requests and responses&lt;/a&gt; that the microservice transmits conform to a common understanding documented in a contract.&lt;/p&gt;

&lt;p&gt;In this way, contract testing ensures that microservices can communicate.&lt;/p&gt;

&lt;h3&gt;
  
  
  Integration tests
&lt;/h3&gt;

&lt;p&gt;Integration testing checks the interactions between different modules (or classes), usually belonging to the same subsystem, to ensure that they work together as intended when providing high-level functionality.&lt;/p&gt;

&lt;p&gt;Integration tests also check that all the communication paths taken by the subsystem are correct and detect any incorrect assumptions that each module may have about how its peers are supposed to act. This type of test is considered the most critical test of the whole architecture.&lt;/p&gt;

&lt;h3&gt;
  
  
  Component tests
&lt;/h3&gt;

&lt;p&gt;A component is a microservice or set of microservices that accomplishes a role within the larger system. &lt;a href="https://www.lambdatest.com/learning-hub/component-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Component testing&lt;/a&gt; allows you to independently validate and evaluate the performance of each component of a microservice application without integrating other services.&lt;/p&gt;

&lt;p&gt;Generally, it is easier and faster to run component tests than to evaluate microservices.&lt;/p&gt;

&lt;p&gt;Since it is difficult and slow to test microservices, you need to simulate other microservices or dependencies. You can isolate the dependencies by replacing them with test duplicates or dummy servers.&lt;/p&gt;

&lt;p&gt;Modern teams adopt cloud-testing solutions like LambdaTest to perform component testing through browser testing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cross browser testing&lt;/a&gt; platforms like LambdaTest allow you to perform automated testing of components at scale over an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online browser farm&lt;/a&gt; of 3000+ browsers and operating systems. LambdaTest provides your team with a cloud-based virtual machine running a real operating system. You can perform real-time component testing of your websites or web applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Run your&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Selenium online&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;Automation Testing scripts on the LambdaTest cloud grid. Test on 3000+ desktop &amp;amp; mobile environments. Try it for free.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/pfzA5bsxf_E"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  End-to-end tests
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/learning-hub/end-to-end-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar24_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;End-to-end testing&lt;/a&gt; builds on integration testing, which in turn builds on all the other forms of testing you have learned. As the name suggests, E2E tests the business logic as an integration test process, not in isolation, but as part of the whole system.&lt;/p&gt;

&lt;p&gt;They should, in theory, simulate a real user of your application or at least perform the actions of a real user. These tests are usually the most difficult to write and consume the most development time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Microservices architecture is a software architecture model in which each task of a larger application is presented as an independent application.&lt;/p&gt;

&lt;p&gt;Microservices offer many advantages over other architectures, including easier deployments and better scalability. However, they also come with some challenges, including testing.&lt;/p&gt;

&lt;p&gt;When it comes to testing microservices, there are advantages and disadvantages to consider. On the one hand, microservices can be tested independently, making finding and fixing bugs easier. On the other hand, microservices must be tested in concert with each other, which can be more complex and time-consuming.&lt;/p&gt;

</description>
      <category>automationtesting</category>
      <category>microservices</category>
      <category>selenium</category>
      <category>cloudtesting</category>
    </item>
    <item>
      <title>Guide To Find Index Of Element In List with Python Selenium</title>
      <dc:creator>JoliveHodehou</dc:creator>
      <pubDate>Thu, 29 Dec 2022 15:37:35 +0000</pubDate>
      <link>https://forem.com/testmuai/guide-to-find-index-of-element-in-list-with-python-selenium-1ag9</link>
      <guid>https://forem.com/testmuai/guide-to-find-index-of-element-in-list-with-python-selenium-1ag9</guid>
      <description>&lt;p&gt;In an ideal world, you can test your web application in the same &lt;a href="https://www.lambdatest.com/blog/what-is-test-environment/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test environment&lt;/a&gt; and return the same results every time. The reality can be difficult sometimes when you have flaky tests, which may be due to the complexity of the web elements you are trying to perform an action on your test case.&lt;/p&gt;

&lt;p&gt;However, web elements are essential when writing automated tests. To avoid this, it is important to use the right method to find the element you are trying to act on.&lt;/p&gt;

&lt;p&gt;Finding an element using an index can help to avoid tests that produce inconsistent results. In this &lt;a href="https://www.lambdatest.com/learning-hub/python-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Python tutorial&lt;/a&gt;, we will discuss how to find index of element in list with Python using &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So, let’s get started!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Automate &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cypress testing&lt;/a&gt; and perform browser automation testing with LambdaTest. Our cloud infrastructure has 3000+ desktop &amp;amp; mobile environments. Try for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an index?
&lt;/h2&gt;

&lt;p&gt;In &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt;, an index is a numerical position of an element within a list of elements. For example, if you have a list of elements representing links on a webpage and want to select the third link, you could use an index to specify that you want to select the element at the third position in the list.&lt;/p&gt;

&lt;p&gt;An &lt;strong&gt;index&lt;/strong&gt; is defined based on specific nodes in the node set for indexing using Selenium &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;WebDriver&lt;/a&gt;. You can use the indexes to get a specific item in the list of identified locators. You can learn more about it from this blog on different &lt;a href="https://www.lambdatest.com/learning-hub/selenium-locators?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;locators in Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let’s assume that if you write an &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath&lt;/a&gt; &lt;strong&gt;//input[&lt;a class="mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;=’lambda’]&lt;/strong&gt;, which gives you five matching nodes, then you would have to use the indexing concept.&lt;/p&gt;

&lt;p&gt;For this, if the object is identified at index 1, then the XPath would be &lt;strong&gt;[//input[&lt;a class="mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;=’lambda’]][1]&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Else, if it is identified at index 2, then it would be &lt;strong&gt;(//input[&lt;a class="mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;=’lambda’])[2]&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;**Note&lt;/em&gt;&lt;em&gt;: Indexes start from 0.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let’s take an example to illustrate better.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt; LambdaTest Sign up page.&lt;/p&gt;

&lt;p&gt;On the &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest registration page&lt;/a&gt;, we have a country selection field, which is a &lt;strong&gt;select&lt;/strong&gt;. When we use the XPath &lt;strong&gt;//*[&lt;a class="mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;=”country_code”]&lt;/strong&gt; to find the element, it returns 215 nodes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh8glwy8oo1fwlz0xt627.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh8glwy8oo1fwlz0xt627.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So we will need to use the indexes to find the specific element we want to interact with. Note that in this blog on how to find index of element in list with Python, we use XPath to find our locators. You have the choice to use other methods like &lt;a href="https://www.lambdatest.com/blog/how-pro-testers-use-css-selectors-in-selenium-automation-scripts/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS Selector&lt;/a&gt; etc.&lt;/p&gt;

&lt;p&gt;Now let’s prepare our test environment. We will need to install pytest and Selenium.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to set up a test environment?
&lt;/h2&gt;

&lt;p&gt;In the section of this blog on how to find index of element in list with Python, we will learn how to set up a test environment. However, before that, let’s understand the pytest framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the pytest framework?
&lt;/h2&gt;

&lt;p&gt;Pytest is a very popular &lt;a href="https://www.lambdatest.com/blog/top-5-python-frameworks-for-test-automation-in-2019/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Python test automation framework&lt;/a&gt; (mainly used for &lt;a href="https://www.lambdatest.com/learning-hub/unit-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;unit testing&lt;/a&gt;). This highly configurable and scalable testing framework comes with a rich set of features to help you write better code for Python tests.&lt;/p&gt;

&lt;p&gt;Pytest is often described as a flexible framework with less boilerplate code than other testing frameworks. &lt;a href="https://www.lambdatest.com/blog/end-to-end-tutorial-for-pytest-fixtures-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;pytest fixtures&lt;/a&gt; provide context for tests by passing parameter names in test cases; its parameterization eliminates duplicate code for testing multiple sets of input and output, and its rewritten assert statements provide detailed output for failure causes.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/UzkuOACmBpA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Execute &amp;amp; analyse Cypress test scripts online. Deploy quality builds faster with 40+ browser versions on &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cypress cloud&lt;/a&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing the pytest framework
&lt;/h2&gt;

&lt;p&gt;To install pytest on your machine, you first need to install Pipenv.&lt;/p&gt;

&lt;p&gt;But make sure you have Homebrew on your machine because we will use a macOS operating system in this tutorial on how to find index of element in list with Python Selenium.&lt;/p&gt;

&lt;p&gt;1- Type the following command in your terminal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;brew install pipenv&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The pipenv installation should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fle0427v4mqigc0kcav9e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fle0427v4mqigc0kcav9e.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- Once you have installed it, make sure you have &lt;strong&gt;pipenv&lt;/strong&gt; installed on your machine by typing in your terminal:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pipenv&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The result should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8g25yqkwfb12udnkxi11.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8g25yqkwfb12udnkxi11.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are several other alternatives to Pipenv for package management, which can also be used like pyenv, poetry, virtualenv, autoenv, etc. However, adding them is beyond the scope of this blog on how to find index of element in list with Python Selenium.&lt;/p&gt;

&lt;p&gt;3- Creation of Pipfile in an empty directory. This file is essential for using Pipenv. It tracks your project’s dependencies if you need to reinstall them.&lt;/p&gt;

&lt;p&gt;The python_version parameter is the version of the base interpreter you specified when creating a new pipenv environment.&lt;/p&gt;

&lt;p&gt;The packages section is where you can list the packages required for your project. “*” is for installing the latest stable versions of the packages.&lt;/p&gt;

&lt;p&gt;At the time of writing this blog on how to find index of element in list with Python Selenium, the latest versions of pytest and Selenium are pytest 7.1.2 and 4.2.2, respectively.&lt;/p&gt;

&lt;p&gt;4- In your terminal, go to the directory and install the latest stable versions of the pytest and Selenium packages with the command:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pipenv Install&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxiiw71fltdc1mhajjrjb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxiiw71fltdc1mhajjrjb.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this blog on how to find index of element in list with Python Selenium, we will use the LambdaTest &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid&lt;/a&gt; with pytest to run our tests. But you could have done this locally by installing the latest version of WebDriver for the browser you want to use. You can also use WebDriverManager.&lt;/p&gt;

&lt;p&gt;Here are the download links for the most commonly used browsers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Firefox: GeckoDriver&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Chrome: ChromeDriver&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Opera: OperaDriver&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Edge: Microsoft Edge WebDriver&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Make sure you have the correct version for your browser; otherwise, it won’t work.&lt;/p&gt;

&lt;p&gt;Now let’s add some code to the demo on how to find index of element in list with Python using Selenium WebDriver from our Selenium controlled browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This Cypress automation testing tutorial will help you learn the benefits of &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cypress automation&lt;/a&gt;, and how to install Cypress and execute Cypress automation testing over scores of browsers and operating systems online.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to find index of element in list with Python Selenium?
&lt;/h2&gt;

&lt;p&gt;In this section of the Python automation testing blog on how to find index of element in list with Python, we will consider the following test scenario to download files using Selenium Python:&lt;/p&gt;

&lt;p&gt;1- Go to the &lt;a href="https://www.lambdatest.com/selenium-playground/input-form-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Playground &amp;gt; Input Form&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;2- Click on the &lt;strong&gt;Country&lt;/strong&gt; DropDown.&lt;/p&gt;

&lt;p&gt;3- Select a country (India).&lt;/p&gt;

&lt;p&gt;4- Save the selected country in a country.txt file.&lt;/p&gt;

&lt;p&gt;This is what the structure of our project should look like.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9sj8amx4lqzkamx35dgg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9sj8amx4lqzkamx35dgg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the blog, we will create a &lt;strong&gt;tests&lt;/strong&gt; folder.&lt;/p&gt;

&lt;p&gt;In Python projects, it is conventional to create a “&lt;strong&gt;tests&lt;/strong&gt;” directory under the project’s root directory to hold all the test cases.&lt;/p&gt;

&lt;p&gt;We will create a file &lt;strong&gt;test_index.py&lt;/strong&gt; in our “&lt;strong&gt;tests&lt;/strong&gt;” folder, in which we will write our test case.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff4wih2zf1uf65d3ddym2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff4wih2zf1uf65d3ddym2.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import pytest
    import time
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    @pytest.mark.usefixtures('driver')
    class TestIndex():
      def test_index(self, driver):
       driver.get("https://www.lambdatest.com/selenium-playground/input-form-demo")
       driver.find_element(By.NAME, "country").click()
      country_index = 104
       dropdown = driver.find_element(By.NAME, "country")
       option = dropdown.find_element(By.XPATH, "//select[@name='country']/option[{}]".format(country_index))
       option.click()

       with open('country.txt', 'a') as f:
          f.write(" Selected country is : "+ option.text)
          f.write('\n')
       time.sleep(3)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import pytest

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The pytest module provides a rich set of tools for constructing and running tests. In this blog on how to find index of element in list with Python Selenium, we have used unittest, but several other &lt;a href="https://www.lambdatest.com/selenium-python-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Python testing&lt;/a&gt; frameworks can be used, like Unittest, Robot, DocTest, etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import time
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python sleep() is a method of the Python time module. So, first, we must import the time module, and then we can use this method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    time.sleep(3)

    from selenium import webdriver

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will import the Selenium packages that we will use for our project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    from selenium.webdriver.common.by import By
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;selenium.webdriver&lt;/strong&gt; module provides all the WebDriver implementations. Currently, supported WebDriver implementations are Firefox, Chrome, Microsoft Edge, IE, and Remote.&lt;/p&gt;

&lt;p&gt;The By class is used to locate elements within a document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    self.driver.find_element(By.NAME, "country").click()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Automation uses locators to find elements on a page. Selenium locators are simple query strings for finding elements. They return all elements that match their query.&lt;/p&gt;

&lt;p&gt;Selenium WebDriver supports many locators: ID, Name, Class Name, CSS Selectors, XPath, Link text, Partial link text, and Tag name.&lt;/p&gt;

&lt;p&gt;Here we used Name to find the country field and clicked on the element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqnxw9mz80vr42snp5m57.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqnxw9mz80vr42snp5m57.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will notice that the different countries all have the same tagName. So we will have to use the index to choose a specific country.&lt;/p&gt;

&lt;p&gt;Indexes can also be useful in cases where the same XPath returns multiple web elements.&lt;/p&gt;

&lt;p&gt;The index is defined based on specific nodes in the node set for indexing using Selenium WebDriver. We can also reference the specific node to the index using many indexes enclosed in []. The tag name UI element contains several child elements whose tag name is &lt;strong&gt;option&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Element:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//select[@name='country']/option
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now look at the Items tab; you will see that the XPath above returns 251 elements since there are 251 countries in the drop-down list.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fetwzws4ovliz0za205zj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fetwzws4ovliz0za205zj.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s try to choose India from the list of countries:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpe492xvl3yq1iu3csoo4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpe492xvl3yq1iu3csoo4.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we know the index of the option, we save it in a variable country_index.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdxb5gdjnsmg6zjyouc44.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdxb5gdjnsmg6zjyouc44.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We then use this index to choose the country India.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqq20zmaxpbl51hr1atms.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqq20zmaxpbl51hr1atms.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We then saved the chosen country in a country.txt file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform manual or automated &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;testing web&lt;/a&gt; browsers on 3000+ browsers online. Deploy and scale faster with the most powerful cross browser testing tool online.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to find index of element in list with Python Selenium on the cloud Grid?
&lt;/h2&gt;

&lt;p&gt;To use LambdaTest Selenium Grid with pytest to perform &lt;a href="https://www.lambdatest.com/python-web-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Python web automation&lt;/a&gt;, you will need a LambdaTest account.&lt;/p&gt;

&lt;p&gt;LambdaTest is a continuous quality cloud that lets you perform &lt;a href="https://www.lambdatest.com/python-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Python automation testing&lt;/a&gt; on a reliable &amp;amp; scalable online Selenium Grid infrastructure across 3000+ real browsers and operating systems online. Furthermore, you can also cut down build times by multiple folds using parallel test execution.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WZlsHlReRww"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can also Subscribe to the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress E2E testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here are steps you can follow:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1- Navigate to the LambdaTest website and log in if you already have an account, or create one if you don’t have an account yet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwbwj9lbmbyrwau3hw1ls.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwbwj9lbmbyrwau3hw1ls.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- Once you are logged in, navigate to the automation page by clicking Automation on the left sidebar of your screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjhhnlpfh9hr9aqi9fxzk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjhhnlpfh9hr9aqi9fxzk.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- To use pytest with LambdaTest Grid, you need LambdaTest credentials (i.e. username and access key). To get the credentials, click the “Access Key” button on the right side of your screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5518wakxcyv2sre9tmoe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5518wakxcyv2sre9tmoe.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This article explains the &lt;a href="https://www.lambdatest.com/blog/emulator-vs-simulator-vs-real-device/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;emulator vs simulator&lt;/a&gt; vs real device differences, the learning of which can help you select the right mobile testing solution for your business.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;Now, let’s add a conftest.py file to the root of our project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    from os import environ

    import pytest
    from selenium import webdriver
    from selenium.webdriver.remote.remote_connection import RemoteConnection


    @pytest.fixture(scope='function')
    def driver(request):
       desired_caps = {}

       browser = {
           "platform": "Windows 10",
           "browserName": "chrome",
           "version": "latest"
       }

       username = "YOUR_USERNAME"
       access_key = "YOUR_ACCESS_KEY"

       desired_caps.update(browser)
       test_name = request.node.name
       build = environ.get('BUILD', "How To Find An Element By Index")
       tunnel_id = environ.get('TUNNEL', False)

       selenium_endpoint = "@hub.lambdatest.com/wd/hub"&amp;gt;http://{}:{}@hub.lambdatest.com/wd/hub".format(username, access_key)
       desired_caps['build'] = build
       desired_caps['name'] = test_name
       desired_caps['video'] = True
       desired_caps['visual'] = True
       desired_caps['network'] = True
       desired_caps['console'] = True
       caps = {"LT:Options": desired_caps}

       executor = RemoteConnection(selenium_endpoint)
       browser = webdriver.Remote(
           command_executor=executor,
           desired_capabilities=caps
       )
       yield browser

       def fin():
           # browser.execute_script("lambda-status=".format(str(not request.node.rep_call.failed if "passed" else
           # "failed").lower()))
           if request.node.rep_call.failed:
               browser.execute_script("lambda-status=failed")
           else:
               browser.execute_script("lambda-status=passed")
               browser.quit()

       request.addfinalizer(fin)


    @pytest.hookimpl(tryfirst=True, hookwrapper=True)
    def pytest_runtest_makereport(item, call):
       # this sets the result as a test attribute for LambdaTest reporting.
       # execute all other hooks to obtain the report object
       outcome = yield
       rep = outcome.get_result()

       # set a report attribute for each phase of a call, which can
       # be "setup", "call", "teardown"
       setattr(item, "rep_" + rep.when, rep)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Test execution in the cloud
&lt;/h2&gt;

&lt;p&gt;With the various configurations set up in the conftest.py file, we are ready to run the tests.&lt;br&gt;
Run &lt;strong&gt;pipenv run python -m pytest&lt;/strong&gt;, and you should see the tests running in the terminal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnmgzliki628bwrpob8iz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnmgzliki628bwrpob8iz.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the tests have run successfully, log in to &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Automation Dashboard&lt;/a&gt; to check the status of the &lt;a href="https://www.lambdatest.com/learning-hub/test-execution?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test execution&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqonlyudtpn9ywo1ie47q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqonlyudtpn9ywo1ie47q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see that the value of the selected element is India.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhe8ct71w18xi8997bvva.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhe8ct71w18xi8997bvva.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;country.txt content is below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   Selected country is : India
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Bonus Section
&lt;/h2&gt;

&lt;p&gt;Let’s try to do something much more fun. We’ll find all the countries starting with A and save them in a &lt;strong&gt;list_country.txt&lt;/strong&gt; file. Let’s add a new function for this test case.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    def test_list_country(self, driver):
       driver.get("https://www.lambdatest.com/selenium-playground/input-form-demo")
       dropdown = driver.find_element(By.NAME, "country")
       country=dropdown.find_elements(By.XPATH, "//select[@name='country']/option")

       for i in range(2,len(country)):
         country=dropdown.find_elements(By.XPATH, "//select[@name='country']/option")
         country1=dropdown.find_element(By.XPATH, "//select[@name='country']/option[{}]".format(i))
         time.sleep(2)
         with open('list_country.txt', 'a') as f:
           f.write(" Selected country is : "+ country1.text)
           f.write('\n')

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The contents of your list_country file should look like this: list_country.txt (github.com)&lt;/p&gt;

&lt;p&gt;If you’re interested in becoming an automation testing expert and building your skills in Python, one way to get started is by earning a Selenium Python 101 certification. This will give you a strong foundation in using Selenium for testing and automation and can help you build a successful career in this field.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Need a great solution for &lt;a href="https://www.lambdatest.com/safari-browser-for-windows?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;safari for windows&lt;/a&gt;? Forget about emulators or simulators — use real online browsers. Try LambdaTest for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This concludes the tutorial on how to find index of element in list with Python Selenium. When you automate your web tests using Selenium, you may encounter elements in the DOM that have the same attributes. Indexes can help you perform different actions on a specific element.&lt;/p&gt;

&lt;p&gt;I hope this has given you a good overview of how to find index of element in list with Python Selenium. If you have any questions or comments, please leave them in the section below.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>jquery</category>
      <category>webdev</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Selenium with Python Tutorial: How to Get Current URL with Python</title>
      <dc:creator>JoliveHodehou</dc:creator>
      <pubDate>Thu, 29 Dec 2022 14:12:14 +0000</pubDate>
      <link>https://forem.com/testmuai/selenium-with-python-tutorial-how-to-get-current-url-with-python-3a9d</link>
      <guid>https://forem.com/testmuai/selenium-with-python-tutorial-how-to-get-current-url-with-python-3a9d</guid>
      <description>&lt;p&gt;If you use Selenium WebDriver, you probably know that there are many methods to perform specific actions or interact with elements on a web page. The Selenium Python module gives you the methods you need to be able to automate many tasks when working with a &lt;a href="https://www.lambdatest.com/web-browser-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;web browser online&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As a tester, you may need to know the URL of the page displayed by your Selenium-controlled web browser. This can be useful to keep track of the URL from which you have extracted certain data so that you can update this data in the automation test script. You may also need to know the current URL while making an assertion to check a keyword in the page title.&lt;/p&gt;

&lt;p&gt;You can easily get the current URL of a web page when performing &lt;a href="https://www.lambdatest.com/python-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Python automation testing&lt;/a&gt; — to do that, you just need to access the **current_url **method of the &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; object.&lt;/p&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/python-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Python tutorial&lt;/a&gt;, I will show you how to get current URL in Selenium Python using Pytest. If you are new to Pytest, you can go through this &lt;a href="https://www.lambdatest.com/learning-hub/selenium-pytest-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Pytest tutorial&lt;/a&gt; on &lt;a href="https://www.lambdatest.com/blog/selenium-python-pytest-testing-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;getting started with Pytest&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let’s get started.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Run &lt;a href="https://www.lambdatest.com/appium-mobile-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Appium&lt;/a&gt; mobile testing of native and web apps. Improve your app quality with instant access to real devices on LambdaTest. Register now for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Pytest?
&lt;/h2&gt;

&lt;p&gt;Pytest is one of the most popular &lt;a href="https://www.lambdatest.com/blog/top-python-frameworks-for-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Python test automation frameworks&lt;/a&gt; (primarily used for unit testing). It’s a highly configurable and extensible testing framework that comes with a rich set of features to help you write better code for testing in Python.&lt;/p&gt;

&lt;p&gt;Pytest is described as a scalable framework with less boilerplate code than other testing frameworks. &lt;a href="https://www.lambdatest.com/blog/end-to-end-tutorial-for-pytest-fixtures-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Pytest fixtures&lt;/a&gt; provide context for tests by passing parameter names in test cases; its parameterization eliminates duplicate code for testing multiple sets of input and output, and its rewritten assert statements provide detailed output for causes of failure.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/UzkuOACmBpA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How to set the test environment in Selenium using Pytest?
&lt;/h2&gt;

&lt;p&gt;In this section of this article on how to get current URL in Selenium Python, we will learn to set up a test environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation of Pipenv
&lt;/h2&gt;

&lt;p&gt;Before we start, we will set up a test environment. For this, please follow the steps below:&lt;/p&gt;

&lt;p&gt;1- We will install Pipenv to manage our dependencies better. Pipenv is a dependency manager for Python projects. If you’re familiar with Node.js’ npm or Ruby’s bundler, it is similar in spirit to those tools.&lt;/p&gt;

&lt;p&gt;The following command is to install pipenv on macOS. On the official pipenv website, you can see how to install it on other operating systems.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   brew install pipenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2- Once the installation is complete, enter the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    pipenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ABAyUuCKvAseUAjgy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ABAyUuCKvAseUAjgy.png" width="800" height="570"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are several other alternatives to Pipenv for package management, which can also be used like pyenv, poetry, virtualenv, autoenv, etc. However, adding them is beyond the scope of this blog.&lt;/p&gt;

&lt;p&gt;3- Creation of &lt;strong&gt;Pipfile&lt;/strong&gt; in an empty directory. This file is essential for using Pipenv. It’s used to track your project’s dependencies if you need to reinstall them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [[source]]
    name = "pypi"
    url = "https://pypi.org/simple"
    verify_ssl = true
    [packages]
    pytest = "*"
    selenium = "*"
    [requires]
    python_version = "*"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;python_version&lt;/strong&gt; parameter is the version of the base interpreter you specified when creating a new pipenv environment.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;packages&lt;/strong&gt; section is the place where you can list the packages required for your project.&lt;/p&gt;

&lt;p&gt;“*” is for installing the latest stable versions of the packages. At the time of writing this blog on how to get current URL in Selenium Python, the latest versions of Pytest and Selenium are Pytest 7.1.2 and 4.2.2, respectively.&lt;/p&gt;

&lt;p&gt;4- In your terminal, go to the directory and install the latest stable versions of the Pytest and Selenium packages with the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    pipenv install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AWx-F6r7HkJD3UUMx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AWx-F6r7HkJD3UUMx.png" width="800" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5- Download the latest WebDriver for the browser you wish to use. A WebDriver is a remote control interface that enables introspection and control of user agents. It provides a platform- and language-neutral wire protocol for out-of-process programs to instruct the behavior of web browsers remotely.&lt;/p&gt;

&lt;p&gt;The WebDriver Wire Protocol (aka “WebDriver protocol”) is an open standard that allows the software to interact with a browser as if a human was interacting with the browser.&lt;/p&gt;

&lt;p&gt;Here are the download links for the most commonly used browsers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Firefox: GeckoDriver&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Chrome: ChromeDriver&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Opera: OperaDriver&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Edge: Microsoft Edge WebDriver&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Make sure you have the correct version for your browser, otherwise it won’t work. However, you do not need a WebDriver, in case you are running your test on the &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The Selenium test configuration in the cloud is managed by a cloud-based Selenium Grid, such as LambdaTest, which will help you run Selenium tests for your web application to ensure &lt;a href="https://www.lambdatest.com/learning-hub/cross-browser-compatibility?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser compatibility&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platforms like LambdaTest allow you to perform &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt; on an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browser farm&lt;/a&gt; of over 3000+ browsers and operating systems.&lt;/p&gt;

&lt;p&gt;Now, let’s add some code to demonstrate how to get current URL in Selenium Python from our Selenium-controlled browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;a href="https://www.lambdatest.com/mobile-emulator-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Emulator online&lt;/a&gt;  from LambdaTest allows you to seamlessly test your mobile applications, websites, and web apps on mobile browsers and mobile devices.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to get current URL in Selenium Python using Pytest?
&lt;/h2&gt;

&lt;p&gt;Now that our project is ready, it is time to add our first test scenario. Here I’ve created:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;test_ecommerce_playground.py&lt;/strong&gt;” for scenario 1&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;test_selenium_playground.py&lt;/strong&gt;” for scenario 2.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is what the structure of our project should look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AMJeQlTIXX2x-DrBq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AMJeQlTIXX2x-DrBq.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Python projects, it is conventional to create a “&lt;strong&gt;tests&lt;/strong&gt;” directory under the project root directory to hold all the test cases. In this module, we simply add functions for our test cases.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AhIRDQSH3eXBMcyEN.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AhIRDQSH3eXBMcyEN.png" width="347" height="71"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’ll write page object stubs for both pages and then use them to write our test case function. In our project, I’ve created a directory called &lt;strong&gt;pages&lt;/strong&gt; right here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AOWjW_s38k-sJ1nDr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AOWjW_s38k-sJ1nDr.png" width="345" height="91"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that this directory is outside of the **tests **directory.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We also need it outside because we want this &lt;strong&gt;pages&lt;/strong&gt; directory to be a Python package.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Python packages are denoted by this &lt;strong&gt;&lt;strong&gt;init&lt;/strong&gt;.py&lt;/strong&gt; file (pronounced “dunder init”). It’s just an empty file inside a directory that says, “Hey, this is a Python package, and you can treat it as such, specifically for import statements.”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AZpQitWhf8lu0QECh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AZpQitWhf8lu0QECh.png" width="658" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s add a &lt;strong&gt;config.json&lt;/strong&gt; file to our project. It should be located at the root of our project. The &lt;strong&gt;config.json&lt;/strong&gt; is our configuration file. It allows us to define some settings or preference parameters that will be applied to our project.&lt;/p&gt;

&lt;p&gt;It contains a browser, which I have set to “Firefox,” and an implicit timeout. We have hard-coded an implicit timeout of 10 seconds for all interactions. The best way for our tests to read this configuration file will be to use a pytest fixture. You will see this later in our &lt;strong&gt;conftest.py&lt;/strong&gt; file&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Which are the most wanted &lt;a href="https://www.lambdatest.com/blog/automation-testing-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated testing tools&lt;/a&gt; that have climbed the top of the ladder so far? Let’s take a look.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Scenario 1:
&lt;/h2&gt;

&lt;p&gt;Step 1: Navigate to ‘&lt;a href="https://ecommerce-playground.lambdatest.io/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.io/&lt;/a&gt;‘&lt;br&gt;
Step 2: Search with the keyword “iPhone”.&lt;br&gt;
Step 3: Display the current URL of the page in the console.&lt;br&gt;
Step 4: Check if the search keyword is in the current URL of the page.&lt;br&gt;
Step 5: Save the current URL of the page in a urls.txt file.&lt;/p&gt;

&lt;p&gt;Let’s look at the code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ecommerce_playground.py&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
    class EcommercePlaygroundPage:
       #url
       url = 'https://ecommerce-playground.lambdatest.io/'
       #locators
       search_form = (By.NAME, "search")
       search_button = (By.CSS_SELECTOR, ".type-text")
       # Initializer
       def __init__(self, browser):
           self.browser = browser

       # Interaction methods
       def load(self):
           self.browser.get(self.url)
           self.browser.implicitly_wait(30)

       def search(self , keyword):
           search_form = self.browser.find_element(*self.search_form)
           search_form.send_keys(keyword)
           search_button = self.browser.find_element(*self.search_button)
           search_button.click()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;selenium.webdriver&lt;/strong&gt; module provides all the WebDriver implementations. Currently supported WebDriver implementations are Firefox, Chrome, Microsoft Edge, IE and Remote.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;By&lt;/strong&gt; class is used to locate elements within a document.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;Keys&lt;/strong&gt; class provides methods through which you can access keys like RETURN, F1, ALT, ENTER, and more. Please read through our earlier blog on &lt;a href="https://www.lambdatest.com/blog/handling-keyboard-actions-in-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;handling keyboard actions in Selenium&lt;/a&gt; to learn more about it.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;test_ecommerce_playground.py&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   import pytest
    from pages.ecommerce_playground import EcommercePlaygroundPage
    keyword = "iPhone"
    def test_ecommerce_playground(browser):
       ecommerce_page = EcommercePlaygroundPage(browser)
       ecommerce_page.load()
       ecommerce_page.search(keyword)
       get_url = browser.current_url
       title = browser.title
       print("The current url is: "+str(get_url))
       assert "iPhone" in get_url
       with open('urls.txt', 'a') as f:
           f.write(title + " : "+ get_url)
           f.write('\n')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Execution Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Shown below is the page URL:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AO2wHb2Xdpk5sVGoR.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AO2wHb2Xdpk5sVGoR.png" width="800" height="479"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;urls.txt content is below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Search - iPhone : https://ecommerce-playground.lambdatest.io/index.php?route=product%2Fsearch&amp;amp;search=iPhone
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Through this usability testing tutorial, you will learn how &lt;a href="https://www.lambdatest.com/learning-hub/usability-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;usability testing&lt;/a&gt; is a great way to discover unexpected bugs, find what is unnecessary or unused before going any further, and have unbiased opinions from an outsider.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Scenario 2:
&lt;/h2&gt;

&lt;p&gt;Step1: Navigate to ‘&lt;a href="https://www.lambdatest.com/selenium-playground/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;https://www.lambdatest.com/selenium-playground/&lt;/a&gt;‘.&lt;br&gt;
Step 2: Click Simple Form Demo.&lt;br&gt;
Step 3: Display the current URL of the page in the console.&lt;br&gt;
Step 4: Save the current URL of the page to a urls.txt file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FileName — selenium_playground.py&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    from selenium.webdriver.common.by import By
    class SeleniumPlaygroundPage:
       #url
       url = 'https://www.lambdatest.com/selenium-playground/'
       #locators
       simple_form_demo = (By.XPATH, "//a[normalize-space()='Simple Form Demo']")
       # Initializer
       def __init__(self, browser):
           self.browser = browser
       # Interaction methods
       def load(self):
           self.browser.get(self.url)
       def simple_form(self):
           simple_form = self.browser.find_element(*self.simple_form_demo)
           simple_form.click()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;test_selenium_playground.py&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import pytest
    from pages.selenium_playground import SeleniumPlaygroundPage
    def test_selenium_playground(browser):
       playground_page = SeleniumPlaygroundPage(browser)
       playground_page.load()
       playground_page.simple_form()
       # Get the current url of the page in a variable
       get_url = browser.current_url
       title = browser.title
       # Display the url in the console
       print("The current url is: "+str(get_url))
       # Save the url in a urls.txt file
       with open('urls.txt', 'a') as f:
           f.write(title + " : "+ get_url)
           f.write('\n')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Automation uses locators to find elements on a page. &lt;a href="https://www.lambdatest.com/learning-hub/selenium-locators?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium locators&lt;/a&gt; are simple query strings for finding elements. They will return all elements that match their query.&lt;/p&gt;

&lt;p&gt;Selenium WebDriver supports many types of locators — ID, Name, Class Name, CSS Selectors, XPath, Link Text, Partial Link Text, and Tag Name.&lt;/p&gt;

&lt;p&gt;Now let’s look at how to get locators for the target items we need for our test scenario.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2ALgiIUhaJJg9qAN1a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2ALgiIUhaJJg9qAN1a.png" width="800" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here I have used the Inspect Element to store the &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath&lt;/a&gt; of the &lt;strong&gt;Simple Form Demo&lt;/strong&gt; link in a variable named &lt;strong&gt;simple_form_demo&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       simple_form_demo = (By.XPATH, "//a[normalize-space()='Simple Form Demo']")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will use “&lt;strong&gt;find_element&lt;/strong&gt;“, which is called directly from the WebDriver instance, which we have named &lt;strong&gt;browser&lt;/strong&gt; in our code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       simple_form = self.browser.find_element(*self.simple_form_demo)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To locate the Simple Form Demo element, we’ll need to say &lt;strong&gt;browser.find_element&lt;/strong&gt; and we’ll pass in our simple_form_demo locator.&lt;/p&gt;

&lt;p&gt;Now you may be wondering what this asterisk is? Well, the &lt;a href="https://www.lambdatest.com/blog/findelement-and-findelements-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;find_element method in Selenium&lt;/a&gt; takes two arguments — the locator type and then the query — but &lt;strong&gt;simple_form_demo&lt;/strong&gt; is a tuple.&lt;/p&gt;

&lt;p&gt;By adding this here, I can pass my tuple, my locator, into the &lt;strong&gt;find_element&lt;/strong&gt; method. If it’s successful, it will return an object representing the &lt;strong&gt;simple_form&lt;/strong&gt; element on the page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       simple_form.click()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we will use the calls to the element objects returned by the &lt;strong&gt;find_element&lt;/strong&gt; methods. &lt;strong&gt;click()&lt;/strong&gt; allows you to click on an element. Once I have this element, I can click on it to go to the page it redirects to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      # Get the current url of the page in a variable
       get_url = browser.current_url
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;current_url&lt;/strong&gt; returns the URL of the page currently loaded in the browser. We used this WebDriver Call to store the Current URL of the page in a variable called &lt;strong&gt;get_url&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       # Save the url in a urls.txt file
       with open('urls.txt', 'a') as f:
           f.write(title + " : "+ get_url)
           f.write('\n')

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We then saved the contents of this variable in a &lt;strong&gt;urls.txt&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AaAIU0V3KYU37R7tq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AaAIU0V3KYU37R7tq.png" width="800" height="475"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After clicking on Simple Form Demo, you are redirected to this page:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2ACzCLVQjIKX0rtwOX.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2ACzCLVQjIKX0rtwOX.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Content of &lt;strong&gt;urls.txt&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Selenium Grid Online | Run Selenium Test On Cloud :&lt;br&gt;
&lt;a href="https://www.lambdatest.com/selenium-playground/simple-form-demo" rel="noopener noreferrer"&gt;https://www.lambdatest.com/selenium-playground/simple-form-demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This smoke testing tutorial covers what &lt;a href="https://www.lambdatest.com/learning-hub/smoke-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;smoke testing&lt;/a&gt; is, its importance, benefits, and how to perform it with real-time examples.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How to get current URL in Selenium Python on the cloud Grid?
&lt;/h2&gt;

&lt;p&gt;Cloud Selenium Grid provides us with an option to run tests on a range of &lt;a href="https://www.lambdatest.com/intl/en-in/virtual-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;virtual browsers&lt;/a&gt;, browser versions, and operating systems securely over the cloud. LambdaTest is one such platform that provides a secure, scalable, and super reliable cloud-based Selenium Grid infrastructure that lets you run tests at scale.&lt;/p&gt;

&lt;p&gt;LambdaTest is a cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform that allows you to run tests on an &lt;a href="https://www.lambdatest.com/online-device-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online device farm&lt;/a&gt; of 3000+ real devices running on real operating systems for mobile, desktop, and tablets. LambdaTest Selenium Grid also allows you to perform &lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WZlsHlReRww"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can also Subscribe to the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress E2E testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;To use LambdaTest Selenium Grid with Pytest to perform &lt;a href="https://www.lambdatest.com/python-web-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Python web automation&lt;/a&gt;, you will need a LambdaTest account. Here are steps you can follow:&lt;/p&gt;

&lt;p&gt;1- Navigate to the &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest website&lt;/a&gt; and log in if you already have an account, or create one if you don’t have an account yet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A93Gf6MgUZdTkxyzg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A93Gf6MgUZdTkxyzg.png" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- Once you are logged in, navigate to the automation page by clicking &lt;strong&gt;Automation&lt;/strong&gt; on the left sidebar of your screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A0Jt-GOEsKT37W7z_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A0Jt-GOEsKT37W7z_.png" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- To use Pytest with LambdaTest Grid, you need LambdaTest credentials (i.e. username and access key). To get the credentials, click the “&lt;strong&gt;Access Key&lt;/strong&gt;” button on the right side of your screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ApsX9j7mAg6dqz0Oo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ApsX9j7mAg6dqz0Oo.png" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4- Let us now save the credentials (username and access key) to environment variables LT_USERNAME and LT_ACCESS_KEY.&lt;/p&gt;

&lt;p&gt;We will create an .env file in which we will save our credentials.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    nano .env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then Paste&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    LT_USERNAME=YOUR_USERNAME
    LT_ACCESS_KEY=YOUR_ACCESS_KEY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An .env file should appear in your project once you save the changes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Ap6XYyGXTHOsvSxjq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Ap6XYyGXTHOsvSxjq.png" width="800" height="774"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You must now update your &lt;strong&gt;conftest.py&lt;/strong&gt; file as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import json
    import pytest
    import selenium.webdriver
    from os import environ
    from selenium import webdriver
    from selenium.common.exceptions import WebDriverException
    from selenium.webdriver.remote.remote_connection import RemoteConnection
    @pytest.fixture
    def config(scope='session'):

     # Read the file
     with open('config.json') as config_file:
       config = json.load(config_file)
      # Assert values are acceptable
     assert config['browser'] in ['Firefox', 'Chrome', 'Headless Chrome']
     assert isinstance(config['implicit_wait'], int)
     assert config['implicit_wait'] &amp;gt; 0

     # Return config so it can be used
     return config
    @pytest.fixture
    def browser(config):
     # Initialize the WebDriver instance
     if config['browser'] == 'Firefox':
       b = selenium.webdriver.Firefox()
     elif config['browser'] == 'Chrome':
       b = selenium.webdriver.Chrome()
     elif config['browser'] == 'Headless Chrome':
       opts = selenium.webdriver.ChromeOptions()
       opts.add_argument('headless')
       b = selenium.webdriver.Chrome(options=opts)
     else:
       raise Exception(f'Browser "{config["browser"]}" is not supported')

     # Make its calls wait for elements to appear
     b.implicitly_wait(config['implicit_wait'])

     # Return the WebDriver instance for the setup
     yield b

     # Quit the WebDriver instance for the cleanup
     b.quit()
    @pytest.fixture(scope='function')
    def browser(request):
       desired_caps = {}
       browser = {
           'LT:Options' : {
             "user" : environ.get('LT_USERNAME', None),
             "accessKey" : environ.get('LT_ACCESS_KEY', None),
             "build" : "lamdatest_build",
             "name" : "lamdatest_demo",
             "platformName" : "Windows 11",
           },
           "browserName" : "Firefox",
           "browserVersion" : "99.0",
       }
       desired_caps.update(browser)
       test_name = request.node.name
       build = environ.get('BUILD', "Sample PY Build")
       username = browser.get('LT:Options', {}).get('user')
       access_key = browser.get('LT:Options', {}).get('accessKey')
       selenium_endpoint = "@hub.lambdatest.com/wd/hub"&amp;gt;http://{}:{}@hub.lambdatest.com/wd/hub".format(username, access_key)

       executor = RemoteConnection(selenium_endpoint, resolve_ip=False)
       browser = webdriver.Remote(
           command_executor=executor,
           desired_capabilities=desired_caps
       )
       yield browser
       def fin():
           #browser.execute_script("lambda-status=".format(str(not request.node.rep_call.failed if "passed" else "failed").lower()))
           if request.node.rep_call.failed:
               browser.execute_script("lambda-status=failed")
           else:
               browser.execute_script("lambda-status=passed")
               browser.quit()
       request.addfinalizer(fin)

    @pytest.hookimpl(tryfirst=True, hookwrapper=True)
    def pytest_runtest_makereport(item, call):
       # this sets the result as a test attribute for LambdaTest reporting.
       # execute all other hooks to obtain the report object
       outcome = yield
       rep = outcome.get_result()
       # set an report attribute for each phase of a call, which can
       # be "setup", "call", "teardown"
       setattr(item, "rep_" + rep.when, rep)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use the &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Desired Capabilities Generator&lt;/a&gt; from LambdaTest to automatically generate the capability class needed to run your Selenium automation test scripts on LambdaTest’s Selenium Grid. The Selenium Capabilities Generator will provide you with the complete capability class code based on your mouse-interactions from the user interface.&lt;/p&gt;

&lt;p&gt;In our project we use &lt;a href="https://www.lambdatest.com/learning-hub/selenium-4?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium 4&lt;/a&gt;, so this is what the declaration of the Desired Selenium Capabilities class looks like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    desired_caps = {}
       browser = {
           'LT:Options' : {
             "user" : environ.get('LT_USERNAME', None),
             "accessKey" : environ.get('LT_ACCESS_KEY', None),
             "build" : "lamdatest_build",
             "name" : "lamdatest_demo",
             "platformName" : "Windows 11",
           },
           "browserName" : "Firefox",
           "browserVersion" : "99.0",
       }
       desired_caps.update(browser)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we have saved our credentials in an environment file, we made this import to be able to use them in our &lt;strong&gt;conftest.py&lt;/strong&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    from os import environ

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the tests have run successfully, log in to &lt;a href="https://automation.lambdatest.com/build?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Automation Dashboard&lt;/a&gt; to check the status of the test execution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AhNcm-97bfvaFp7PY.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AhNcm-97bfvaFp7PY.png" width="800" height="479"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Ahf30qwSYonUZ59Cg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Ahf30qwSYonUZ59Cg.png" width="800" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are looking to develop advanced, hands-on expertise in &lt;a href="https://www.lambdatest.com/selenium-python-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Python testing&lt;/a&gt; and take your career to the next level, you can take the Selenium Python 101 certification from LambdaTest.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the Selenium Python 101 certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/KeSWHW4Lx1E"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this Data driven testing tutorial, let us deep dive into what data driven testing is, its pros &amp;amp; cons, its types, &lt;a href="https://www.lambdatest.com/learning-hub/data-driven-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec29_pk&amp;amp;utm_term=pk&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;data driven testing&lt;/a&gt; in an agile environment, benefits, and their best practices.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this Selenium Python tutorial, we have seen how to get current URL in Selenium Python using the Pytest framework. We started by setting up the test environment in Selenium using Pytest and learned core methods to get the current URL in Selenium using Python. It is generally employed in cases where you require an intermediate URL from a redirect chain or need to do a series of navigations among different URLs. Finally, we saw the code execution on cloud Selenium Grid like LambdaTest.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed reading this article on how to get current URL in Selenium Python.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>tutorial</category>
      <category>python</category>
      <category>testdev</category>
    </item>
    <item>
      <title>How To Download File Using Selenium Python</title>
      <dc:creator>JoliveHodehou</dc:creator>
      <pubDate>Tue, 27 Dec 2022 10:13:52 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-download-file-using-selenium-python-1ef2</link>
      <guid>https://forem.com/testmuai/how-to-download-file-using-selenium-python-1ef2</guid>
      <description>&lt;p&gt;Although browsers such as Firefox and Chrome have made downloading files easier, these downloads depend on users visiting a website and manually clicking a download button. This can be a problem if the user is interested in downloading multiple files.&lt;/p&gt;

&lt;p&gt;By automating the task of downloading a file, you can save time and effort and focus on the features that matter. However, there are various ways to do that.&lt;/p&gt;

&lt;p&gt;The combination of Python and Selenium opens up many opportunities for automating various tasks like clicking, typing, hovering, and downloading files. Using &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-with-python/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium with Python&lt;/a&gt; can automate this process of downloading files by identifying and clicking the download button.&lt;/p&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/python-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Python tutorial&lt;/a&gt;, I will show you how to download files with &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; and Python using the &lt;a href="https://www.lambdatest.com/unittest-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;unittest testing&lt;/a&gt; framework. You could then download any type of file and save it in a specific folder.&lt;/p&gt;

&lt;p&gt;So, let’s get started!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Try an online &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium automation&lt;/a&gt; Grid to run your browser automation testing scripts. Our cloud infrastructure has 3000+ desktop &amp;amp; mobile environments. Try for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Test Environment Setup
&lt;/h2&gt;

&lt;p&gt;You need to have the unittest framework, Selenium, and the different browser drivers on our machine. In this blog on how to download file using Selenium Python, we will consider running our tests on Chrome, Firefox, and Safari.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the unittest framework?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;unittest&lt;/strong&gt; testing framework was initially inspired by JUnit and had a flavor similar to the major &lt;a href="https://www.lambdatest.com/blog/11-best-unit-testing-frameworks-for-selenium-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;unit testing frameworks&lt;/a&gt; in other languages. This is the default Python test framework provided with the Python package and, therefore, the one most developers start their tests with. It can also be used for &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation&lt;/a&gt;, collection aggregation, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing the unittest framework
&lt;/h2&gt;

&lt;p&gt;To have unittest installed on our machine, we first need to install Python.&lt;/p&gt;

&lt;p&gt;But make sure you have Homebrew on your machine because we will use a macOS operating system in this tutorial on how to download file using Selenium Python.&lt;/p&gt;

&lt;p&gt;1- Type the following command in your terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    brew install Python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Python installation should look like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AdHDGNwEyWeD_Yb0N7HXVyg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AdHDGNwEyWeD_Yb0N7HXVyg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- Once you have installed it, make sure you have Python installed on your machine by typing in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Python --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Python3 --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AaGNDodqbvinKhHcNgMVxtA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AaGNDodqbvinKhHcNgMVxtA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- Next, you need to install Selenium on our machine. To do this, we will install pip using &lt;strong&gt;get-pip.py&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Download the script from &lt;a href="https://bootstrap.pypa.io/get-pip.py" rel="noopener noreferrer"&gt;https://bootstrap.pypa.io/get-pip.py&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open a terminal/command prompt, cd to the folder containing the get-pip.py file, and run:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    python3 get-pip.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Check if pip is installed by typing in your terminal
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     pip3 --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ab_XtPYsuol3mAqkjLgAMpQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ab_XtPYsuol3mAqkjLgAMpQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4- Once pip is installed, you can install Selenium in the same way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   pip install selenium
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or depending on your permissions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   sudo pip install selenium
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Python3:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    sudo pip3 install selenium
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5- Add browser driver. WebDriver is an open source tool for automated testing of web applications on many browsers. It provides capabilities for navigating web pages, user input, executing JavaScript, and much more.&lt;/p&gt;

&lt;p&gt;We will run tests with Google Chrome, Mozilla Firefox, and Safari to download file using Selenium Python.&lt;/p&gt;

&lt;p&gt;Type the following command in your terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    brew cask install chromedriver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;ChromeDriver&lt;/strong&gt; will help us run our tests in Google Chrome. Without it, it is impossible to run Selenium test scripts in Google Chrome and automate any web application. This is why you need ChromeDriver to run test cases on the Google Chrome browser.&lt;/p&gt;

&lt;p&gt;Once the installation is complete, check if ChromeDriver is installed by typing the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    chromeDriver -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AaCz8MHwq6VjlMr4IJqPBgA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AaCz8MHwq6VjlMr4IJqPBgA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;6- Now let’s install &lt;strong&gt;GeckoDriver&lt;/strong&gt;, a web browser engine used in many applications developed by the Mozilla Foundation and the Mozilla Corporation. GeckoDriver is the link between your tests in Selenium and the Firefox browser.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    brew cask install geckodriver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check if GeckoDriver is installed by typing the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    geckodriver -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ABzaX6XRhRedM3PkCXy31Sw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ABzaX6XRhRedM3PkCXy31Sw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, installation of the browser drivers is unnecessary if the tests will be executed on a &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cloud Selenium grid&lt;/a&gt; like LambdaTest.&lt;/p&gt;

&lt;p&gt;LambdaTest is a cloud-based &lt;a href="https://www.lambdatest.com/" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform that provides you with an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browser farm&lt;/a&gt; of 3000+ browsers and operating system combinations to perform &lt;a href="https://www.lambdatest.com/learning-hub/cross-browser-compatibility?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser compatibility&lt;/a&gt; testing at scale.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WZlsHlReRww"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can also Subscribe to the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress E2E testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test on &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing tool&lt;/a&gt; Grid Cloud of 3000+ Desktop &amp;amp; Mobile Browsers.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Downloading file using Selenium Python to a specific folder
&lt;/h2&gt;

&lt;p&gt;In this section of the &lt;a href="https://www.lambdatest.com/python-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Python automation testing&lt;/a&gt; tutorial, we will consider the following test scenario to download file using Selenium Python:&lt;/p&gt;

&lt;p&gt;1- Go to the &lt;a href="https://www.lambdatest.com/selenium-playground/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Playground&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;2- Click on the &lt;strong&gt;File Download&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;3- In the &lt;strong&gt;Enter Data&lt;/strong&gt; field, enter “How to download files using Selenium &amp;amp; Python?”&lt;/p&gt;

&lt;p&gt;4- Click on the &lt;strong&gt;Generate File&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;5- Click on the &lt;strong&gt;Download&lt;/strong&gt; button to download the file Lambdainfo.txt, which should contain “How to download files using Selenium &amp;amp; Python?”&lt;/p&gt;

&lt;p&gt;This is what the structure of our project should look like.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AloNY05IiMgGCA5l7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AloNY05IiMgGCA5l7.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the blog on how to download file using Selenium Python, we will create three folders which are as follows: &lt;strong&gt;pages, tests&lt;/strong&gt;, and &lt;strong&gt;utils&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Python packages are denoted by this &lt;strong&gt;&lt;strong&gt;init&lt;/strong&gt;.py&lt;/strong&gt; file (pronounced “dunder init”). It’s just an empty file inside a directory that says, “Hey, this is a Python package, and you can treat it as such, specifically for import statements.”&lt;/p&gt;

&lt;p&gt;In our “&lt;strong&gt;utils&lt;/strong&gt;” folder, we will create a &lt;strong&gt;locators.py&lt;/strong&gt; file in which we will put our different locators.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AqkCMufLPnfO9bUSp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AqkCMufLPnfO9bUSp.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    from selenium.webdriver.common.by import By
    class SeleniumPlaygroundPageLocators(object):
       #locators
      file_download = (By.XPATH, '//li[.="File Download"]')
       data_field = (By.XPATH, '//*[@id="textbox"]')
       generate_file = (By.ID, 'create')
       download_button = (By.XPATH, '//*[@id="link-to-download"]')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Tests&lt;/strong&gt; use locators to find elements on a page. Locators are simple query strings for finding elements. They will return all elements that match their query.&lt;/p&gt;

&lt;p&gt;Selenium WebDriver supports many types of locators . Some of the most commonly used &lt;a href="https://www.lambdatest.com/learning-hub/selenium-locators?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium locators&lt;/a&gt; include — IDs, Names, Class Names, CSS Selectors, XPaths, Link Text, Partial Link Text, and Tag Name.&lt;/p&gt;

&lt;p&gt;Now let’s look at how to get locators for the target items we need for our test scenario. We have created a &lt;strong&gt;SeleniumPlaygroundPageLocators&lt;/strong&gt; class in which we have created variables for each element in which we will save our selectors for later use in our code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     file_download = (By.XPATH, '//li[.="File Download"]')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AjRSYyRROQZn0GZID.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AjRSYyRROQZn0GZID.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       data_field = (By.XPATH, '//*[@id="textbox"]')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AMBWLWicoQcbUMaUU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AMBWLWicoQcbUMaUU.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      generate_file = (By.ID, 'create')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2Aa4ik85vlzGDMi206.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2Aa4ik85vlzGDMi206.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       download_button = (By.XPATH, '//*[@id="link-to-download"]')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2Ap1PTpac69j-TId9W.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2Ap1PTpac69j-TId9W.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have also created a directory called “&lt;strong&gt;pages&lt;/strong&gt;“. In “&lt;strong&gt;pages&lt;/strong&gt;,” we will create a file &lt;strong&gt;selenium_playground_page.py&lt;/strong&gt; in which the page objects are written. To learn more about page objects, refer to our earlier blog on &lt;a href="https://www.lambdatest.com/blog/page-object-model-in-selenium-python/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Page Object Model (POM) in Selenium Python&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   from selenium.webdriver.common.keys import Keys
    from utils.locators import *
    import time
    # Page objects are written in this module.
    class Selenium_Playground_Page():

       def __init__(self, driver):
           self.locator = SeleniumPlaygroundPageLocators
           self.driver = driver

       def download(self, text):
           self.driver.find_element(*self.locator.file_download).click()
           self.driver.find_element(*self.locator.data_field).send_keys(text)
           self.driver.find_element(*self.locator.generate_file).click()
           self.driver.find_element(*self.locator.download_button).click()
           time.sleep(5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Try running your browser automation testing scripts on an online &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium automation testing&lt;/a&gt; Grid. There are over 3000 desktop and mobile environments in our cloud infrastructure. Take a free test!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    from selenium.webdriver.common.keys import Keys
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;selenium.webdriver&lt;/strong&gt; module provides all the WebDriver implementations. The &lt;strong&gt;Keys&lt;/strong&gt; class provides methods through which you can access keys. You can refer to this blog on &lt;a href="https://www.lambdatest.com/blog/how-to-use-selenium-sendkeys/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Keys&lt;/a&gt; to learn more about Keys class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    from utils.locators import *
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we import all the &lt;strong&gt;classes **in our **locators.py&lt;/strong&gt; file in the &lt;strong&gt;utils&lt;/strong&gt; folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import time
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python sleep() is a method of the Python time module. So, first, we must import the time module, and then we can use this method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    time.sleep(5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Python projects, it is common practice to create a “&lt;strong&gt;tests&lt;/strong&gt;” directory under the project’s root directory to hold all the test scenarios. In &lt;strong&gt;tests&lt;/strong&gt;, we have two files &lt;strong&gt;test_download_file.py&lt;/strong&gt; and &lt;strong&gt;conftest.py&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import unittest
    from selenium import webdriver
    class Browser(unittest.TestCase):
       def setUp(self):
           PATH = "/Users/macbookair/Desktop/how_download_files_selenium_python/download" #This path must be modified according to your OS and the directory where you want to save your file
           self.driver.get("https://www.lambdatest.com/selenium-playground/")
       def tearDown(self):
           self.driver.close()
    if __name__ == '__main__':
       unittest.main()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import unittest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The unittest module provides a rich set of tools for constructing and running tests. In this blog on how to download file using Selenium Python, we have used unittest, but several other &lt;a href="https://www.lambdatest.com/blog/top-python-frameworks-for-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Python testing frameworks&lt;/a&gt; can be used like PyTest, Robot, DocTest, etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    PATH = "/Users/macbookair/Desktop/how_download_files_selenium_python/download"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have created a &lt;strong&gt;PATH&lt;/strong&gt; variable in which we save the path we want to save the file that we will download with Selenium Python.&lt;/p&gt;

&lt;p&gt;Later we will add some code to our &lt;strong&gt;conftest.py&lt;/strong&gt; file to be able to run the tests on our different browsers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import unittest
    from tests.conftest import Browser
    from pages.selenium_playground_page import *
    # I am using python unittest for asserting cases.
    class TestDownloadFile(Browser):
       def test_download(self):
           page = Selenium_Playground_Page(self.driver)
           download_file = page.download("How to download files using Selenium &amp;amp; Python?")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Automate Cypress tests and perform browser automation &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cypress testing&lt;/a&gt; with LambdaTest. Our cloud infrastructure has 3000+ desktop &amp;amp; mobile environments. Try for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to download file using Selenium Python in Chrome?
&lt;/h2&gt;

&lt;p&gt;In our &lt;strong&gt;conftest.py&lt;/strong&gt; file, we need to add some code. First, we will import the chromeOptions with the following import statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    from selenium.webdriver.chrome.options import Options
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Chrome Options&lt;/strong&gt; class is used to control the properties of Chrome Driver and is used with combining Desired Capabilities. It helps you perform various operations, such as defining the folder where you want to save a download file.&lt;/p&gt;

&lt;p&gt;Usage to create a Chrome driver instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          #Google Chrome
           options = Options()
           prefs = {"download.default_directory" : PATH}
           options.add_experimental_option("prefs",prefs)
           self.driver = webdriver.Chrome(options=options)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;options&lt;/strong&gt;: This allows you to set the preferences of the Chrome browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;download.default_directory&lt;/strong&gt;: Allows to modify the default download directory. The default download folder will be the path defined in our PATH variable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;add_experimental_option&lt;/strong&gt;: Allows users to add these preferences to their Selenium webdriver object.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our &lt;strong&gt;conftest.py&lt;/strong&gt; file should now look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import unittest
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options

    class Browser(unittest.TestCase):
       def setUp(self):
           PATH = "/Users/macbookair/Desktop/how_download_files_selenium_python/download"
           #Google Chrome
           options = Options()
           prefs = {"download.default_directory" : PATH}
           options.add_experimental_option("prefs",prefs)
           self.driver = webdriver.Chrome(options=options)
           self.driver.get("https://www.lambdatest.com/selenium-playground/")

       def tearDown(self):
           self.driver.close()

    if __name__ == '__main__':
       unittest.main()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can run your test by typing in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    python3 -m unittest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your test should run as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A88vlV3i_O6yvnwqq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A88vlV3i_O6yvnwqq.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once your test has run successfully, you should have the &lt;strong&gt;Lambdainfo.txt&lt;/strong&gt; file in your download folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A_JR4kgukdzCvLq4f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A_JR4kgukdzCvLq4f.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The file does contain the text “How to download files using Selenium &amp;amp; Python?”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Execute &amp;amp; analyse &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cypress cloud&lt;/a&gt; test scripts online. Deploy quality builds faster with 40+ browser versions on cloud.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to download file using Selenium Python in Firefox?
&lt;/h2&gt;

&lt;p&gt;Now, we will need to create a Firefox profile. Here is the code you will need to add to your &lt;strong&gt;conftest.py&lt;/strong&gt; file if you plan to run your tests with Mozilla Firefox.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;           #Firefox
           profile = webdriver.FirefoxProfile()
           profile.set_preference("browser.download.folderList", 2)
           profile.set_preference("browser.download.manager.showWhenStarting", False)
           profile.set_preference("browser.download.dir", PATH)
           profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/x-gzip")
           self.driver = webdriver.Firefox(firefox_profile=profile)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;More explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Profile&lt;/strong&gt;: The profile object is specific to FirefoxDriver and contains all the preferences to be defined.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;browser.download.folderList&lt;/strong&gt;: Tells not to use the default Downloads directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;browser.download.manager.showWhenStarting&lt;/strong&gt;: Turns of showing download progress.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;browser.download.dir&lt;/strong&gt;: Sets the directory for downloads.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;browser.helperApps.neverAsk.saveToDisk&lt;/strong&gt;: Informs Firefox to automatically download the files of the chosen mime types.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        self.driver = webdriver.Firefox(firefox_profile=profile)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This line of code allows us to create a Firefox driver object with all the preferences.&lt;/p&gt;

&lt;p&gt;Our &lt;strong&gt;conftest.py file should now look like this:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import unittest
    from selenium import webdriver
    class Browser(unittest.TestCase):
       def setUp(self):
           PATH = "/Users/macbookair/Desktop/how_download_files_selenium_python/download"
           #Mozilla Firefox
           profile = webdriver.FirefoxProfile()
           profile.set_preference("browser.download.folderList", 2)
           profile.set_preference("browser.download.manager.showWhenStarting", False)
           profile.set_preference("browser.download.dir", PATH)
           profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/x-gzip")
           self.driver = webdriver.Firefox(firefox_profile=profile)
           self.driver.get("https://www.lambdatest.com/selenium-playground/")

       def tearDown(self):
           self.driver.close()
    if __name__ == '__main__':
       unittest.main()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we can rerun our tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A5YjtuJj4k9_3FBqq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A5YjtuJj4k9_3FBqq.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to download file using Selenium Python in Safari?
&lt;/h2&gt;

&lt;p&gt;It is not necessary to download the Safari driver for Selenium WebDriver. Instead, the built-in Safari driver, safaridriver, is currently available in most Selenium client libraries. But before running web &lt;a href="https://www.lambdatest.com/learning-hub/ui-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;UI testing&lt;/a&gt; in Safari, ensure you enable remote automation in the Safari browser.&lt;/p&gt;

&lt;p&gt;To allow remote automation in Safari, you must turn on WebDriver support:&lt;/p&gt;

&lt;p&gt;1- To enable the Develop menu in the Safari browser, click &lt;strong&gt;Safari &amp;gt; Preferences &amp;gt; Advanced&lt;/strong&gt; tab. Select the Show Develop Menu check box. The Develop menu appears in the menu bar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AySGN09bhldRCW9xsGtZs8Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AySGN09bhldRCW9xsGtZs8Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- To enable Remote Automation, click &lt;strong&gt;Develop &amp;gt; Allow&lt;/strong&gt; Remote Automation in the menu bar.&lt;/p&gt;

&lt;p&gt;3- Authorize safaridriver to launch the webdriver service that hosts the local web server. To permit this, run &lt;strong&gt;/usr/bin/safaridriver&lt;/strong&gt; once manually and complete the authentication prompt.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AYZ6r4FH8r5gPMRuDhbvLQw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AYZ6r4FH8r5gPMRuDhbvLQw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4- Now, we will need to make some changes before running the tests. Firstly we will change the default download folder for Safari. You can do this in the Safari preferences in the general tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A6KxK5zwU3J_EI18CKpqNig.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A6KxK5zwU3J_EI18CKpqNig.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5- Now, we will disable the download confirmation alerts. In the website tab, in the preferences.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AWf2zYFXNGIdPdfcm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AWf2zYFXNGIdPdfcm.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s add some code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;           #Safari
           self.driver = webdriver.Safari()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our &lt;strong&gt;conftest.py&lt;/strong&gt; file should now look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import unittest
    from selenium import webdriver
    class Browser(unittest.TestCase):
       def setUp(self):
           PATH = "/Users/macbookair/Desktop/how_download_files_selenium_python/download"
           #Safari
           self.driver = webdriver.Safari()       
           self.driver.get("https://www.lambdatest.com/selenium-playground/")
       def tearDown(self):
           self.driver.close()
    if __name__ == '__main__':
       unittest.main()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything is ready to run the tests with Safari. After running your tests, the result should be as follows&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AN73xgxlF2N2y5sPF.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AN73xgxlF2N2y5sPF.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This Cypress automation testing tutorial will help you learn the benefits of &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cypress automation&lt;/a&gt;, and how to install Cypress and execute Cypress automation testing over scores of browsers and operating systems online.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to download file using cloud Selenium Grid?
&lt;/h2&gt;

&lt;p&gt;Every project is unique, and you must optimize your application for any configuration to provide a smooth and consistent user experience on all devices, browsers, and operating systems.&lt;/p&gt;

&lt;p&gt;In an ideal world, developers would test their apps using real devices under real conditions. However, in-house labs tend to be small and thus cannot provide users with real-world experiences. Instead, they opt to use &lt;a href="https://www.lambdatest.com/blog/emulator-vs-simulator-vs-real-device/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;emulators or simulators&lt;/a&gt; designed to mimic the real feelings of users. Although these tools are great for &lt;a href="https://www.lambdatest.com/mobile-app-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;app testing&lt;/a&gt;, they cannot replace real devices. In such cases, you must opt for a &lt;a href="https://www.lambdatest.com/real-device-cloud?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;real device cloud&lt;/a&gt; testing solution that offers real devices.&lt;/p&gt;

&lt;p&gt;LambdaTest cloud &lt;a href="https://www.lambdatest.com/blog/selenium-grid-setup-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid&lt;/a&gt; offers an &lt;a href="https://www.lambdatest.com/online-device-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online device farm&lt;/a&gt; with 3000+ real devices and browsers to help you get the job done.&lt;/p&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/python-web-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Python web automation&lt;/a&gt; tutorial on how to download file using Selenium Python, we will use LambdaTest REST APIs (/user-files/download) to download files from LambdaTest cloud storage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2Aho1IQ8rZ0Wyus3AI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2Aho1IQ8rZ0Wyus3AI.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will have to use the POST request to upload files to our LambdaTest storage and then the PUT request to download the user file from LambdaTest storage.&lt;/p&gt;

&lt;p&gt;Before we continue, we will install &lt;strong&gt;requests&lt;/strong&gt;, a Python library that will allow us to make HTTP requests in Python. It abstracts the complexity of requests behind a nice simple API, so you can focus on interacting with services and consuming data in your application.&lt;/p&gt;

&lt;p&gt;Run the following command from the terminal:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pip3 install requests&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once requests are installed, you can use them in your project. Importing requests looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import requests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our file test_download_file.py, we import JSON and request packages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import requests
    import json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then let’s add some code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   class TestAPIDownloadFile():

           username = "username"
           access_Key = "access key"

           #POST_REQUEST
           url = "https://api.lambdatest.com/automation/api/v1/user-files"

           payload={}

           files=[
           ('files',('Lambdainfo.txt',open('/Users/macbookair/Downloads/Lambdainfo.txt','rb'),'text/plain'))
           ]

           headers = {
           'authority': 'api.lambdatest.com',
           'accept': 'application/json',
           }

           response = requests.request("POST", url, auth=(username, access_Key), headers=headers, data=payload, files=files)

           print(response.text)


           #PUT_REQUEST
           url = "https://api.lambdatest.com/automation/api/v1/user-files/download"


           payload = json.dumps({
           "key": "Lambdainfo.txt"
           })

           headers = {
           'accept': 'application/octet-stream',
           'Content-Type': 'application/json'
           }

           response = requests.request("PUT", url, auth=(username, access_Key), headers=headers, data=payload)
           open('/Users/macbookair/Documents/how_download_files_selenium_python/download/Lambdainfo.txt', 'wb').write(response.content)

           print(response.text)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In a new class &lt;strong&gt;TestAPIDownloadFile&lt;/strong&gt; that we added to our file we declare two variables as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    username = "username"
    access_Key = "access key"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These variables will be used for identification in our API calls before accessing the endpoint.&lt;/p&gt;

&lt;p&gt;You need to replace the value of the &lt;strong&gt;username&lt;/strong&gt; and &lt;strong&gt;access key&lt;/strong&gt; using the authentication data that you can retrieve from the &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest profile page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2Ab1je0m3jT587Db4T.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2Ab1je0m3jT587Db4T.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          #POST_REQUEST
           url = "https://api.lambdatest.com/automation/api/v1/user-files"

           payload={}

           files=[     ('files',('Lambdainfo.txt',open('/Users/macbookair/Downloads/Lambdainfo.txt','rb'),'text/plain'))
           ]

           headers = {
           'authority': 'api.lambdatest.com',
           'accept': 'application/json',
           }

           response = requests.request("POST", url, auth=(username, access_Key), headers=headers, data=payload, files=files)

           print(response.text)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we make a POST request to upload a file from our computer to the lambda storage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;           files=[     ('files',('Lambdainfo.txt',open('/Users/macbookair/Downloads/Lambdainfo.txt','rb'),'text/plain'))
           ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You must replace ‘&lt;strong&gt;Lambdainfo.txt&lt;/strong&gt;‘ by the name of your file and ‘&lt;strong&gt;/Users/macbookair/Downloads/Lambdainfo.txt&lt;/strong&gt;‘ by the path where the file is located.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   response = requests.request("POST", url, auth=(username, access_Key), headers=headers, data=payload, files=files)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a response variable, we save the response of our request that we display afterward by doing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      print(response.text)


           #PUT_REQUEST
           url = "https://api.lambdatest.com/automation/api/v1/user-files/download"


           payload = json.dumps({
           "key": "Lambdainfo.txt"
           })

           headers = {
           'accept': 'application/octet-stream',
           'Content-Type': 'application/json'
           }

           response = requests.request("PUT", url, auth=(username, access_Key), headers=headers, data=payload)
           open('/Users/macbookair/Documents/how_download_files_selenium_python/download/Lambdainfo.txt', 'wb').write(response.content)

           print(response.text)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once our file has been uploaded to the lambda storage, we can now use our PUT requests to download it to the directory of our choice.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     payload = json.dumps({
           "key": "Lambdainfo.txt"
           })

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key&lt;/strong&gt; identifies our file on the storage, so you have to replace it with the name of our file on the storage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;open('/Users/macbookair/Documents/how_download_files_selenium_python/download/Lambdainfo_API.txt', 'wb').write(response.content)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we save the file in the directory of our choice. You must replace the specified path with the one where you want to save the file.&lt;/p&gt;

&lt;p&gt;Once the test is run in your console, you can see the response to your requests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AL5rK3eG40CFYbXs5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AL5rK3eG40CFYbXs5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the file that has been downloaded in the defined directory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A0oT0Qiu2fic1IarI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A0oT0Qiu2fic1IarI.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re a Python programmer looking to make a name for yourself in the &lt;a href="https://www.lambdatest.com/learning-hub/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt; domain, then the Selenium Python 101 certification program from LambdaTest is your best bet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This concludes the tutorial on how to download file using Selenium Python. When you automate your web tests using Selenium, you may need to test the complete functionality of a website or a web application. This means you will have to exercise features like downloading and uploading files, streaming video or audio, and reading/writing documents.&lt;/p&gt;

&lt;p&gt;In this tutorial on &lt;a href="https://www.lambdatest.com/selenium-python-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec27_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Python testing&lt;/a&gt;, we saw how to download file using Selenium Python to a specific folder. Moreover, we learned to download file using Selenium Python in different browsers like Chrome, Firefox, and Safari. In the end, we looked at downloading file on a cloud Selenium Grid like LambdaTest.&lt;/p&gt;

&lt;p&gt;I hope this has given you a good overview of how to download file using Selenium Python. If you have any questions or comments, please leave them in the section below.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
