Frequently
we need to run selenium WebDriver test in different browsers
like IE, Google Chrome, Opera, Mozilla Firefox etc.. for browser
compatibility software testing. Selenium WebDriver software testing tool has
separate driver for each browser. Selenium WebDriver has InternetExplorerDriver for IE
browser. Earlier, I have already described HOW TO RUNWEBDRIVER TEST SCRIPT IN FIREFOX and HOW TO RUNTEST SCRIPT IN GOOGLE CHROME BROWSER. Now let's learn how
to run WebDriver test In IE for software web application.
Configuration
Steps To Run WebDriver Test In IE
Step
1 : Download IEDriverServer.exe
For
running web application's software test In IE browser, you
need IEDriverServer.exe. You can download It from below given
link.
- You can download It from THIS PAGE too as shown In bellow Image.
Save
IEDriverServer.exe In your D: drive.
Step
2 : Configure IE Browser To Resolve Expected Errors
Before
running your software automation test In IE browser, You need to configure your
IE browser to resolved bellow given 2 common errors which people are facing
occasionally.
Error
1 : 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).
Error
2 : Exception in thread
"main" org.openqa.selenium.remote.SessionNotFoundException:
Unexpected error launching Internet Explorer. Browser zoom level was set to
200%. It should be set to 100% (WARNING: The server did not provide any
stacktrace information).
Solution
to resolve above errors Is as below.
Solution
To Resolve Error 1 : Enable protected mode for all zones
You
need to enable protected mode for all zones from Internet Options ->
Security tab. To enable protected mode for all zones
- Open
Internet Explorer browser.
- Go to
menu Tools -> Internet Options.
- Click
on Security tab.
- Select Internet from
"Select a zone to view or change security settings" and Select(check) check
box "Enable Protected Mode" from In the "Security level for
this zone" block as shown In bellow Images.
- Apply
same thing for all other 3 zones -> Local Internet, Trusted
Sites and Restricted Sites as shown In bellow
Images.
Solution
To Resolve Error 2 : Set IE browser zoom level to 100%
By
default, IE browser's zoom level will be 100%. But If someone has changed It to
200% or any other level then you will face error during webdriver software test
execution In IE browser and your test will fail. You need to set IE browser's
zoom level 100%.
To
Set IE browser's zoom level 100%
- Open
Internet Explorer browser.
- Go to
menu View -> Zoom -> Select
100% as shown In bellow Image.
This setting
will resolve error related to "Browser zoom level was set to 200%. It
should be set to 100%"
Step
3 : Execute First WebDriver Test In Internet Explorer browser
Now
you are all set to execute first selenium webdriver In IE browser. I have
created sample test to run test In IE browser. Execute bellow given sample calc
test In eclipse and verify Its output In console.
IEBrowserSampleTest.java
import
org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.ie.InternetExplorerDriver;
public class IEBrowserSampleTest
{
public
static void main(String[] args) throws Exception
{
//
Set path of IEDriverServer.exe.
// Note : IEDriverServer.exe should be In D: drive.
System.setProperty("webdriver.ie.driver", "D://IEDriverServer.exe");
// Note : IEDriverServer.exe should be In D: drive.
System.setProperty("webdriver.ie.driver", "D://IEDriverServer.exe");
//
Initialize InternetExplorerDriver Instance.
WebDriver
driver = new InternetExplorerDriver();
//
Load sample calc test URL.
driver.get("http://only-testing-blog.blogspot.com/2014/04/calc.html");
//
Execute sample calc test.
driver.findElement(By.xpath("//input[@id='1']")).click();
driver.findElement(By.xpath("//input[@id='plus']")).click();
driver.findElement(By.xpath("//input[@id='6']")).click();
driver.findElement(By.xpath("//input[@id='equals']")).click();
String
result = driver.findElement(By.xpath("//input[@id='Resultbox']")).getAttribute("value");
System.out.println("Calc
test result Is : " + result); driver.close();
}
}
At the end of
execution, console output will be looks like bellow.
No comments:
Post a Comment