Thursday, 20 June 2013

Handling Windows Processes while running Selenium WebDriver script

 In general we use one step to kill the windows process:

             WindowsUtils.tryToKillByName("ProcessName.exe");

Now I am pasting here my code of killing skype.exe process before running webdriver script

package WDTNG;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.os.WindowsUtils;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class HandleWP {
    WebDriver d;
    @BeforeMethod
    public void start() throws Exception
    {
       
            WindowsUtils.tryToKillByName("skype.exe");
            d = new FirefoxDriver();
    }
    @Test
    public void test()
    {
        d.get("http://www.google.com");
    }
    @AfterMethod
    public void am()
    {
        d.quit();
    }
}

No comments:

Post a Comment