karishma yadav
karishma yadav

Reputation: 15

IE browser is not getting closed after test run

I ran Selenium code for Cross-Browser testing using TestNG,After process chrome browser is getting closed but IE is not getting closed after the run. Below is the code for Browser Testing :

package learningTestNGVideo;
import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class CrossBrowserTesting {
    //global variable WebDriver
    public WebDriver driver;
    @Parameters("browser")
    @BeforeClass
    public void LaunchBrowser(String browser){

        if(browser.equalsIgnoreCase("IE")){
            System.setProperty("webdriver.ie.driver","E:\\Selenium2018\\IEDriverServer_x64_3.8.0\\IEDriverServer.exe");
            driver= new InternetExplorerDriver();
        }
        else if(browser.equalsIgnoreCase("Chrome")){
            System.setProperty("webdriver.chrome.driver","E:\\Selenium2018\\setup\\chromedriver_win32\\chromedriver.exe");
            driver= new ChromeDriver();

        }
        else if(browser.equalsIgnoreCase("firefox")){
            System.setProperty("webdriver.gecko.driver","E:\\Selenium2018\\geckodriver-v0.19.1-win64\\geckodriver.exe");

            driver= new FirefoxDriver();
        }

    driver.get("http://automationpractice.com/index.php");
    }

    @Test
    public void ClickonSignIn(){

        driver.findElement(By.xpath(".//*[@id='header']/div[2]/div/div/nav/div[1]/a")).click();
        System.out.println("Successfull");
        }
    @AfterMethod
    public void CloseBrowser() throws IOException{
        driver.close();
    }

}

Below is the Error I am getting for Close browser method

 org.openqa.selenium.NoSuchWindowException: Unable to get browser
    Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:14.666Z'
    System info: host: '####', ip: '####', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
    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: false, ignoreZoomSetting: false, initialBrowserUrl: http://localhost:25599/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
    Session ID: e346d8bb-4875-4567-902e-428e73f34013
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

Here is xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite1" parallel="tests">
  <test name="Test-IE">
    <parameter name="browser" value="IE"></parameter>
    <classes>
      <class name="learningTestNGVideo.CrossBrowserTesting" />
    </classes>
  </test>
  <!-- Test -->
  <test name="Test-Firefox">
    <parameter name="browser" value="firefox"></parameter>
    <classes>
      <class name="learningTestNGVideo.CrossBrowserTesting" />
    </classes>
  </test>
  <test name="Test-Chrome">
    <parameter name="browser" value="chrome"></parameter>
    <classes>
      <class name="learningTestNGVideo.CrossBrowserTesting" />
    </classes>
  </test>
</suite>
<!-- Suite -->

Upvotes: 0

Views: 238

Answers (1)

hiren
hiren

Reputation: 1105

The issue here seems to be with the security settings of your IE. All security zones should be set to the same Protected Mode setting. I found that setting the Local Intranet zone's Enable Protected Mode setting to true can solve this problem.

Press the Alt key to bring up the IE11 menu bar. Select Tools > Internet Options and go to the Security tab. Select each zone (Internet, Local intranet, Trusted sites, Restricted sites) and check the Enable Protected Mode checkbox.

Upvotes: 1

Related Questions