Skip to content

Commit

Permalink
v0.4.1, added headless option to selecnium login handler and made tes…
Browse files Browse the repository at this point in the history
…t implementation
  • Loading branch information
marcosav committed Sep 25, 2022
1 parent a97ab93 commit e108aec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'com.gmail.marcosav2010'
version '0.4'
version '0.4.1'

publishing {
repositories {
Expand Down Expand Up @@ -45,7 +45,7 @@ dependencies {

implementation group: 'org.jsoup', name: 'jsoup', version: '1.15.3'

implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.4.0'
testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.4.0'

implementation group: 'org.projectlombok', name: 'lombok', version: '1.18.22'
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.22'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

Expand All @@ -23,13 +24,25 @@ public class SeleniumLoginHandler implements LoginHandler {
private static final String PASSWORD_FIELD_NAME = "password";
private static final String SUBMIT_BUTTON_XPATH = "//button[@type='submit']";

private final boolean headless;

public SeleniumLoginHandler() {
this(true);
}

public SeleniumLoginHandler(boolean headless) {
this.headless = headless;
}

@Override
public Map<String, String> login(String url, String username, String password) throws LoginException {
Map<String, String> cookies = new HashMap<>();
RemoteWebDriver driver = null;

try {
driver = new FirefoxDriver();
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(headless);
driver = new FirefoxDriver(options);

driver.get(url);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class TestMFPSession {
private static final String USER = System.getenv("MFP_USERNAME");
private static final String PASSWORD = System.getenv("MFP_PASSWORD");

private final LoginHandler loginHandler = new SeleniumLoginHandler();
private final LoginHandler loginHandler = new SeleniumLoginHandler(false);

@Test
void test() throws IOException, LoginException {
Expand Down

0 comments on commit e108aec

Please sign in to comment.