0

I have a few selenium tests on a react application. All tests are passing for chrome and firefox without any error. However, in IE (internet explorer v11) - all tests pass, but fails at the tearDown method: -

teardown method: -

@AfterClass
public void tearDown(){
        driver.close();
        //driver.quit();
}

screenshot of TestNG error log: -

enter image description here

Browser Base Class: -

public class TestBase {

public  static WebDriver driver;
public  static Properties prop;
public static EventFiringWebDriver e_driver;
public static WebEventListener eventlistener;
public static ChromeDriver chrome;
public static WebDriver driverName;
public TestBase(){
    try {
        prop = new Properties();
        FileInputStream ip = new FileInputStream("src/main/java/config/config.properties");
        prop.load(ip);
    }catch (FileNotFoundException e){
        e.printStackTrace();
    }catch (IOException e ){
        e.printStackTrace();
    }

}



public static void initialization(String browser){

    try {


    if(browser.equals("chrome")){
        System.setProperty("webdriver.chrome.driver", "C:\\Browser\\chromedriver.exe");
        driver = new ChromeDriver();
    }else if (browser.equals("firefox")){
        System.setProperty("webdriver.gecko.driver", "C:\\Browser\\geckodriver.exe");
        driver = new FirefoxDriver();
    }else if(browser.equals("ie")){
        System.setProperty("webdriver.ie.driver", "C:\\Browser\\IEDriverServer.exe");

        DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
        ieCapabilities.setCapability("nativeEvents", false);
        ieCapabilities.setCapability("unexpectedAlertBehaviour", "accept");
        ieCapabilities.setCapability("ignoreProtectedModeSettings", true);
        ieCapabilities.setCapability("disable-popup-blocking", true);
        ieCapabilities.setCapability("enablePersistentHover", true);
        ieCapabilities.setCapability("ignoreZoomSetting", true);


        driver = new InternetExplorerDriver(ieCapabilities);
    }else if(browser.equals("edge")){
        System.setProperty("webdriver.edge.driver", "C:\\Browser\\MicrosoftWebDriver.exe");
        EdgeOptions options = new EdgeOptions();
        options.setCapability("unexpectedAlertBehaviour", "accept");
        driver = new EdgeDriver(options);
        e_driver = new EventFiringWebDriver(driver);
        //now create object of event listner handler  to register it with eventfiring web driver
        eventlistener = new WebEventListener();
        e_driver.register(eventlistener);
        driverName = driver;
        driver = e_driver;
    }
    if(!browser.contains("edge")){

        e_driver = new EventFiringWebDriver(driver);
        //now create object of event listner handler  to register it with eventfiring web driver
        eventlistener = new WebEventListener();
        e_driver.register(eventlistener);
        driverName = driver;
        driver = e_driver;

        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();
        driver.manage().timeouts().pageLoadTimeout(TestUtil.PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(TestUtil.IMPLICIT_WAIT, TimeUnit.SECONDS);
    }
    driver.get(prop.getProperty("url"));
} catch (TimeoutException e){

if (driver != null)
    driver.close();
    //driver.quit();

        e.printStackTrace();


    }

    catch (Exception e){

        e.printStackTrace();


    }



}

console error log

Starting MSEdgeDriver ... (...) on port 2440
Only local connections are allowed.
Please protect ports used by MSEdgeDriver and related test frameworks to prevent access by malicious code.
org.openqa.selenium.WebDriverException: unknown error: cannot find MSEdge binary
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: '<host>', ip: '<ip>', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_221'
Driver info: driver.version: EdgeDriver
remote stacktrace: Backtrace:
    Ordinal0 [0x00007FF605E27542+1930562]
    Ordinal0 [0x00007FF605D8BCC2+1293506]
    Ordinal0 [0x00007FF605CF0801+657409]
    Ordinal0 [0x00007FF605C60F1F+69407]
    Ordinal0 [0x00007FF605C5EF02+61186]
    Ordinal0 [0x00007FF605C87C9D+228509]
    Ordinal0 [0x00007FF605C850EF+217327]
    Ordinal0 [0x00007FF605C6702F+94255]
    Ordinal0 [0x00007FF605C681EE+98798]
    Ordinal0 [0x00007FF605DAA6A1+1418913]
    GetHandleVerifier [0x00007FF605EE8AF9+656601]
    GetHandleVerifier [0x00007FF605EE8891+655985]
    GetHandleVerifier [0x00007FF605EF095C+688956]
    GetHandleVerifier [0x00007FF605EE92D3+658611]
    Ordinal0 [0x00007FF605DA069E+1377950]
    Ordinal0 [0x00007FF605DACB46+1428294]
    Ordinal0 [0x00007FF605DAB9BD+1423805]
    BaseThreadInitThunk [0x00007FFF02907974+20]
    RtlUserThreadStart [0x00007FFF0402A271+33]

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
    at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
    at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:207)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
    at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:141)
    at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:130)
    at com.testapp.base.TestBase.initialization(TestBase.java:73)
    at com.testingapp.testcases.BusyIndicatorTest.setUp(BusyIndicatorTest.java:48)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146)
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:166)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
    at org.testng.TestRunner.privateRun(TestRunner.java:744)
    at org.testng.TestRunner.run(TestRunner.java:602)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
    at org.testng.SuiteRunner.run(SuiteRunner.java:289)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
    at org.testng.TestNG.runSuites(TestNG.java:1144)
    at org.testng.TestNG.run(TestNG.java:1115)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
