diff --git a/.github/workflows/Check-in-automation.yml b/.github/workflows/Check-in-automation.yml new file mode 100644 index 0000000..1f11263 --- /dev/null +++ b/.github/workflows/Check-in-automation.yml @@ -0,0 +1,36 @@ +name: JIB container publish + +on: + workflow_dispatch: + +jobs: + + check-in-automation: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'adopt' # Alternative distribution options are available. + - name: Cache Maven packages + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + - name: Build + run: mvn compile + - name: Run + run: mvn exec:java -Dexec.mainClass="io.github.mathieusoysal.App" + + - name: Save trace + uses: JamesIves/github-pages-deploy-action@v4.4.1 + with: + token: ${{ inputs.GITHUB_TOKEN }} + branch: archive + clean: false + folder: archive + target-folder: archive/${{ github.event.release.tag_name }} \ No newline at end of file diff --git a/src/main/java/io/github/mathieusoysal/App.java b/src/main/java/io/github/mathieusoysal/App.java index dffb6be..5260560 100644 --- a/src/main/java/io/github/mathieusoysal/App.java +++ b/src/main/java/io/github/mathieusoysal/App.java @@ -17,7 +17,7 @@ public static void main(String[] args) { try (Roboto roboto = new Roboto()) { checkAllEnvVariables(ENV_NAME_MAIL, ENV_NAME_PASSWORD); roboto.connect(System.getenv(ENV_NAME_MAIL), System.getenv(ENV_NAME_PASSWORD)); - while (!roboto.checkinButtonIsPresent()) + while (roboto.checkinButtonIsPresent()) roboto.refreshPage(); roboto.clickOnSubscription(); } catch (RobotoException e) { diff --git a/src/main/java/io/github/mathieusoysal/Roboto.java b/src/main/java/io/github/mathieusoysal/Roboto.java index 4c4d1fd..065bfd9 100644 --- a/src/main/java/io/github/mathieusoysal/Roboto.java +++ b/src/main/java/io/github/mathieusoysal/Roboto.java @@ -42,6 +42,8 @@ public class Roboto implements AutoCloseable { private boolean telemetry = true; + private String pageContent = ""; + public Roboto(final String admissionURL, final boolean telemetry) { this.telemetry = telemetry; playwright = Playwright.create(); @@ -81,10 +83,10 @@ public void connect(String email, String password) fillPasswordField(password); clickSubmitButton(); page.waitForLoadState(); - String stateAfterConnection = page.url(); - if (stateBeforeConnection.equals(stateAfterConnection)) { + String currentState = page.url(); + if (stateBeforeConnection.equals(currentState)) { trace = "RefusedConnection"; - LOGGER.error(() -> "Connection refused"); + LOGGER.error(() -> "Connection refused check your credentials"); throw new RefusedConnectionException(); } LOGGER.info(() -> "Roboto is signed in to " + admissionURL); @@ -97,9 +99,9 @@ public void refreshPage() { public boolean checkinButtonIsPresent() { page.waitForLoadState(); - return page.locator( - "input[type='submit'] :not([value='Enregistrement impossible']) :not([value='Can not subscribe'])") - .last().isVisible(); + if (pageContent.equals("")) + pageContent = page.content(); + return !pageContent.equals(page.content()); } public void subcribeToCheckIn() { @@ -110,7 +112,8 @@ public void subcribeToCheckIn() { @Override public void close() { if (telemetry) { - String archiveName = trace + "-" + LocalDateTime.now(ZoneId.systemDefault()).toString().replaceAll(":", "-") + String archiveName = "archive/" + trace + "-" + + LocalDateTime.now(ZoneId.systemDefault()).toString().replaceAll(":", "-") + ".zip"; context.tracing().stop(new Tracing.StopOptions() .setPath(Paths.get(archiveName))); @@ -171,9 +174,9 @@ void validateCaptcha() { } void clickOnSubscription() { - page.locator("input[type='submit'] :not([value='Enregistrement impossible']) :not([value='Can not subscribe'])") - .last().click(); - LOGGER.info(() -> "Subscription clicked"); + // page.locator("input[type='submit'] :not([value='Enregistrement impossible']) + // :not([value='Can not subscribe'])").last().click(); + // LOGGER.info(() -> "Subscription clicked"); // TODO: Add a check to see if the subscription is successful } diff --git a/src/main/java/io/github/mathieusoysal/exceptions/ConnectionButtonNotFoundException.java b/src/main/java/io/github/mathieusoysal/exceptions/ConnectionButtonNotFoundException.java index 0b94847..416b349 100644 --- a/src/main/java/io/github/mathieusoysal/exceptions/ConnectionButtonNotFoundException.java +++ b/src/main/java/io/github/mathieusoysal/exceptions/ConnectionButtonNotFoundException.java @@ -8,9 +8,4 @@ public ConnectionButtonNotFoundException(String url, String selector) { super("Connection button not found on " + url + " with selector " + selector); } - @Override - public String getErrorType() { - return "ConnectionButtonNotFoundException"; - } - } diff --git a/src/main/java/io/github/mathieusoysal/exceptions/EmailFieldNotFoundException.java b/src/main/java/io/github/mathieusoysal/exceptions/EmailFieldNotFoundException.java index 1e7677a..4cbc2f4 100644 --- a/src/main/java/io/github/mathieusoysal/exceptions/EmailFieldNotFoundException.java +++ b/src/main/java/io/github/mathieusoysal/exceptions/EmailFieldNotFoundException.java @@ -8,9 +8,4 @@ public EmailFieldNotFoundException(String url, String cssSelector) { super("Email field not found on: " + url + " with CSS selector:" + cssSelector); } - @Override - public String getErrorType() { - return "EmailFieldNotFoundException"; - } - } diff --git a/src/main/java/io/github/mathieusoysal/exceptions/PasswordFieldNotFoundException.java b/src/main/java/io/github/mathieusoysal/exceptions/PasswordFieldNotFoundException.java index 188a702..54ffe6b 100644 --- a/src/main/java/io/github/mathieusoysal/exceptions/PasswordFieldNotFoundException.java +++ b/src/main/java/io/github/mathieusoysal/exceptions/PasswordFieldNotFoundException.java @@ -7,9 +7,4 @@ public class PasswordFieldNotFoundException extends RobotoException { public PasswordFieldNotFoundException(String url, String cssSelector) { super("Password field not found on: " + url + " with CSS selector:" + cssSelector); } - - @Override - public String getErrorType() { - return "PasswordFieldNotFoundException"; - } } diff --git a/src/main/java/io/github/mathieusoysal/exceptions/RefusedConnectionException.java b/src/main/java/io/github/mathieusoysal/exceptions/RefusedConnectionException.java index 9a50806..dae1955 100644 --- a/src/main/java/io/github/mathieusoysal/exceptions/RefusedConnectionException.java +++ b/src/main/java/io/github/mathieusoysal/exceptions/RefusedConnectionException.java @@ -6,9 +6,4 @@ public RefusedConnectionException() { super("Connection refused, please check your login and password."); } - @Override - public String getErrorType() { - return "RefusedConnectionException"; - } - } diff --git a/src/main/java/io/github/mathieusoysal/exceptions/RobotoException.java b/src/main/java/io/github/mathieusoysal/exceptions/RobotoException.java index cc8d757..847ea69 100644 --- a/src/main/java/io/github/mathieusoysal/exceptions/RobotoException.java +++ b/src/main/java/io/github/mathieusoysal/exceptions/RobotoException.java @@ -5,7 +5,4 @@ public abstract class RobotoException extends Exception { public RobotoException(String message) { super(message); } - - public abstract String getErrorType(); - } diff --git a/src/test/java/io/github/mathieusoysal/RobotoTest.java b/src/test/java/io/github/mathieusoysal/RobotoTest.java index c136b7f..942c6e7 100644 --- a/src/test/java/io/github/mathieusoysal/RobotoTest.java +++ b/src/test/java/io/github/mathieusoysal/RobotoTest.java @@ -6,7 +6,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.microsoft.playwright.Page; @@ -106,16 +108,6 @@ void clickSubmitButton_witWrongURL_test() { roboto.close(); } - @Test - void checkinButtonIsPresent_test() throws EmailFieldNotFoundException, PasswordFieldNotFoundException, - ConnectionButtonNotFoundException, RefusedConnectionException { - Roboto roboto = new Roboto(false); - roboto.connect(System.getenv("TEST_EMAIL"), System.getenv("TEST_PASSWORD")); - assertFalse(roboto.checkinButtonIsPresent()); - roboto.close(); - // TODO: find a way to test the checkin button - } - @Test void captachaTest() throws EmailFieldNotFoundException, PasswordFieldNotFoundException, ConnectionButtonNotFoundException, RefusedConnectionException { @@ -126,4 +118,14 @@ void captachaTest() throws EmailFieldNotFoundException, PasswordFieldNotFoundExc // TODO: find a way to test the captcha } + @Test + void testCheckinButtonIsNotPresent() throws EmailFieldNotFoundException, PasswordFieldNotFoundException, + ConnectionButtonNotFoundException, RefusedConnectionException { + Roboto roboto = new Roboto(false); + roboto.getPage().setDefaultTimeout(5000); + roboto.connect(System.getenv("TEST_EMAIL"), System.getenv("TEST_PASSWORD")); + assertFalse(roboto.checkinButtonIsPresent()); + assertFalse(roboto.checkinButtonIsPresent()); + } + }