I try to get value (email adress) from page https://temp-mail.org/ , and put it to the string.
So my code is this:
maven dependencies:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
<scope>test</scope>
</dependency>
</dependencies>
I create Abstract page
public abstract class AbstractPage {
protected WebDriver driver;
protected AbstractPage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
protected abstract AbstractPage openPage(String url);
}
TempMailPage:
public class TempMailOrgPage extends AbstractPage {
String regex = "^[A-Za-z0-9+_.-]+@(.+)$";
Pattern pattern = Pattern.compile(regex);
public TempMailOrgPage(WebDriver driver) {
super(driver);
}
public TempMailOrgPage openPage(String url) {
driver.get(url);
driver.manage().window().maximize();
return this;
}
@FindBy(xpath = "//input[@id='mail']")
WebElement mailField;
public TempMailOrgPage getAddress() {
//new WebDriverWait(driver, 10).until(ExpectedConditions.textToBePresentInElement(mailField, regex));
new WebDriverWait(driver, 10).until(ExpectedConditions.textMatches((By) mailField, pattern));
System.out.println(mailField.getAttribute("value"));
return this;
}
}
and Test
public class MainTest {
WebDriver driver;
@BeforeMethod(alwaysRun = true)
public void browserRun() {
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
}
@Test(description = "try get addresb")
public void scenarioWithCopyingEmail() {
new TempMailOrgPage(this.driver)
.openPage("https://temp-mail.org/")
.getAddress();
}
@AfterMethod(alwaysRun = true)
public void afterTestCompleted() {
driver.quit();
driver = null;
}
}
And after test running I get error. I understand that a mistake in waiting then email address is generating.
And instead of a word "Loading" will be mail address. In this line I try to use pattern:
new WebDriverWait(driver, 10).until(ExpectedConditions.textMatches((By) mailField, pattern));
What am I doing wrong with waiting?
P.s. using thread.sleep not a way.
openPage()in classTempMailOrgPagedoesn't do anything? Shouldn't it open the URL withdriver.get()?openPage()method which only returns reference to the current object... Where is the line of code that actually opens temp-mail.org?