Skip to content

Commit

Permalink
Quality: removed unnecessary blank lines and used spaces for indents …
Browse files Browse the repository at this point in the history
…in stead of tabs
  • Loading branch information
awulder committed Feb 26, 2013
1 parent bd91233 commit 0d0446b
Show file tree
Hide file tree
Showing 21 changed files with 2,113 additions and 2,142 deletions.
Expand Up @@ -19,8 +19,8 @@

public class AssertionAndStopTestError extends AssertionError {

public AssertionAndStopTestError(Object detailMessage) {
super(detailMessage);
}
public AssertionAndStopTestError(Object detailMessage) {
super(detailMessage);
}

}
Expand Up @@ -25,9 +25,9 @@
*/
public interface ConfigurableWebDriverSupplier {

public void setBrowser(String browser);
public void setBrowser(String browser);

public void setCustomProfilePreferencesFile(File customProfilePreferencesFile);
public void setCustomProfilePreferencesFile(File customProfilePreferencesFile);

public void setProfileDirectory(File profileDirectory);
public void setProfileDirectory(File profileDirectory);
}
191 changes: 95 additions & 96 deletions src/main/java/com/xebia/incubator/xebium/DefaultWebDriverSupplier.java
Expand Up @@ -40,59 +40,58 @@

public class DefaultWebDriverSupplier implements ConfigurableWebDriverSupplier {

private static final Logger LOG = LoggerFactory.getLogger(SeleniumDriverFixture.class);
private static final Logger LOG = LoggerFactory.getLogger(SeleniumDriverFixture.class);

private String browser;
private String browser;

private File customProfilePreferencesFile;

private File profileDirectory;

public DefaultWebDriverSupplier() {
}

public WebDriver newWebDriver() {
WebDriver driver;
if ("firefox".equalsIgnoreCase(browser)) {
FirefoxProfile profile;
// Load FireFox-profile if present
if (profileDirectory != null) {
profile = new FirefoxProfile(profileDirectory);
LOG.info("Firefox profile successfully loaded");
}
else {
profile = new FirefoxProfile();
}

if (customProfilePreferencesFile != null) {
PreferencesWrapper prefs = loadFirefoxPreferences();

prefs.addTo(profile);
try {
StringWriter writer = new StringWriter(512);
prefs.writeTo(writer);
LOG.info("Added properties to firefox profile: " + writer.toString());
} catch (IOException e) {
LOG.error("Unable to log firefox profile settings", e);
}
}

// Ensure we deal with untrusted and unverified hosts.
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(true);

driver = new FirefoxDriver(profile);
} else if ("iexplore".equalsIgnoreCase(browser)) {
driver = new InternetExplorerDriver();
} else if ("chrome".equalsIgnoreCase(browser)) {
driver = new ChromeDriver();
} else if ("safari".equalsIgnoreCase(browser)) {
driver = new SafariDriver();
} else if ("htmlUnit".equalsIgnoreCase(browser)) {
driver = new HtmlUnitDriver();
} else if ("htmlUnit+js".equalsIgnoreCase(browser)) {
driver = new HtmlUnitDriver(true);
} else if ("opera".equalsIgnoreCase(browser)) {
private File profileDirectory;

public DefaultWebDriverSupplier() {
}

public WebDriver newWebDriver() {
WebDriver driver;
if ("firefox".equalsIgnoreCase(browser)) {
FirefoxProfile profile;
// Load FireFox-profile if present
if (profileDirectory != null) {
profile = new FirefoxProfile(profileDirectory);
LOG.info("Firefox profile successfully loaded");
} else {
profile = new FirefoxProfile();
}

if (customProfilePreferencesFile != null) {
PreferencesWrapper prefs = loadFirefoxPreferences();

prefs.addTo(profile);
try {
StringWriter writer = new StringWriter(512);
prefs.writeTo(writer);
LOG.info("Added properties to firefox profile: " + writer.toString());
} catch (IOException e) {
LOG.error("Unable to log firefox profile settings", e);
}
}

// Ensure we deal with untrusted and unverified hosts.
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(true);

driver = new FirefoxDriver(profile);
} else if ("iexplore".equalsIgnoreCase(browser)) {
driver = new InternetExplorerDriver();
} else if ("chrome".equalsIgnoreCase(browser)) {
driver = new ChromeDriver();
} else if ("safari".equalsIgnoreCase(browser)) {
driver = new SafariDriver();
} else if ("htmlUnit".equalsIgnoreCase(browser)) {
driver = new HtmlUnitDriver();
} else if ("htmlUnit+js".equalsIgnoreCase(browser)) {
driver = new HtmlUnitDriver(true);
} else if ("opera".equalsIgnoreCase(browser)) {
driver = new OperaDriver();
} else if ("opera-mobile-tablet".equalsIgnoreCase(browser)) {
DesiredCapabilities capabilities = DesiredCapabilities.opera();
Expand All @@ -112,52 +111,52 @@ public WebDriver newWebDriver() {
driver = new OperaDriver(capabilities);
} else if ("phantomjs".equalsIgnoreCase(browser)) {
driver = new PhantomJSDriver(DesiredCapabilities.phantomjs());
} else {
try {
driver = new RemoteWebDriverSupplier(browser).get();
} catch (Exception e) {
throw new RuntimeException("Unknown browser type. Should be one of 'firefox', 'iexplore', 'chrome', " +
} else {
try {
driver = new RemoteWebDriverSupplier(browser).get();
} catch (Exception e) {
throw new RuntimeException("Unknown browser type. Should be one of 'firefox', 'iexplore', 'chrome', " +
"'opera', 'opera-mobile-tablet', 'opera-mobile-phone', 'htmlUnit' or 'htmlUnit+js'", e);
}
}
return driver;
}

private PreferencesWrapper loadFirefoxPreferences() {
PreferencesWrapper prefs;
FileReader reader;
try {
reader = new FileReader(customProfilePreferencesFile);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
try {
prefs = new PreferencesWrapper(reader);
} finally {
try {
reader.close();
} catch (IOException e) {
LOG.error("Unable to close firefox profile settings file", e);
}
}
return prefs;
}

public void setBrowser(String browser) {
this.browser = browser;
}

public void setCustomProfilePreferencesFile(
File customProfilePreferencesFile) {
this.customProfilePreferencesFile = customProfilePreferencesFile;
}

public void setProfileDirectory(File profileDirectory) {
this.profileDirectory = profileDirectory;
}

@Override
public String toString() {
return getClass().getName();
}
}
}
return driver;
}

private PreferencesWrapper loadFirefoxPreferences() {
PreferencesWrapper prefs;
FileReader reader;
try {
reader = new FileReader(customProfilePreferencesFile);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
try {
prefs = new PreferencesWrapper(reader);
} finally {
try {
reader.close();
} catch (IOException e) {
LOG.error("Unable to close firefox profile settings file", e);
}
}
return prefs;
}

public void setBrowser(String browser) {
this.browser = browser;
}

public void setCustomProfilePreferencesFile(
File customProfilePreferencesFile) {
this.customProfilePreferencesFile = customProfilePreferencesFile;
}

public void setProfileDirectory(File profileDirectory) {
this.profileDirectory = profileDirectory;
}

@Override
public String toString() {
return getClass().getName();
}
}

0 comments on commit 0d0446b

Please sign in to comment.