Skip to content

Commit

Permalink
Add script to get html page
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuSoysal authored Apr 26, 2023
1 parent 234c35a commit 19d8ee5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
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.checkinButtonIsNotPresent())
roboto.refreshPage();
roboto.clickOnSubscription();
} catch (RobotoException e) {
Expand Down
22 changes: 12 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 @@ -95,11 +97,11 @@ public void refreshPage() {
LOGGER.info(() -> "Page refreshed");
}

public boolean checkinButtonIsPresent() {
public boolean checkinButtonIsNotPresent() {
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 Down Expand Up @@ -171,9 +173,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
13 changes: 12 additions & 1 deletion src/test/java/io/github/mathieusoysal/RobotoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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.Test;

Expand Down Expand Up @@ -111,7 +112,7 @@ void checkinButtonIsPresent_test() throws EmailFieldNotFoundException, PasswordF
ConnectionButtonNotFoundException, RefusedConnectionException {
Roboto roboto = new Roboto(false);
roboto.connect(System.getenv("TEST_EMAIL"), System.getenv("TEST_PASSWORD"));
assertFalse(roboto.checkinButtonIsPresent());
assertFalse(roboto.checkinButtonIsNotPresent());
roboto.close();
// TODO: find a way to test the checkin button
}
Expand All @@ -126,4 +127,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(1000);
roboto.connect(System.getenv("TEST_EMAIL"), System.getenv("TEST_PASSWORD"));
assertTrue(roboto.checkinButtonIsNotPresent());
assertTrue(roboto.checkinButtonIsNotPresent());
}

}

0 comments on commit 19d8ee5

Please sign in to comment.