driver  : InternetExplorerDriver: internet explorer on WINDOWS (d8509abb-d16b-4872-bdc2-010789af308c)
Trying to find Element By : By.xpath: //div[@id='hamburger_menu']
Exception occured: org.openqa.selenium.NoSuchSessionException: session d8509abb-d16b-4872-bdc2-010789af308c does not exist
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: '<host>', ip: '<ip>', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_221'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ignoreProtectedModeSettings: true, ignoreZoomSetting: true, initialBrowserUrl: http://localhost:7136/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: accept}
Session ID: <id>

What I've tried: -

  1. initializing WebDriver driver = null in browser case class
  2. Control Panel -> Internet Options -> Security -> Disabled "protected zone" for all four zones
  3. ieCapabilities.setCapability("ignoreProtectedModeSettings", true); this is an alias for INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS
  4. if(driver != null) { driver.close(); }

I've tried all these which were mentioned in other stack overflow questions, however, I end up with the same error.

Do let me know if any more info. regarding the code is required.

EDIT:

I've noticed that my instance to the new InternetExplorerDriver has been striked through

driver = new InternetExplorerDriver (ieCapabilities);

This was striked, as DesiredCapabilities have been deprecated.

Before: -

DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability("ignoreProtectedModeSettings", true);
driver = new InternetExplorerDriver(ieCapabilities);

Now: -

InternetExplorerOptions IEoptions = new InternetExplorerOptions();
IEoptions.setCapability("ignoreProtectedModeSettings", true);
driver = new InternetExplorerDriver(IEoptions);

This fixed the striked-through.


When I run the IE set of tests individually i.e. without chrome, firefox & edge tests. I can see all the tests passing & no error at teardown method. I am Unable to figure out the reason!

Manny
  • 134
  • 2
  • 15
  • Try to put driver.close(); in Try block instead of catch block and try to check whether it works or not. Also try to inform the actual error returned by the code. It can give more idea about the issue. – Deepak-MSFT Oct 30 '19 at 09:08
  • I am calling driver.close() only for an exception. @Deepak-MSFT I've added console log for more error details – Manny Oct 30 '19 at 09:29
  • NoSuchSessionExpection happens when you try to perform actions after quitting the session. Ref: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/NoSuchSessionException.html Try to reinitialize the driver object before quitting it may help to solve the error. – Deepak-MSFT Oct 30 '19 at 09:52
  • @Deepak-MSFT Wouldn't adding a check of driver != null the same? As, mentioned in my question ~ I've already added that check. Also, please check the EDIT part above in my question - I'm not sure why my instance to InternetExplorerDriver has been striked through.. could this be the one of the reason? – Manny Oct 30 '19 at 10:06
  • That strike through line can be the reason for this error. Try to check whether object has proper driver assigned. try to put any other line of code after assigning the driver to verify that. It may help to narrow down the issue. – Deepak-MSFT Oct 30 '19 at 10:18
  • @Deepak-MSFT I added a print statement for driver object - **driver = InternetExplorerDriver: internet explorer on WINDOWS (37c112b4-a132-4a7a-a072-bf230fe4a684)Before navigating to: 'http://localhost:3000/'** Seems like it was assigned correctly. – Manny Oct 31 '19 at 03:35
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/201631/discussion-between-mansi-manhas-and-deepak-msft). – Manny Oct 31 '19 at 03:57
  • I am continuing the discussion in chat. – Deepak-MSFT Oct 31 '19 at 10:39

0 Answers0