From 8c82bdbd126ac8a2ebad3f0d8904f4dbcf037ee8 Mon Sep 17 00:00:00 2001 From: Samarth Hapse <131296047+samarthhapse@users.noreply.github.com> Date: Wed, 28 Feb 2024 06:54:24 +0530 Subject: [PATCH] Update edgedriver.md --- guide/browser-drivers/edgedriver.md | 76 ++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/guide/browser-drivers/edgedriver.md b/guide/browser-drivers/edgedriver.md index 9bf0d827..e0bf4fad 100644 --- a/guide/browser-drivers/edgedriver.md +++ b/guide/browser-drivers/edgedriver.md @@ -32,6 +32,80 @@ Run your Nightwatch.js tests in Edge can be achieved using the [Microsoft Edge } +# Example + +## How to launch Edge browser in Selenium + ? +Chrome, Firefox, and Safari are undoubtedly the leading browsers worldwide as they comprise almost 85% of the total browser market share. This might make it seem like one can avoid optimizing their sites for a browser like Microsoft Edge. However, that’s not the case. + +As per a report by StatCounter, the legacy versions of Edge still make up 7.9% of the total desktop browser market share in the US. Besides, Edge also has significant brand recognition as it comes from the Microsoft family. Thus, to provide a truly browser-agnostic experience, it becomes imperative for teams to test their web applications on Edge. + +This article will demonstrate the fundamental steps to launch Edge browser using Selenium WebDriver for automated testing. It will also detail how Mac users can test on Edge legacy. + +### Configuring the Edge Driver +### Prerequisites: + +Installing the Windows 10 environment on the machine to run tests for legacy versions (15,16,17) of Edge +Downloading accurate WebDriver server version +Ensuring that the updated version of Selenium is being used + +### Now let’s get started with the steps for configuration. + +The primary step is to check the version of the OS build being used. Based on the OS version build, download the corresponding Edge driver. +1.To check the OS Build, go to Start > Settings > System > About. In the example in this article, OS version build is 17134. +2.Download the driver for the desired Edge version from the official source as per the OS version build identified earlier. Once the zip file is downloaded, unzip it and copy the .exe file to a specific location. +3.The next step is to import it in the project file. It’s assumed that the user knows how to set up a basic Selenium project. +4.One can refer to this article on Selenium with Java to understand how to set-up a basic Selenium with Java project in Eclipse IDE. +5.Define the Edge driver with its accurate path using the system setProperty method and instantiate the Edge driver. + +``` +// Set the driver path +System.setProperty("webdriver.edge.driver", "C://EdgeDriver.exe"); + +// Start Edge Session +WebDriver driver = new EdgeDriver(); + +driver.get("https://google.com"); + +driver.quit(); +``` +At this point, the Edge driver has been configured. Now let’s perform a sample test scenario. In this scenario, the code will automate 3 fundamental steps: + +1.Launch the Edge browser +2.Navigate to the Google website +3.Enter “BrowserStack Guide” as a search query + +#### Code for launching Edge Browser using Selenium: + +```sh +import java.util.concurrent.TimeUnit; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.edge.EdgeDriver; +public class Edge_Test{ +public static void main(String[] args) { +//Setting system properties of EdgeDriver +System.setProperty("webdriver.edge.driver", "C://EdgeDriver.exe"); +//Creating an object of EdgeDriver +WebDriver driver = new EdgeDriver(); +driver.manage().window().maximize(); +//Deleting all the cookies +driver.manage().deleteAllCookies(); +//Specifiying pageLoadTimeout and Implicit wait +driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS); +driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); +//launching the specified URL +driver.get("https://www.google.com/"); +//Locating the elements using name locator for the text box +driver.findElement(By.name("q")).sendKeys("BrowserStack Guide"); +// locator for Google search button +WebElement searchIcon = driver.findElement(By.name("btnK")); +searchIcon.click(); +} +} +``` +Executing the script above will launch the Edge browser, navigate to the Google website, and enter the term BrowserStack Guide as a search query. + ### Learn more For more information about the Microsoft Edge WebDriver refer to the [Official documentation](https://developer.microsoft.com/en-us/microsoft-edge/platform/documentation/dev-guide/tools/webDriver/). @@ -55,4 +129,4 @@ For more information about the Microsoft Edge WebDriver refer to the [Official d - \ No newline at end of file +