banner



How To Handle Windows Based Popup In Selenium

Selenium WebDriver is one of the famous functional automation tools/APIs currently in the market. Many companies are already implementing their automation frameworks using Selenium WebDriver, every bit it is an opensource automation framework and tin be written in whatsoever of the popular programming languages.


Withal, like whatever other tool, it has its ain set of limitations. One of the limitations is handling window-based pop-ups, as the web driver automates but browsers. For instance, in case your test case needs to upload a file and perform some other actions on the webpage, information technology may not be able to practice it successfully. That'south because "File Upload" is a window-based popup. In such a scenario, you will accept to investigate some third-party tools/APIs which tin automate windows-based applications.


To combat this claiming, we will integrate third-party tools like AutoIT, Sikuli (Windows Automation Tools), etc. However, in these tools, the APIs support only a scattering of languages and require specific procedures for integration. Along with that, the syntax and code volition be different than the Selenium code.

Software Testing Services


To overcome these problems, we tin can use WinAppDriver to automate Window-based functionality (for ex: File Upload). The WinAppDriver can also be tightly integrated with the Selenium Web driver since the code is very like to the WebDriver code. Avert learning curve on any specific language or tools to leverage WinAppDriver and Web driver integration.


What is WinAppDriver?


WinAppDriver means Windows Application Commuter and it is a service to support Selenium-similar UI Test Automation on Microsoft Windows-based applications. WinAppDriver supports testing Universal Windows Platform (UWP), Windows Forms (WinForms), Windows Presentation Foundation (WPF), and Classic Windows (Win32) apps on Windows 10 PCs.


Pre-Requisites to setup WinAppDriver:

  1. Windows ten Machine
  2. Enable Debug Style in Windows10 machine
  3. Add Selenium dependencies to the projection
  4. Add together Coffee-Client (Appium) dependencies
  5. WinAppDriver server should exist running on the car
  6. Any one of the elements inspecting tools like inspect.exe, WinAppDriver Recorder or Appium Desktop, etc.


WinAppDriver Setup Steps:

  1. Download the latest WinAppDriver installer from this location
  2. Run the installer on Windows x auto where your application under test is installed
  3. Enable Developer Mode in Windows Settings
  4. Run WinAppDriver.exe from the installation directory (i.due east. C:\Plan Files (x86) \Windows Application Driver) [This stride can be avoided using the code which is discussed in the upcoming sections of this blog mail]
    a. WinAppDriver will then be running on the test machine listening to requests on the default IP address and port (127.0.0.1:4723)
  5. Write the WinAppDriver plan and execute

Every bit discussed in the point 6 of Pre-Requisites above, use audit tool to find the elements on the windows-based pop-up to demonstrate the scenario. Post-obit is the procedure to get the inspect tool on your automobile.


Finding the Elements using Audit.exe Tool:

To go the inspect.exe tool, we demand to install Windows SDK in our motorcar. When you lot download and install Windows SDK, you can observe the audit.exe in the beneath mentioned location:
C:\Program Files (x86) \Windows Kits\10\bin\\x64 (Ex: C:\Program Files (x86)\Windows Kits\x\bin\10.0.18362.0\x64)

Post-obit is the sample UI screenshot of the inspect.exe tool:

Selenium WebDriver automation tool

Post-obit is the File Upload Window Popup Screenshot to demonstrate treatment window-based popup using WinAppDriver in WebDriver:

Automation testing services

In the in a higher place screenshot, we need to inspect the File Name textbox and open push button. To practice apply the inspect.exe tool. Following are the screenshots for inspecting both the elements and the screenshots showing their backdrop of the element being inspected.

automation testing tools
testing automation services

By using these properties, nosotros tin detect the locators of that element as below:

  • XPath
  • Proper name
  • Accessibility id
  • Automation id
  • Course name
  • Tag name (Localized Control Type), etc.


Sample Program to Demonstrate Integration of WinAppDriver With WebDriver:

i. Commencement the WinAppDriver server by running the winappdriver.exe file. Screenshot is shared below for reference.

Integration of WinAppDriver

2. Create a Java Maven projection and add the post-obit dependencies:

          <dependency>     <groupId>io.appium</groupId>     <artifactId>java-client</artifactId>     <version>{include latest/stable version}</version> </dependency> <dependency>     <groupId>org.seleniumhq.selenium</groupId>     <artifactId>selenium-java</artifactId>     <version>{include latest/stable version}</version> </dependency>        

