mvn -version
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-12T00:58:10+04:00) Maven home: C:\Program Files\maven Java version: 1.8.0_20, vendor: Oracle Corporation Java home: C:\Program Files\Java\jdk1.8.0_20\jre Default locale: ru_RU, platform encoding: Cp1251 OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
git clone git://github.com/barancev/webdriver-java-quickstart-archetype.git
cd webdriver-java-quickstart-archetype mvn install
mvn archetype:generate -DarchetypeGroupId=ru.stqa.selenium -DarchetypeArtifactId=webdriver-java-quickstart-archetype -DarchetypeVersion=0.7 -DgroupId=ru.mail.pechkin -DartifactId=PechkinFuncTest
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.42.2</version> </dependency>
site.url=http://pechkin-mail.ru/ browser.name=firefox
private WebElement emailField; private WebElement usernameField; private WebElement passwordField; private WebElement inviteField;
private WebElement dogovorCheckbox; private WebElement persCheckbox;
private WebElement submitButton;
@FindBy(id = "email") private WebElement emailField; @FindBy(id = "username") private WebElement usernameField; @FindBy(id = "password") private WebElement passwordField; @FindBy(id = "invite") private WebElement inviteField; @FindBy(id = "dogovor") private WebElement dogovorCheckbox; @FindBy(id = "pers") private WebElement persCheckbox; @FindBy(id = "reg_submit") private WebElement submitButton;
public RegistrationPage setEmail(String email){ emailField.sendKeys(email); return this; } public RegistrationPage setUsername(String username){ usernameField.sendKeys(username); return this; } public RegistrationPage setPassword(String password){ passwordField.sendKeys(password); return this; } public RegistrationPage setInvite(String invite){ inviteField.sendKeys(invite); return this; } public RegistrationPage setDogovor() { if(!dogovorCheckbox.isSelected()) { dogovorCheckbox.click(); } return this; } public RegistrationPage setPersonal() { if(!persCheckbox.isSelected()) { persCheckbox.click(); } return this; } public void clickSubmitButton() { submitButton.click(); }
@FindBy(id = "error_block") private WebElement errorText; public boolean isError() { if(errorText.isDisplayed()) { return true; } else { return false; } }
package ru.mail.pechkin.pages; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; public class RegistrationPage extends AnyPage{ @FindBy(id = "reg_submit") private WebElement submitButton; @FindBy(id = "email") private WebElement emailField; @FindBy(id = "username") private WebElement usernameField; @FindBy(id = "password") private WebElement passwordField; @FindBy(id = "invite") private WebElement inviteField; @FindBy(id = "dogovor") private WebElement dogovorCheckbox; @FindBy(id = "pers") private WebElement persCheckbox; @FindBy(id = "error_block") private WebElement errorText; public RegistrationPage(PageManager pages) { super(pages); } public RegistrationPage setEmail(String email){ emailField.sendKeys(email); return this; } public RegistrationPage setUsername(String username){ usernameField.sendKeys(username); return this; } public RegistrationPage setPassword(String password){ passwordField.sendKeys(password); return this; } public RegistrationPage setInvite(String invite){ inviteField.sendKeys(invite); return this; } public RegistrationPage setDogovor() { if(!dogovorCheckbox.isSelected()) { dogovorCheckbox.click(); } return this; } public RegistrationPage setPersonal() { if(!persCheckbox.isSelected()) { persCheckbox.click(); } return this; } public void clickSubmitButton() { submitButton.click(); } public boolean isError() { if(errorText.isDisplayed()) { return true; } else { return false; } } }
public void setEmailWithValidAllFields(String email) { pages.registrationPage.setEmail(email).setUsername(username).setPassword(password); pages.registrationPage.setDogovor().setPersonal(); }
public void clickRegistration() { pages.registrationPage.clickSubmitButton(); }
public boolean isError() { return pages.registrationPage.isError(); }
package ru.mail.pechkin.logic; public class RegistrationHelper extends DriverBasedHelper implements IRegistrationHelper { private final String username = "username"; private final String password = "passw"; private ApplicationManager manager; public RegistrationHelper(ApplicationManager applicationManager) { super(applicationManager.getWebDriver()); this.manager = applicationManager; } @Override public String getTitle() { return driver.getTitle(); } public void setEmailWithValidAllFields(String email) { pages.registrationPage.setEmail(email).setUsername(username).setPassword(password); pages.registrationPage.setDogovor().setPersonal(); } public void clickRegistration() { pages.registrationPage.clickSubmitButton(); } public boolean isError() { return pages.registrationPage.isError(); } }
@Test public void validEmailWithLowerAndUpperLetters() { app.getNavigationHelper().openRegistrationPage(); app.getRegistrationHelper().setEmailWithValidAllFields("testEmail@mailinator.com"); app.getRegistrationHelper().clickRegistration(); Assert.assertTrue(!app.getRegistrationHelper().isError()); } @Test public void validEmailWithNumberInLocalPart() { app.getNavigationHelper().openRegistrationPage(); app.getRegistrationHelper().setEmailWithValidAllFields("1testEmail1@mailinator.com"); app.getRegistrationHelper().clickRegistration(); Assert.assertTrue(!app.getRegistrationHelper().isError()); }
@Test public void notValidEmailEmptyField() { app.getNavigationHelper().openRegistrationPage(); app.getRegistrationHelper().setEmailWithValidAllFields(""); app.getRegistrationHelper().clickRegistration(); Assert.assertTrue(app.getRegistrationHelper().isError()); } @Test public void notValidEmailWithLackOfLocalPart(){ app.getNavigationHelper().openRegistrationPage(); app.getRegistrationHelper().setEmailWithValidAllFields("@mailinator.com"); app.getRegistrationHelper().clickRegistration(); Assert.assertTrue(app.getRegistrationHelper().isError()); }
Source: https://habr.com/ru/post/236561/
All Articles