-
Notifications
You must be signed in to change notification settings - Fork 0
/
Email.cs
54 lines (41 loc) · 1.59 KB
/
Email.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using OpenQA.Selenium;
// Email client code
public class EmailHandler
{
private IWebDriver _driver;
public EmailHandler(IWebDriver driver)
{
_driver = driver;
}
public string GetFakeEmailAddress()
{
// Site opening
_driver.Navigate().GoToUrl("https://fakemail.net");
// Receiving email
string emailAddress = WaitH.WaitUntilElementClickable(_driver, By.Id("email")).Text;
return emailAddress;
}
public void ConfirmEmail()
{
_driver.Navigate().GoToUrl("https://www.fakemail.net/");
// Wait until the items with e-mails are visible
var emailElements = WaitH.WaitUntilElementsVisible(_driver, By.CssSelector("#schranka .klikaciRadek"));
foreach (var emailElement in emailElements)
{
if (emailElement.Text.Contains("Account confirmation", StringComparison.OrdinalIgnoreCase))
{
// Open the letter
emailElement.Click();
// Wait for the loading of the iframe with the email content
WaitH.WaitUntilElementClickable(_driver, By.Id("iframeMail"));
// Switch to iframe
_driver.SwitchTo().Frame("iframeMail");
// Wait until the “Confirm registration” button becomes available
WaitH.WaitUntilElementClickable(_driver, By.XPath("//a[contains(text(), 'Confirm registration')]")).Click();
// Switch to a new tab
_driver.SwitchTo().Window(_driver.WindowHandles[1]);
break;
}
}
}
}