3. Beneath is the sample programme for "File Upload" using WinAppDriver in Selenium WebDriver:

          import coffee.cyberspace.URL;  import org.openqa.selenium.Past; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Deportment; import org.openqa.selenium.remote.DesiredCapabilities; 		 import io.appium.java_client.windows.WindowsDriver;  public grade FileUpload { 		public static void main(String[] args) throws Exception {         	     System.setProperty("webdriver.chrome.commuter", "<Path of chromedriver.exe file>");           WebDriver commuter = new ChromeDriver();           driver.become("http://demo.automationtesting.in/Annals.html");            WebElement chooseFileButton = driver.findElement(By.id("imagesrc"));        	     new Actions(driver).click(chooseFileButton).perform();            // WinAppDriver code starts hither           DesiredCapabilities desktopCapabilities = new DesiredCapabilities();         	     desktopCapabilities.setCapability("app", "Root");           WindowsDriver session = new WindowsDriver(new URL("http://127.0.0.one:4723"),desktopCapabilities);          		// uploading a sample file called "Data.txt" from the D drive.           WebElement openWindowPopupFileNameTextbox = session.findElementByXPath("//Edit[@Name='File name:']");           openWindowPopupFileNameTextbox.sendKeys("D:\\Data.txt");                       WebElement openWindowPopupOpenButton = session.findElementByXPath("//Button[@Proper name='Open'][@AutomationId='1']");           openWindowPopupOpenButton.click();            // WebDriver code starts again from here          WebElement hockeyCheckbox = commuter.findElement(By.id("checkbox3"));           hockeyCheckbox.click();                      driver.quit();     } }        

In the above example, when you click on Choose File push button, it opens "File Upload" popular-upwardly which is Windows-based and cannot exist identified and interacted past Web driver. Here, we can integrate WinAppDriver to collaborate with the windows-based popular-ups to automate residue of the test steps.

          DesiredCapabilities desktopCapabilities = new DesiredCapabilities();         	     desktopCapabilities.setCapability("app", "Root");           WindowsDriver session = new WindowsDriver(new URL("http://127.0.0.ane:4723"),desktopCapabilities);        

The above code is useful to accept the command of the entire desktop to interact with Windows-based elements. To achieve that, we need to set the "app" capability as "root" and create an instance of the Windows Driver.

To Place the "File Name" textbox, we have written XPath by using some of the properties of that particular element using the audit tool. Following is the XPath and code for your reference.

          WebElement openWindowPopupFileNameTextbox = session.findElementByXPath("//Edit[@Proper noun='File name:']");           openWindowPopupFileNameTextbox.sendKeys("D:\\Data.txt");        

Similar steps for XPath to observe the "Open up" button on the File Upload pop-upwardly.

          WebElement openWindowPopupOpenButton = session.findElementByXPath("//Button[@Proper noun='Open'][@AutomationId='1']");           openWindowPopupOpenButton.click();        

Our actual scenario (i.east., File Upload) ends here. Withal, post completion of "file upload" the script should continue to collaborate with the elements on the web folio. For that, the following code volition help:

          WebElement hockeyCheckbox = commuter.findElement(By.id("checkbox3"));           hockeyCheckbox.click();        

Every bit promised in the starting of this post, we tin run the WinAppDriver server programmatically to avoid manual intervention. The beneath sample code will help in starting WinAppDriver programmatically and automating the File Upload functionality.

          import java.net.MalformedURLException; import java.cyberspace.URL;  import org.openqa.selenium.Past; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.remote.DesiredCapabilities;  import io.appium.java_client.windows.WindowsDriver;  public class FileUploadUsingWinAppDriver {     public static void main(String[] args) throws Exception {       	        System.setProperty("webdriver.chrome.driver", "<Path of chromedriver.exe file>");         WebDriver driver = new ChromeDriver();      	        commuter.get("http://demo.automationtesting.in/Annals.html");          WebElement chooseFileButton  = driver.findElement(By.id("imagesrc"));        	   new Actions(driver).click(chooseFileButton).perform();          // Start the WinAppDriver Programmatically      	        String command = "C:/Program Files (x86)/Windows Application Driver/WinAppDriver.exe";         ProcessBuilder architect = new ProcessBuilder(command).inheritIO();      	        Process process = builder.start();                // WinAppDriver code starts hither         DesiredCapabilities desktopCapabilities = new DesiredCapabilities();      	        desktopCapabilities.setCapability("app", "Root");         WindowsDriver session = new WindowsDriver(new URL("http://127.0.0.one:4723"),desktopCapabilities);                       // uploading a sample file called "Data.txt" from the D drive.         WebElement windowsPopupFileNameTextbox = session.findElementByXPath("//Edit[@Proper name='File name:']");         windowsPopupFileNameTextbox.sendKeys("D:\\Data.txt");      	            WebElement windowsPopupOpenButton = session.findElementByXPath("//Button[@Name='Open'][@AutomationId='one']");         windowsPopupOpenButton.click();               // WebDriver code starts once again from here              WebElement hockeyCheckbox = driver.findElement(By.id("checkbox3"));         hockeyCheckbox.click();          	   driver.quit();       	        // Need to destroy the process every bit a best practice         process.destroy();     } }        

This brings u.s. to the end of this commodity on How to Handle Windows-based Popups Using WinAppDriver in Selenium WebDriver.

Wish to know more about basic commands in selenium? Experience complimentary to leave your question below. We'll get back to y'all in the shortest possible time.

Source: https://www.evoketechnologies.com/blog/how-to-handle-windows-based-popups-using-winappdriver-in-selenium-webdriver/

Posted by: partridgevered1971.blogspot.com

0 Response to "How To Handle Windows Based Popup In Selenium"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel