Recently I was working in a POC for Cross Browser testing
using Selenium 2. My objective is to automate the application in IE, Firefox,
Chrome and Safari ( MAC). I will share basic code and observation in this post.
Prerequisite: Web Driver 2.25.jar, Eclipse IDE, ChromeDriver.exe,
IE Driver.exe, Safari Extension.
- 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".
- The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates for IE driver.
- As Safari web driver is not available, currently Safari Driver is implemented as a Safari browser extension. Refer below link to configure safari extension
Code:
public class ResourceManager {
private WebDriver driver;
public static
WebDriver globalSeleniumInstance;
@Parameters({ "browser"})
public void beforeSuite(int
browser) throws MalformedURLException
{
System.out.println("browser is
"+ browser);
switch(browser)
{
case
1 :
System.out.println("Running FireFox");
driver = new FirefoxDriver();
break;
case
2 :
System.setProperty("webdriver.chrome.driver","C:\\Seleniumworkspace\\BasicTN8\\chromedriver.exe");
System.out.println("Running Chrome");
driver
= new ChromeDriver();
break;
case 3 :
System.setProperty("webdriver.ie.driver","C:\\Seleniumworkspace\\BasicTN8\\IEDriverServer.exe");
DesiredCapabilities dc =
DesiredCapabilities.internetExplorer();
dc.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
driver
= new InternetExplorerDriver(dc);
driver.manage().deleteAllCookies();
break;
case 4:
System.out.println("Running Safari");
driver
= new SafariDriver();
break;
default :
driver
= new FirefoxDriver();
break;
}
globalSeleniumInstance = driver;
}
@AfterSuite
public void
afterSuite() throws
InterruptedException {
System.out.println("after Suite");
Thread.sleep(5000);
driver.quit();
}
}
Observation: Chrome and Firefox driver worked very well. I faced some issue with IE Driver. IEDriver
is slow compare to Chrome and Firefox driver. Also some time we are getting out
of focus issue with IE Driver.
As stated earlier, Safari driver is not fully functional,
some operation like Drag & Drop are not yet supported. As an alternative we
can use java script to perform those operations or can use Java.awt.robot class
to simulate mouse movement or Drag & Drop operation in Safari Web driver.
Bellevue Locksmith THANKS FOR SHARING
ReplyDeletejava.lang.Exception: Method openBrowser should have no parameters
ReplyDeleteat org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java:69)
at org.junit.runners.ParentRunner.validatePublicVoidNoArgMethods(ParentRunner.java:131)
at org.junit.runners.ParentRunner.collectInitializationErrors(ParentRunner.java:111)
at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:98)
at org.junit.runners.ParentRunner.validate(ParentRunner.java:344)
at org.junit.runners.ParentRunner.(ParentRunner.java:74)
at org.junit.runners.BlockJUnit4ClassRunner.(BlockJUnit4ClassRunner.java:55)
at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestMethodReference.(JUnit4TestMethodReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:54)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
I am using JUnit and getting the above error. Help please................
ReplyDeletepublic class BhuiyanBase extends BhuiyanAbstract {
private static WebDriver driver;
public static WebDriver globalSeleniumInstance;
@BeforeClass
public static void openBrowser(int browser) throws MalformedURLException {
System.out.println("browser is "+ browser);
switch(browser)
{
case 1 :
System.out.println("Running FireFox");
driver = new FirefoxDriver();
break;
case 2 :
System.setProperty("webdriver.chrome.driver","C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe");
System.out.println("Running Chrome");
driver = new ChromeDriver();
break;
case 3 :
System.setProperty("webdriver.ie.driver","C:\\Program Files (x86)\\Internet Explorer\\IEDriverServer.exe");
DesiredCapabilities dc = DesiredCapabilities.internetExplorer();
dc.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
driver = new InternetExplorerDriver(dc);
driver.manage().deleteAllCookies();
break;
case 4:
System.out.println("Running Safari");
driver = new SafariDriver();
break;
default :
driver = new FirefoxDriver();
break;
}
globalSeleniumInstance = driver;
}
@Before
public void setUp() {
driver.get("https://www.bhuiyan.us");
}
@AfterClass
public static void tearDown(){
driver.close();
}
}
u have to assign the value to the browser(i.e variable which is available in OpenBrowser method)before to the @beforeclass annotation.
ReplyDeletethat value u can get from any other external resource(like Excel)
DeletePretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon.
ReplyDeleteSoftware Testing Services
Software Testing Company
Software Testing Companies
QA Testing Services
Functional Testing Services
Test Automation Services
Functional Testing Company
Performance Testing Services
Security Testing Services
API Testing Services
i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
ReplyDeleteTop QA Companies
Top Automation Testing Companies
Top Mobile App Testing Companies
Top Performance Testing Companies
Top Security Testing Companies
ReplyDeleteI am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
Top Software Testing Companies
Top Security Testing Companies
Top Mobile Testing Companies
Top Test Automation Companies
Top Performance Testing Companies
Website testing services
Thank you so much for this nice information. Hope so many people will get aware of this and useful as well. And please keep update like this.
ReplyDeleteServerless Data Warehouse
Benefits of Agile Testing
Top Node.js Frameworks
Ai in banking
Data Migration Tools
Big Data Companies
Penetration Testing Companies
Software Testing Companies