TestNG and Selenium- IE fails to launch independen

2019-06-02 06:57发布

问题:

I'm using TestNG and Selenium to perform parallel tests. This works great in Firefox and Chrome, but breaks in IE. The steps I have the web driver executing are as follow:

  1. A browser instance is created using a parameter from testng.xml (found below)
  2. An available user is selected from a pool of test user credentials
  3. The user is logged in
  4. Tests proceed

When IE launches its instances, all of them are assigned the same user. Furthermore, all instances appear to fight over which one has focus. (Conversely, in Firefox and Chrome, all instances are appropriately assigned their own user and do not fight over focus.)

Because each IE instance uses the same user credentials, I get testing collisions and because they fight over which instance has focus, I get Selenium TimeoutExceptions due to waitForElementPresent commands.

My hunch is that IE is simply incapable of having multiple unique instances open concurrently. Can anyone either confirm my suspicion or direct me as to how I might remedy the issue? Thank you for your help!!

For reference, here is my testng.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="6" verbose="0" name="Command line suite" parallel="tests">

    <!-- IE Tests -->
    <test name="SourceBoxUIIe" preserve-order="true">
        <parameter name="browser" value="ie"/>
        <classes>
            <class name="org.familysearch.links.uitests.SourceBoxUITest"/>
        </classes>
    </test>
    <test name="EditPageIe" preserve-order="true">
        <parameter name="browser" value="ie"/>
        <classes>
            <class name="org.familysearch.links.uitests.EditPageUITest"/>
        </classes>
    </test>
    <test name="LinksGadgetPageIe" preserve-order="true">
        <parameter name="browser" value="ie"/>
        <classes>
            <class name="org.familysearch.links.uitests.LinksGadgetPageUITest"/>
        </classes>
    </test>
    <test name="AdminChangeLogIe" preserve-order="true">
        <parameter name="browser" value="ie"/>
        <classes>
            <class name="org.familysearch.links.uitests.AdminChangeLogPageUITest"/>
        </classes>
    </test>
    <test name="AttachedToPageIe" preserve-order="true">
        <parameter name="browser" value="ie"/>
        <classes>
            <class name="org.familysearch.links.uitests.AttachedToPageUITest"/>
        </classes>
    </test>
    <test name="ChangeLogIe" preserve-order="true">
        <parameter name="browser" value="ie"/>
        <classes>
            <class name="org.familysearch.links.uitests.ChangeLogUITest"/>
        </classes>
    </test>

    <!-- Firefox Tests Would Be here -->
    <!-- Chrome Tests Would Be Here-->

  <!-- Command line test -->
</suite> <!-- Command line suite -->

回答1:

Your hunch is almost correct. Per the wiki :

Multiple instances of InternetExplorerDriver

With the creation of the IEDriverServer.exe, it should be possible to create and use multiple simultaneous instances of the InternetExplorerDriver. However, this functionality is largely untested, and there may be issues with cookies, window focus, and the like. If you attempt to use multiple instances of the IE driver, and run into such issues, consider using the RemoteWebDriver and virtual machines.

There are 2 solutions for problem with cookies (and another session items) shared between multiple instances of InternetExplorer.

The first is to start your InternetExplorer in private mode. After that InternetExplorer will be started with clean session data and will not save changed session data at quitting. To do so you need to pass 2 specific capabilities to driver: ie.forceCreateProcessApi with true value and ie.browserCommandLineSwitches with -private value. Be aware that it will work only for InternetExplorer 8 and newer, and Windows Registry HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main path should contain key TabProcGrowth with 0 value.

The second is to clean session during InternetExplorer starting. For this you need to pass specific ie.ensureCleanSession capability with true value to driver. This clears the cache for all running instances of InternetExplorer, including those started manually.