Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

76
LINES

< > BotCompany Repo | #1032459 // GazelleSiteTester - test Gazelle sites using Playwright

JavaX fragment (include) [tags: use-pretranspiled]

Uses 64664K of libraries. Click here for Pure Java version (5824L/32K).

sclass GazelleSiteTester implements AutoCloseable {
  PlaywrightAndBrowser playwright;
  S site = "https://empty.gazelle.rocks";
  new Scorer scorer;
  
  void init {
    playwright if null = playwrightWithChromium();
  }
  
  abstract class Tester {
    Page page;
    
    void assertPageContainsText(S text) {
      assertNotNull(scorer, text, page.querySelector("text=" + text));
    }
    
    void openSite {
      init();
      page = playwrightOpenPage(playwright.browser, page, site);
    }
    
    void fill(O... _) {
      for (O key, O val : paramsToObjectMap(_))
        page.fill("[name=" + key + "]", str(val));
    }
  }
  
  class TestRegistration extends Tester {
    S user = "testuser" + random(1000000);
    S pw = "pw" + random(1000000);
    S contact = "dummy contact";
    
    run {
      openSite();
      page.click("text=Register as new user");
      fill(+user, f_pw := pw, pw2 := pw, +contact);
      page.click([[[type=submit]:has-text("Register")]]);
      assertPageContainsText(dollarFormat("User $user created", +user));
    }
  }
  
  class LogIn extends Tester {
    S user;
    S pw;
    double delay = 3.0;
    
    run {
      openSite();
      page.fill("[name=user]", user);
      page.fill("[name=pw]", pw);
      
      page.click([[[type=submit]:has-text("Log in")]]);
      sleepSeconds(delay);
      //page.waitForLoadState(); 
      /*page.waitForNavigation(() -> {
        page.click([[[type=submit]:has-text("Log in")]]);
      });*/
      
      assertPageContainsText("[user " + user + "]");
      assertPageContainsText("BEA Objects");
    }
  }
  
  LogIn registerAndLogIn() {
    new TestRegistration reg;
    reg.run();
    new LogIn logIn;
    copyFields(reg, logIn, "user", "pw", "page");
    logIn.run();
    ret logIn;
  }
  
  public void close { dispose playwright; }
  
  toString { ret "Tested " + site + ": " + scorer; }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032459
Snippet name: GazelleSiteTester - test Gazelle sites using Playwright
Eternal ID of this version: #1032459/26
Text MD5: ebd986a105faf262f07d9bf709616930
Transpilation MD5: 5ef5a66bc726d2a4d969bf89fb45f8e9
Author: stefan
Category: javax / gazelle / networking
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-08 00:29:04
Source code size: 1963 bytes / 76 lines
Pitched / IR pitched: No / No
Views / Downloads: 198 / 387
Version history: 25 change(s)
Referenced in: [show references]