-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Click JS Update and Unit Test Upgrades (#1)
# Features * Add JS mode to Click * Add scroll-into-view operation for every click expression * Add Expression unit tests * Update documentation and warning suppressions * Add version option for cmd line mode * Add default case to all switch statements (should be impossible to reach any exception with 'FATAL' tag) * Remove unused code from For * Add DriverFactory # Bug Fixes * Remove unused code from For * Remove plural-required-field utility function from Expression * Remove unused utility functions from Expression * Fix Screenshot bug which added an extra '-' to the tag name * Fix switch-case bug(s)
- Loading branch information
1 parent
ec51818
commit db8db79
Showing
23 changed files
with
458 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/uk/co/spicule/magnesium_script/DriverFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package uk.co.spicule.magnesium_script; | ||
|
||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.chrome.ChromeDriver; | ||
import org.openqa.selenium.chrome.ChromeOptions; | ||
import org.openqa.selenium.edge.EdgeDriver; | ||
import org.openqa.selenium.edge.EdgeOptions; | ||
import org.openqa.selenium.firefox.FirefoxDriver; | ||
import org.openqa.selenium.firefox.FirefoxOptions; | ||
import uk.co.spicule.magnesium_script.expressions.Expression; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class DriverFactory { | ||
public enum BrowserType { | ||
FIREFOX, | ||
CHROME, | ||
EDGE; | ||
|
||
public static BrowserType stringToEnum(String name) throws Expression.InvalidExpressionSyntax { | ||
return BrowserType.valueOf(Expression.validateTypeClass(BrowserType.class, name)); | ||
} | ||
} | ||
|
||
// Instance things | ||
ArrayList<String> options = new ArrayList<String>() { | ||
{ | ||
add("--no-sandbox"); | ||
add("--disable-gpu"); | ||
add("--disable-extensions"); | ||
add("--ignore-certificate-errors"); | ||
add("--incognito"); | ||
add("--window-size=1920,1080"); | ||
add("--proxy-server='direct://"); | ||
add("--proxy-bypass-list=*"); | ||
add("--disable-background-networking"); | ||
add("--safebrowsing-disable-auto-update"); | ||
add("--disable-sync"); | ||
add("--metrics-recording-only"); | ||
add("--disable-default-apps"); | ||
add("--no-first-run"); | ||
add("--disable-setuid-sandbox"); | ||
add("--hide-scrollbars"); | ||
add("--no-zygote"); | ||
add("--disable-notifications"); | ||
add("--disable-logging"); | ||
add("--disable-permissions-api"); | ||
} | ||
}; | ||
|
||
public DriverFactory(boolean headless) { | ||
if(headless) { | ||
options.add("--headless"); | ||
} | ||
} | ||
|
||
public ChromeOptions buildChromeOptions() { | ||
ChromeOptions options = new ChromeOptions(); | ||
this.options.forEach(options::addArguments); | ||
return options; | ||
} | ||
|
||
public FirefoxOptions buildFirefoxOptions() { | ||
FirefoxOptions options = new FirefoxOptions(); | ||
this.options.forEach(options::addArguments); | ||
return options; | ||
} | ||
|
||
public EdgeOptions buildEdgeOptions() { | ||
return new EdgeOptions(); | ||
} | ||
|
||
public WebDriver build(BrowserType type) { | ||
switch(type) { | ||
case CHROME: | ||
return new ChromeDriver(buildChromeOptions()); | ||
case EDGE: | ||
return new EdgeDriver(buildEdgeOptions()); | ||
case FIREFOX: | ||
return new FirefoxDriver(buildFirefoxOptions()); | ||
default: | ||
throw new RuntimeException("FATAL: Invalid browser-type: " + type); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.