Thursday, January 19, 2012

Webdriver - Kill IE process.

Webdriver - Kill IE process

I am working on Webdriver pageobjects, if test case get failed, system will not close the browser because it has not reached the statement driver.close.
There are lot of opened IE's at the end of test execution.
To overcome this issue, I have created following utility program that is called before every test execution to eliminate any opened IE's.

public void xKillIEs() throws Exception
{
final String KILL = "taskkill /IM ";
String processName = "iexplore.exe"; //IE process
Runtime.getRuntime().exec(KILL + processName);
Wait(3000); //Allow OS to kill the process
}

Later I am know that this is not a good idea.
Better implement the following


InternetExplorerDriver driver;

@BeforeClass(alwaysRun = true)
protected void setUp() throws Exception {
driver = new InternetExplorerDriver();
}

@AfterClass(alwaysRun = true)
protected void tearDown() throws Exception {
driver.quit();
xKillIEs();
}




---

5 comments:

  1. Hi Bharath,
    thanks for the info on your blog, it's very useful.
    I have a question, I wonder whether there is an answer to that. Sorry about the question not being related to the above post.
    I want to create an automated tool for my browser for Android (I wrote it myself). Can I use WebDriver for that? (or WebDriver can only work with the established browsers?)
    I can open an URL in the stock browser and check the name and values of the HTML elements, but I wonder whether I can do the same with my browser.
    Thanks a lot,
    Chris

    ReplyDelete
  2. Hello Chris,
    As per my understanding it will work for established browsers. I would suggest to understand how webdriver communicate with original android browser and compare the changes with your custom browser. There is lot of difference how webdriver communicate with different browsers.

    ReplyDelete
  3. Thanks, Bharath. It makes sense.
    I'll do that.
    And I appreciate the swift reply.
    Best regards and congrats on your blog,
    Chris

    ReplyDelete
  4. It wouldn't work if you are running them in a remote location aka RemoteWebDriver+Grid2. Do you have any solution for that?

    ReplyDelete
    Replies
    1. True.
      1. Copy the in the remote location.
      or
      2. Using psTools create a script to copy or create a file in the remote location

      Delete