When we try to launch IE using WebDriver on a very first time on a fresh computer, generally we get the below error:
Exception in thread "main" 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)
We can avoid this using DesiredCapabilities method. The code can be:
DesiredCapabilities DC = DesiredCapabilities.internetExplorer();
DC.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
You can find more on this method here: DesiredCapabilities
So to run your test in IE browser here the complete code:
package WedriverPackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class crossBrowserTesting
{
public static void main(String[] args)
{
DesiredCapabilities DC = DesiredCapabilities.internetExplorer(); DC.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
System.setProperty("webdriver.ie.driver","C:\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver(DC);
driver.get("https://www.vishalsachan.blogspot.com/");
}
}
Software Testing, Test Automation, Test Consulting, and Trainings...... Learn from experience
Thursday, April 28, 2016
Wednesday, April 27, 2016
Handling multiple windows in selenium 2.0 (webdriver)
Here I am trying to explain the concept of Handling Multiple windows in Selenium WebDriver. Selenium WebDriver has built in methods
available to switch from one window to another window.
We will use :
WebDriver.getWindowHandles()
WebDriver.switchTo().window()
I am just pasting here the working code and that you can use in ur eclipse and try seeing how things works.
I am taking example of "www.timesjob.com" where you can click on links given in home page (top left side: ) to open multiple windows in webdriver.
I tried to explain the step by step action taken in code and hope this will help you understanding the code in better way.
---------------------------------------------------------------------------------------------------------------------------
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class HandlingWindows
{
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.timesjobs.com/");
/*below i m clicking to links given in home page which opening new windows*/
driver.findElement(By.xpath("html/body/div[1]/div[3]/header/nav[1]/ul/li[2]/a")).click();
driver.findElement(By.xpath("html/body/div[1]/div[3]/header/nav[1]/ul/li[3]/a")).click();
driver.findElement(By.xpath("html/body/div[1]/div[3]/header/nav[1]/ul/li[4]/a")).click();
/*so till now webdriver has opened 4 windows, one parent and 3 child. Now here next statement printing the current url that is of parent window.*/
System.out.println(driver.getCurrentUrl());
//Now using getWindowHandles method and get all handles of open window
Set AllWindow= driver.getWindowHandles();
String window1 = (String) AllWindow.toArray()[0];
String window2= (String) AllWindow.toArray()[1];
String window3= (String) AllWindow.toArray()[2];
String window4= (String) AllWindow.toArray()[3];
// Now here we can switch to any window using switchTo()
driver.switchTo().window(window2);
System.out.println(driver.getCurrentUrl());
/* I am just prinmting the URL to check if window is switching or not. here you can perform any operation in current focused window*/
driver.switchTo().window(window3);
System.out.println(driver.getCurrentUrl());
driver.switchTo().window(window4);
System.out.println(driver.getCurrentUrl());
driver.switchTo().window(window1);
System.out.println(driver.getCurrentUrl());
driver.quit();
}
}
---------------------------------------------------------------------------------------------------------------------
The output is :
http://www.timesjobs.com/
http://jobbuzz.timesjobs.com/
http://stepahead.timesjobs.com/
http://www.techgig.com/
http://www.timesjobs.com/
I hope this is simple way of learning the concept and now can try advance things.
We will use :
WebDriver.getWindowHandles()
WebDriver.switchTo().window()
I am just pasting here the working code and that you can use in ur eclipse and try seeing how things works.
I am taking example of "www.timesjob.com" where you can click on links given in home page (top left side: ) to open multiple windows in webdriver.
I tried to explain the step by step action taken in code and hope this will help you understanding the code in better way.
---------------------------------------------------------------------------------------------------------------------------
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class HandlingWindows
{
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.timesjobs.com/");
/*below i m clicking to links given in home page which opening new windows*/
driver.findElement(By.xpath("html/body/div[1]/div[3]/header/nav[1]/ul/li[2]/a")).click();
driver.findElement(By.xpath("html/body/div[1]/div[3]/header/nav[1]/ul/li[3]/a")).click();
driver.findElement(By.xpath("html/body/div[1]/div[3]/header/nav[1]/ul/li[4]/a")).click();
/*so till now webdriver has opened 4 windows, one parent and 3 child. Now here next statement printing the current url that is of parent window.*/
System.out.println(driver.getCurrentUrl());
//Now using getWindowHandles method and get all handles of open window
Set
String window1 = (String) AllWindow.toArray()[0];
String window2= (String) AllWindow.toArray()[1];
String window3= (String) AllWindow.toArray()[2];
String window4= (String) AllWindow.toArray()[3];
// Now here we can switch to any window using switchTo()
driver.switchTo().window(window2);
System.out.println(driver.getCurrentUrl());
/* I am just prinmting the URL to check if window is switching or not. here you can perform any operation in current focused window*/
driver.switchTo().window(window3);
System.out.println(driver.getCurrentUrl());
driver.switchTo().window(window4);
System.out.println(driver.getCurrentUrl());
driver.switchTo().window(window1);
System.out.println(driver.getCurrentUrl());
driver.quit();
}
}
---------------------------------------------------------------------------------------------------------------------
The output is :
http://www.timesjobs.com/
http://jobbuzz.timesjobs.com/
http://stepahead.timesjobs.com/
http://www.techgig.com/
http://www.timesjobs.com/
I hope this is simple way of learning the concept and now can try advance things.
Labels:
Automation
,
Selenium
,
webdriver
,
window handling
Thursday, April 7, 2016
Starting a new automation testing project
Initiating test automation on your project may seem
challenging, or even overwhelming and this is not going to be an cake walk for
sure.
I have been part of automation for legacy projects and delivered
my best without much pain. But when it comes to start a new automation project
, it required brain storming , home work
starting from presenting the benefit to management, convincing them for
adopting tools, resources ect.
I am considering two scenarios here
1- You
are part of any product base company or any startup and you are owner of QA
activities and you want to start with automation.
2- You
are part of large projects (mainly legacy systems, or applications) where
various factors comes in way to go for any automation implementation.
I would rather cover the first scenario also considering we
have to setup a team as well. That means there is no automation till now and
you are going to start with a new team.
Your work starts with the below questions and finding out
the answers:
- Have you done initial level of feasibility study to adopt the automation. This may include how we are going to be benefited. Do we have work which can be automated and fruitful doing so. Make a detail plan and present to management.
- Have you identified the automation tool. If that is open sources, language you need and do you the skills and funding for same? If that is paid, how you will get license, what type of licensing is there, what about support conditions ect.
- Once you have selected the tool, think about do you have skilled resources or you need trainings for them. If yes, how all those things will go. Make a Plan for this clearly.
Overall, it takes a champion, an advocate, to get automation
up and running on a project, but the payoff
can be worthwhile.
Once you are done with above things, next step would be to
start planning. Brainstorm with your team and plan a flexible framework. Think
modular. Create and use naming conventions. Plan for code and function re-use.
this is not end but this article give you starting idea about how to approach toward starting the automation in your project.
Subscribe to:
Posts
(
Atom
)