Skip to content

Commit

Permalink
Merge pull request #34 from MathieuSoysal/18-add-script-to-get-the-ht…
Browse files Browse the repository at this point in the history
…ml-of-sbscription-page

18 add script to get the html of sbscription page
  • Loading branch information
MathieuSoysal authored Apr 28, 2023
2 parents 234c35a + 646d031 commit a4938b4
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 44 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/Check-in-automation.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
token: ${{ inputs.GITHUB_TOKEN }}
branch: archive
clean: false
folder: archive
target-folder: archive/${{ github.event.release.tag_name }}
2 changes: 1 addition & 1 deletion src/main/java/io/github/mathieusoysal/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/io/github/mathieusoysal/Roboto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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() {
Expand All @@ -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)));
Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@ public RefusedConnectionException() {
super("Connection refused, please check your login and password.");
}

@Override
public String getErrorType() {
return "RefusedConnectionException";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ public abstract class RobotoException extends Exception {
public RobotoException(String message) {
super(message);
}

public abstract String getErrorType();

}
22 changes: 12 additions & 10 deletions src/test/java/io/github/mathieusoysal/RobotoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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());
}

}

0 comments on commit a4938b4

Please sign in to comment.