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).

1  
sclass GazelleSiteTester implements AutoCloseable {
2  
  PlaywrightAndBrowser playwright;
3  
  S site = "https://empty.gazelle.rocks";
4  
  new Scorer scorer;
5  
  
6  
  void init {
7  
    playwright if null = playwrightWithChromium();
8  
  }
9  
  
10  
  abstract class Tester {
11  
    Page page;
12  
    
13  
    void assertPageContainsText(S text) {
14  
      assertNotNull(scorer, text, page.querySelector("text=" + text));
15  
    }
16  
    
17  
    void openSite {
18  
      init();
19  
      page = playwrightOpenPage(playwright.browser, page, site);
20  
    }
21  
    
22  
    void fill(O... _) {
23  
      for (O key, O val : paramsToObjectMap(_))
24  
        page.fill("[name=" + key + "]", str(val));
25  
    }
26  
  }
27  
  
28  
  class TestRegistration extends Tester {
29  
    S user = "testuser" + random(1000000);
30  
    S pw = "pw" + random(1000000);
31  
    S contact = "dummy contact";
32  
    
33  
    run {
34  
      openSite();
35  
      page.click("text=Register as new user");
36  
      fill(+user, f_pw := pw, pw2 := pw, +contact);
37  
      page.click([[[type=submit]:has-text("Register")]]);
38  
      assertPageContainsText(dollarFormat("User $user created", +user));
39  
    }
40  
  }
41  
  
42  
  class LogIn extends Tester {
43  
    S user;
44  
    S pw;
45  
    double delay = 3.0;
46  
    
47  
    run {
48  
      openSite();
49  
      page.fill("[name=user]", user);
50  
      page.fill("[name=pw]", pw);
51  
      
52  
      page.click([[[type=submit]:has-text("Log in")]]);
53  
      sleepSeconds(delay);
54  
      //page.waitForLoadState(); 
55  
      /*page.waitForNavigation(() -> {
56  
        page.click([[[type=submit]:has-text("Log in")]]);
57  
      });*/
58  
      
59  
      assertPageContainsText("[user " + user + "]");
60  
      assertPageContainsText("BEA Objects");
61  
    }
62  
  }
63  
  
64  
  LogIn registerAndLogIn() {
65  
    new TestRegistration reg;
66  
    reg.run();
67  
    new LogIn logIn;
68  
    copyFields(reg, logIn, "user", "pw", "page");
69  
    logIn.run();
70  
    ret logIn;
71  
  }
72  
  
73  
  public void close { dispose playwright; }
74  
  
75  
  toString { ret "Tested " + site + ": " + scorer; }
76  
}

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: 200 / 391
Version history: 25 change(s)
Referenced in: [show references]