Selenium WebDriver- Microsoft Edge Browser

Selenium WebDriver- Microsoft Edge Browser:

In this tutorial, we will learn how to launch the Microsoft Edge browser in the Selenium WebDriver.

Before we start automating our test script with Microsoft Edge browser using Selenium, we need to make sure that,

  • We should have Windows-10 installed in our machine.
  • After that, download the Microsoft WebDriver server version for your OS builds.
  • And try to use the latest version of Selenium (version 3.0 and above).

We will create this test case in the same test suite (new_test), which we created in the previous tutorial.

Step1:

  • Firstly, right-click on the src folder and create a new Class File from New ? Class.
Selenium web driver- Microsoft Edge Browser
  • And Give your Class name as Test_edge and click onthe Finish button.
Selenium web driver- Microsoft Edge Browser 1

Step2:

  • Firstly, we have to check the version of our OS builds. Based on our OS version build, we have to download the Edge driver.
  • And then go to Start ? Settings ? about this app to move to the Edge browser.
  •  The settings window would be displayed, in the below screenshot.
  • Remember the release number written next to OS Build. In this case, it is 15063, as shown in the above image.

Step3:

  • Now, go to the Selenium community, and download the Edge driver server.
  • In the Selenium community, find the third party driver division, and click on the Microsoft edge driver link which is shown in the below image,
Selenium web driver- Microsoft Edge Browser 3

Or

Directly open the below link, it will navigate you to the download page of Microsoft Edge driver in your browser.

https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/

  • Move your cursor downward little bit till you see the Downloads section.
  • And download the one which matches your build number.
  • In this case, we will click on Release 15063 and download it.
Selenium web driver- Microsoft Edge Browser 4

Step4:

  • Then, download the zip file into our local system, and unzip the folder, it will generate MicrosoftWebDriver.exe file automatically.
Selenium web driver- Microsoft Edge Browser 5

Step5:

  • Run the server before launching the Edge browser, with the  help of

System.property.

Syntax:

System.SetProperty(“key”, ”value”);

To set the system property for MicrosoftWebDriver where

Key = “webdriver.edge.driver”

And the path of your MicrosoftWebDriver.exe file to invoke the MicrosoftWebDriver class.

Value=”C:\\Users\\JTP\\Downloads\\microsoft edge driver\\MicrosoftWebDriver.exe"

Sample code for the system property:

// System Property for Edge Driver   
System.setProperty("webdriver.edge.driver","C:\\Users\\JTP\\Downloads\\microsoft edge river\\MicrosoftWebDriver.exe");
// create an object for EdgeDriver class.
WebDriver driver=new EdgeDriver();   

Let us see one sample test case, where we will try to automate the following scenarios in the Microsoft Edge browser.

Steps Actions Input Excepted Result
1. Open the Microsoft Edge browser.     The Microsoft Edge browser should be opened.
2. Navigate to the URL https://twitter.com/login?lang=en The twitter login page must be displayed.
3. Pass the value in the username text box. Username=admin Username value should be entered.
4. Pass the value in the password text box.   Password=admin Password value should be entered.
5. Click on the login button.     The login button should be clicked.
6. Capture the title of the home page.     The title of the home page should be captured.
7. Verify the title of the home page.     The title of the home page should be verified.
8. Close the browser.   The browser should be closed.

Here, the sample code for the above example:

package testpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
public class test_edge {
public static void main(String[] args) throws InterruptedException { 
// System Property for Edge driver
System.setProperty("webdriver.edge.driver","C:\\Users\\JTP\\Downloads\\microsoft edge driver\\MicrosoftWebDriver.exe");
// Step1: Launch the Microsoft Edge browser.
 WebDriver driver=new EdgeDriver();
// Step2: Open URL 
driver.get("https://twitter.com/login?lang=en");
// Step3: Pass the value in the username text box.
driver.findElement(By.xpath("//input[@placeholder='Phone, email or username']1]")).sendKeys("admin");
Thread.sleep(2000);
System.out.println("user name entered successfully");
// Step4: Pass the value in the password text box.
driver.findElement(By.xpath("//div[@class='clearfixfield']//input
[@placeholder='Password']")).sendKeys("admin");
Thread.sleep(2000);
System.out.println("password entered successfully "); 
// Step5: Click on login button.
driver.findElement(By.className("clearfix")).click();
System.out.println("login successfully");
// Step6: Capture the title of the home page. 
String exp_title="Login on Twitter";
String act_title=driver.getTitle();
// Step7: Verify the title of the home page. 
if(exp_title.equals(act_title))
{
System.out.println("test passed");
}
else {
System.out.println("test failed");
}
// Step8: Close the browser.
driver.close(); 
}
} 
  • Now, right-click on the Eclipse code and select Run as → Java Application.
  • The output of the above test script would be displayed in the Microsoft Edge browser.
Selenium web driver- Microsoft Edge Browser 6
  • The output of all print command of the above test script would be displayed in the Eclipse console window.
Selenium web driver- Microsoft Edge Browser 7



ADVERTISEMENT
ADVERTISEMENT