0

Hi I am calling a login function but it throws a session not found exception I have saved Login as a library

import lib.Login;
public class MessageBoard {
WebDriver driver;
@BeforeMethod
public void initalise()
{
    System.setProperty("webdriver.ie.driver",     "C:\\Eclipse\\IEDriverServer.exe");
    DesiredCapabilities caps=new DesiredCapabilities();
    caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    driver=new InternetExplorerDriver(caps);
}

@Test
public void LogintoSystem()
{

    driver.manage().window().maximize();
    driver.get("http://segotn11540.rds.volvo.com/vss_connect_testr1/Login/Login.aspx");
    Login login=new Login("TYP40FI","Volvo");

}

I am getting the below error FAILED: LogintoSystem org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 555 milliseconds

Manish B
  • 389
  • 1
  • 4
  • 19
  • 2
    Possible duplicate of [Not able to launch IE browser using Selenium2 (Webdriver) with Java](http://stackoverflow.com/questions/14952348/not-able-to-launch-ie-browser-using-selenium2-webdriver-with-java) – JeffC Jul 18 '16 at 13:46

2 Answers2

1

I've had a similar issue, open up IE and make sure all zones the same in internet options --> security, change the Protected Mode settings in the browser to be the same, either enabled or disabled, but i recommend disabled if its only for testing purposed. Here is a great resource: Note from Jim Evans regarding the protected mode hack on http://jimevansmusic.blogspot.ca/2012/08/youre-doing-it-wrong-protected-mode-and.html: "The driver needed a workaround for people who couldn't set those IE settings because their machine was overly locked down. That's what the capability setting is intended to be used for. It simply bypasses the registry check. Using the capability doesn't solve the underlying problem though. If a Protected Mode boundary is crossed, very unexpected behavior including hangs, element location not working, and clicks not being propagated, could result. To help warn people of this potential problem, the capability was given big scary-sounding names like INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS in Java and IntroduceInstabilityByIgnoringProtectedModeSettings in .NET."

Moe Ghafari
  • 2,227
  • 1
  • 12
  • 17
  • I think the issue is something else It is launching the browser but when it comes to calling the login library it throws an exception I am attaching the code for Login Library 'public class Login { WebDriver driver; public Login(String UserName,String BrandName) { driver=new InternetExplorerDriver(); driver.findElement(By.xpath("//input[@name='UserNameInputText']")).sendKeys(UserName); driver.findElement(By.xpath("//input[@name='Brand']")).sendKeys(BrandName); driver.findElement(By.xpath("//input[@name='CmdLogin']")).click(); String Title=driver.getTitle(); – Manish B Jul 18 '16 at 12:39
  • read the article i added by editing the answer, I used to use the INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, but after reading it the only capability i use is ie.ensureCleanSession – Moe Ghafari Jul 18 '16 at 12:42
0

https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver

•On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".

----------------------------- EDITED ---------------------------------------

I see the actual problem, you basically have 2 different web drivers. 1 on the main test and the other 1 is on the Login class. I would suggest that you pass the webdriver from your main to the Login class

public class Login
{
   WebDriver driver;
   public Login(String UserName,String BrandName, WebDriver Driver)
   {
      driver = Driver; // Assign the driver from main to this Login class
      driver.findElement(By.xpath("//input[@name='UserNameInputText']")).sendKeys(Us‌​erName);
      driver.findElement(By.xpath("//input[@name='Brand']")).sendKeys(BrandName);
      driver.findElement(By.xpath("//input[@name='CmdLogin']")).click();
      String Title=driver.getTitle();
      // and so on...
   }
}

then on your main

@Test
public void LogintoSystem()
{

    driver.manage().window().maximize();
    driver.get("http://segotn11540.rds.volvo.com/vss_connect_testr1/Login/Login.aspx");
    Login login=new Login("TYP40FI","Volvo", driver); // pass the driver

}

Therefore you have the same driver with same session.

----------- EDIT 2 ---------------------

Remove the WebDriver in Login class and utilize the driver parameter to do the job.

public class Login
{
   public Login(String UserName,String BrandName, WebDriver Driver)
   {
      Driver.findElement(By.xpath("//input[@name='UserNameInputText']")).sendKeys(Us‌​erName);
      Driver.findElement(By.xpath("//input[@name='Brand']")).sendKeys(BrandName);
      Driver.findElement(By.xpath("//input[@name='CmdLogin']")).click();
      String Title=Driver.getTitle();
      // and so on...
   }
}

The main stays the same.

kurakura88
  • 2,185
  • 2
  • 12
  • 18
  • But i have used the below statement caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); – Manish B Jul 18 '16 at 12:18
  • that does not have anything to do with the IE Protection Mode error that you have. You still need to either set or disable the Protected Mode on all zones. – kurakura88 Jul 18 '16 at 12:25
  • Disregard my previous comment. I think I understood your actual problem. I added into my previous answer. – kurakura88 Jul 19 '16 at 01:07
  • Hi Kurakura, Your code is perfectly ok but i still need to declare WebDriver,driver in both the classes How can i make same driver with same session – Manish B Jul 20 '16 at 11:05
  • If you need 2 drivers with same session, then my previous answer fits your need. If you need just 1 driver for all, then I would suggest you declare the webdriver as static, therefore it is available for everyone. Your edited code looks ok to me though. – kurakura88 Jul 21 '16 at 00:56
  • Hello Kurakura, My question is if i need to run 1 session of webdriver,how i can achieve that Because the code you have given,i still need to declare webdriver in both the files which means 2 instances of webdriver – Manish B Jul 21 '16 at 11:57
  • There, updated the answer. Pretty straight forward, where you don't need the WebDriver in Login class. The constructor will utilize the WebDriver parameter to do the job. – kurakura88 Jul 22 '16 at 01:04