MCPcopy Create free account
hub / github.com/TestLeafInc/Simba / TempMailer

Class TempMailer

src/main/java/com/force/utility/TempMailer.java:14–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12import com.microsoft.playwright.Playwright;
13
14public class TempMailer extends ProjectHooks{
15
16 public static String getEmailAddress() {
17 String innerText = "";
18 try {
19 Playwright pw = Playwright.create();
20 Browser browser = pw.chromium().launch(new BrowserType.LaunchOptions().setChannel("chrome").setHeadless(true));
21 BrowserContext newContext = browser.newContext();
22 Page page = newContext.newPage();
23 page.navigate("https://www.sharklasers.com/", new Page.NavigateOptions().setTimeout(0));
24 innerText = page.locator("#inbox-id").innerText()+"@sharklasers.com";
25 System.out.println(innerText);
26 if(!innerText.trim().equals("")) {
27 email.set(innerText);
28 newEmails.put(innerText, "Created");
29 }
30 newContext.storageState(new BrowserContext.StorageStateOptions().setPath(Paths.get("storage/"+innerText+".json")));
31 pw.close();
32 }catch(Exception e) {}
33 return innerText;
34 }
35
36 public static String getRegistrationLink(String email) {
37 boolean bEmailReceived = false;
38 int maxEmailWaitTime = 0;
39 String attribute = "";
40 try {
41 Playwright pw = Playwright.create();
42 Browser browser = pw.chromium().launch(new BrowserType.LaunchOptions().setChannel("chrome").setHeadless(true));
43 BrowserContext context = browser.newContext(new Browser.NewContextOptions().setStorageStatePath(Paths.get("storage/"+email+".json")));
44 Page page = context.newPage();
45
46 while(!bEmailReceived && maxEmailWaitTime < ConfigurationManager.configuration().maxEmailTimeout()) {
47 page.navigate("https://www.sharklasers.com/", new Page.NavigateOptions().setTimeout(0));
48 Locator locator = page.locator("(//tr[contains(@class,'mail_row email_unread')]/td[@class='td2'])[1]");
49 if(locator.count() == 1) {
50 locator.click();
51 try {
52 page.setDefaultTimeout(2000);
53 attribute = page.locator("//a[contains(text(),'Verify Account')]").getAttribute("href");
54 newEmails.put(email, "EmailConfirmed");
55 bEmailReceived = true;
56 break;
57 }catch(Exception e) {
58 //e.printStackTrace();
59 }
60 } else {
61 System.out.println("No emails yet !!");
62 }
63 page.setDefaultTimeout(ConfigurationManager.configuration().timeout());
64
65 if(!bEmailReceived) {
66 page.goBack();
67 try {Thread.sleep(10000);} catch(Exception e) {}
68 maxEmailWaitTime = maxEmailWaitTime + 12000;
69 }
70 }
71 pw.close();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected