Skip to content

Commit

Permalink
Add a way to override browser factory
Browse files Browse the repository at this point in the history
Use the parameter browser.factory to select a class implementing
TestBenchBrowserFactory.

Change-Id: Ibc1f11ad83f8ac1ed85766892cfa0463af9bf440
  • Loading branch information
Henri Sara committed Apr 28, 2016
1 parent 4410535 commit ae44989
Showing 1 changed file with 31 additions and 0 deletions.
Expand Up @@ -15,17 +15,44 @@
*/
package com.vaadin.tests.tb3;

import java.util.logging.Logger;

import org.openqa.selenium.Platform;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.vaadin.testbench.parallel.Browser;
import com.vaadin.testbench.parallel.DefaultBrowserFactory;
import com.vaadin.testbench.parallel.TestBenchBrowserFactory;

public class VaadinBrowserFactory extends DefaultBrowserFactory {

TestBenchBrowserFactory delegate = null;

@Override
public DesiredCapabilities create(Browser browser) {
String browserFactoryClass = System.getProperty("browser.factory");
if (browserFactoryClass != null
&& !browserFactoryClass.trim().isEmpty()) {
if (delegate == null) {
getLogger()
.info("Using browser factory " + browserFactoryClass);
try {
delegate = (TestBenchBrowserFactory) getClass()
.getClassLoader().loadClass(browserFactoryClass)
.newInstance();
} catch (Exception e) {
getLogger().warning("Failed to instantiate browser factory " + browserFactoryClass);
throw new RuntimeException(e);
}
}
return delegate.create(browser);
}

return doCreate(browser);
}

public DesiredCapabilities doCreate(Browser browser) {
switch (browser) {
case IE8:
return createIE(browser, "8");
Expand Down Expand Up @@ -59,4 +86,8 @@ public DesiredCapabilities create(Browser browser, String version) {
capabilities.setVersion(version);
return capabilities;
}

private static final Logger getLogger() {
return Logger.getLogger(VaadinBrowserFactory.class.getName());
}
}

0 comments on commit ae44989

Please sign in to comment.