Automated Browser Testing with Edge and Selenium in Python
Last Updated :
24 May, 2024
Cross-browser testing is mandatory in the software industry. We all know that there are many browsers like Firefox, Chrome, Edge, Opera etc., are available. Rather than writing separate code to each and every browser, it is always a decent approach to go towards automated testing. Let us see how to do that using Selenium for Edge browser in Python. Here Edge WebDriver is used in order to run our Selenium automation test scripts over the Edge browser.
Requirements
In order to perform Browser Automation using Edge And Selenium In Python, we need to carry out the following steps:
- Edge browser: Microsoft Edge browser can be downloaded from https://www.microsoft.com/en-us/edge. If already installed, we can get the existing version of edge by using edge://version/
- Selenium framework: Selenium is a powerful tool for controlling a web browser through the program. It is functional for all browsers, works on all major OS. It can be installed using the below command:
pip install selenium
- Edge WebDriver: Selenium Edge Webdriver can be downloaded from this URL. Automatically testing will be getting done in Edge browser with this driver. Download the edge webdriver according to the operating system and unzip the file and get msedgedriver.exe .
- Selenium tools for Microsoft Edge: This module has the required features for automated browser testing, it can be installed using the below command:
pip install msedge-selenium-tools selenium==3.141
Below is a program to execute a simple automated browser testing script:
Python
# import required modules
from selenium import webdriver
# Driver Code
if __name__ == '__main__':
# create object
edgeBrowser = webdriver.Edge(r"msedgedriver.exe")
# open browser and navigate to lambdatest Login Page
edgeBrowser.get('https://www.lambdatest.com')
Output:
LambdaTest Login Page Opened by Edge
On executing the script, we can see, edge browser has opened Facebook page as shown in the image. You can open any valid web page and automatically it will open the mentioned web page in edge browser.
Step for Automation of Browser Testing with Edge and Selenium
1. Platform Selection
Choose the appropriate testing platforms. You can choose a local grid or a cloud grid like LambdaTest for scalability and reliability. It is an AI-powered test orchestration and execution platform that allows you to perform automated browser testing with Selenium, Python across different Edge browser versions. With LambdaTest, you can:
- Perform automated testing: Run automated tests with Python and popular Python testing frameworks like pytest, Robot, and more across 3000+ real environments.
- Perform visual regression testing: Automate your visual tests with an AI-powered SmartUI platform.
- View test reports: Get extension test execution logs of your Selenium Python tests for hassle-free debugging and testing on the go.
2. Browser Compatibility
- Test on multiple Edge versions or other desired browsers using LambdaTest extensive browser farm.
- Ensure cross-browser compatibility by identifying any layout or functionality issues.
3. Automated Actions:
- Maximize Window: Use the maximize_window() command within your Selenium script to optimize visual space.
- Open webpage: Leverage the get() method in Selenium to navigate to Facebook Page.
4. Data Parameterization
- Instead of hardcoding "gfg@lambdatest.com", utilize parameterization in your script to input different email addresses during testing.
- This allows testing valid and invalid email formats, enhancing test coverage.
5. Dynamic Element Identification
- Locate the "useremail" button using reliable identification methods like XPath or CSS selectors.
- Avoid fragile techniques like text-based matching to ensure script robustness across potential Ul changes.
6. Submit Action and Verification
- Use the click() method in Selenium to activate the button and trigger form submission.
- Verify successful and you have successfully Login to the LambdaTest page.
7. Advanced Features
- Visual testing: Capture screenshots before and after the submission to ensure visual consistency across browsers.
- Network analysis: Monitor network traffic during registration to entity potential performance bottlenecks.
Implementation
Python
# Import required module
from selenium.webdriver.opera.options import Options
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium import webdriver
from time import sleep
# Driver Code
if __name__ == '__main__':
# Instantiate the webdriver with the executable location of MS Edge
# Provide the full location of the path to recognise correctly
edgeBrowser = webdriver.Edge(r"msedgedriver.exe")
# This is the step for maximizing browser window
edgeBrowser.maximize_window()
# Browser will get navigated to the given URL
edgeBrowser.get('https://www.lambdatest.com')
try:
# We need to insert Email in order to proceed further.
# So it is given by using 'useremail'
sampleElement = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.ID, 'useremail')))
# We can give a valid email address and since
# this page carries the email id alone, it just
# appends the email id at the end
sampleElement.send_keys("gfg@lambdatest.com")
# A click is happening to move to next page
sampleElement.click()
# A Submit button is searched to click and start
# free testing. Actually "testing_form" is the id
# of the form, which needs to get tested
sampleElement2 = WebDriverWait(browser, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR,
"#testing_form > div")))
# Starting free testing on LambdaTest
sampleElement2.click()
# Just to show the set of actions happening, we can
# give sleep, you can change the values as per requirement
sleep(20)
except TimeoutException:
print("Trying to find the given element but unfortunately no element is found")
sleep(20)
# Once all operations over, we can close browser too
# edgeBrowser.close()
Output
Automated browser testing is very convenient and as separate drivers are available for each browser, we can do the testing easily and no manual work is needed. Even automated testing is faster and can test multiple test pages very quickly and provide successful test results.
Similar Reads
Pros and Cons of Selenium as an Automation Testing tool Selenium is a free, open-source test execution automation platform for web applications. It implements itself using a browser-specific driver that accepts and transmits commands to the browser. You can develop test scripts in a variety of computer languages, including Ruby, Java, NodeJS, PHP, Perl,
8 min read
Automation Using Selenium in C# With Example Selenium is an open-source Web UI automation testing suite. It was developed by Jason Huggins in 2004 as an internal tool at Thought Works. It supports automation across different browsers, platforms, and programming languages which includes Java, Python, C#, etc. It can be easily be deployed on Win
3 min read
How to Add Chrome Extension using Python Selenium IntroductionSelenium is a tool for browser automation that supports multiple browsers for testing. With webdriver we can use multiple languages like Python, C#, and Java to write the code for automation testing. For Adding a Chrome extension in a browser with Selenium WebDriver allows us to automate
5 min read
Non blocking wait in selenium using Python Prerequisite : Browser Automation Using SeleniumWhen we want to do web automation, we require to wait for some javascript elements to load before we perform some action. For that matter, generally people use Python3 time.sleep(in_seconds) which is a blocking call.By blocking call I mean, it waits or
3 min read
How to Build a Simple Auto-Login Bot with Python In this article, we are going to see how to built a simple auto-login bot using python. In this present scenario, every website uses authentication and we have to log in by entering proper credentials. But sometimes it becomes very hectic to login again and again to a particular website. So, to come
3 min read
Working with Input box/Test Box in Selenium with Python Selenium is an effective device for controlling an internet browser through the program. It is purposeful for all browsers, works on all fundamental OS and its scripts are written in numerous languages i.e Python, Java, C#, etc, we can be running with Python.Working with Input box/Test Box, let us h
1 min read
How to check if an element exists with Python Selenium? Selenium is one of the most powerful and widely used tools for web automating web applications. Whether you're a software developer or a QA tester, Selenium is an important tool to have in your toolkit. Selenium is widely used for automating user interactions like clicking buttons, filling out the f
7 min read
Interacting with Webpage - Selenium Python Seleniumâs Python module is designed for automating web testing tasks in Python. It provides a straightforward API through Selenium WebDriver, allowing you to write functional and acceptance tests. To open a webpage, you can use the get() method for navigation. However, the true power of Selenium li
4 min read
How can we Find an Element using Selenium? Selenium is one of the most popular and powerful tools for automating web applications. Selenium is widely used for automating user interactions on a web application like clicking on a button, navigating to a web page, filling out web forms, and many more. But to interact with a web application we f
6 min read
How To Automate Google Chrome Using Foxtrot and Python In this article, we are going to see how to automate google chrome using Foxtrot & Python. What is Foxtrot RPA?Robotic process automation (RPA) cuts down employeesâ workloads by automating repetitive, high-volume steps in processes. Software robots, such as Foxtrot RPA emulate the actions of hum
4 min read