├── .gitignore ├── README.md ├── drivers └── chromedriver ├── pom.xml └── src ├── main └── java │ └── dev │ └── camila │ └── automation │ └── pratice │ └── selenium │ └── App.java └── test └── java └── dev └── camila └── automation └── pratice └── selenium ├── AppTest.java ├── LoginTest.java ├── pages ├── BasePage.java ├── DressesPage.java ├── LoginPage.java └── RegisterPage.java └── tests ├── DressesPageTest.java ├── LoginPageTest.java └── RegisterPageTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/java,maven,eclipse,intellij+all,visualstudiocode 3 | # Edit at https://www.gitignore.io/?templates=java,maven,eclipse,intellij+all,visualstudiocode 4 | 5 | .metadata 6 | bin/ 7 | tmp/ 8 | *.tmp 9 | *.bak 10 | *.swp 11 | *~.nib 12 | local.properties 13 | .settings/ 14 | .loadpath 15 | .recommenders 16 | 17 | # External tool builders 18 | .externalToolBuilders/ 19 | 20 | # Locally stored "Eclipse launch configurations" 21 | *.launch 22 | 23 | # PyDev specific (Python IDE for Eclipse) 24 | *.pydevproject 25 | 26 | # CDT-specific (C/C++ Development Tooling) 27 | .cproject 28 | 29 | # CDT- autotools 30 | .autotools 31 | 32 | # Java annotation processor (APT) 33 | .factorypath 34 | 35 | # PDT-specific (PHP Development Tools) 36 | .buildpath 37 | 38 | # sbteclipse plugin 39 | .target 40 | 41 | # Tern plugin 42 | .tern-project 43 | 44 | # TeXlipse plugin 45 | .texlipse 46 | 47 | # STS (Spring Tool Suite) 48 | .springBeans 49 | 50 | # Code Recommenders 51 | .recommenders/ 52 | 53 | # Annotation Processing 54 | .apt_generated/ 55 | 56 | # Scala IDE specific (Scala & Java development for Eclipse) 57 | .cache-main 58 | .scala_dependencies 59 | .worksheet 60 | 61 | # Eclipse Core 62 | .project 63 | 64 | # JDT-specific (Eclipse Java Development Tools) 65 | .classpath 66 | 67 | # Annotation Processing 68 | .apt_generated 69 | 70 | .sts4-cache/ 71 | 72 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 73 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 74 | 75 | # User-specific stuff 76 | .idea/**/workspace.xml 77 | .idea/**/tasks.xml 78 | .idea/**/usage.statistics.xml 79 | .idea/**/dictionaries 80 | .idea/**/shelf 81 | 82 | # Generated files 83 | .idea/**/contentModel.xml 84 | 85 | # Sensitive or high-churn files 86 | .idea/**/dataSources/ 87 | .idea/**/dataSources.ids 88 | .idea/**/dataSources.local.xml 89 | .idea/**/sqlDataSources.xml 90 | .idea/**/dynamic.xml 91 | .idea/**/uiDesigner.xml 92 | .idea/**/dbnavigator.xml 93 | 94 | # Gradle 95 | .idea/**/gradle.xml 96 | .idea/**/libraries 97 | 98 | # Gradle and Maven with auto-import 99 | # When using Gradle or Maven with auto-import, you should exclude module files, 100 | # since they will be recreated, and may cause churn. Uncomment if using 101 | # auto-import. 102 | # .idea/modules.xml 103 | # .idea/*.iml 104 | # .idea/modules 105 | # *.iml 106 | # *.ipr 107 | 108 | # CMake 109 | cmake-build-*/ 110 | 111 | # Mongo Explorer plugin 112 | .idea/**/mongoSettings.xml 113 | 114 | # File-based project format 115 | *.iws 116 | 117 | # IntelliJ 118 | out/ 119 | 120 | # mpeltonen/sbt-idea plugin 121 | .idea_modules/ 122 | 123 | # JIRA plugin 124 | atlassian-ide-plugin.xml 125 | 126 | # Cursive Clojure plugin 127 | .idea/replstate.xml 128 | 129 | # Crashlytics plugin (for Android Studio and IntelliJ) 130 | com_crashlytics_export_strings.xml 131 | crashlytics.properties 132 | crashlytics-build.properties 133 | fabric.properties 134 | 135 | # Editor-based Rest Client 136 | .idea/httpRequests 137 | 138 | # Android studio 3.1+ serialized cache file 139 | .idea/caches/build_file_checksums.ser 140 | 141 | # Ignores the whole .idea folder and all .iml files 142 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 143 | 144 | .idea/ 145 | 146 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 147 | 148 | *.iml 149 | modules.xml 150 | .idea/misc.xml 151 | *.ipr 152 | 153 | # Sonarlint plugin 154 | .idea/sonarlint 155 | 156 | # Compiled class file 157 | *.class 158 | 159 | # Log file 160 | *.log 161 | 162 | # BlueJ files 163 | *.ctxt 164 | 165 | # Mobile Tools for Java (J2ME) 166 | .mtj.tmp/ 167 | 168 | # Package Files # 169 | *.jar 170 | *.war 171 | *.nar 172 | *.ear 173 | *.zip 174 | *.tar.gz 175 | *.rar 176 | 177 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 178 | hs_err_pid* 179 | 180 | target/ 181 | pom.xml.tag 182 | pom.xml.releaseBackup 183 | pom.xml.versionsBackup 184 | pom.xml.next 185 | release.properties 186 | dependency-reduced-pom.xml 187 | buildNumber.properties 188 | .mvn/timing.properties 189 | .mvn/wrapper/maven-wrapper.jar 190 | .flattened-pom.xml 191 | 192 | .vscode/* 193 | !.vscode/settings.json 194 | !.vscode/tasks.json 195 | !.vscode/launch.json 196 | !.vscode/extensions.json 197 | 198 | # Ignore all local history of files 199 | .history 200 | 201 | # End of https://www.gitignore.io/api/java,maven,eclipse,intellij+all,visualstudiocode -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Automação de Testes com Selenium WebDriver e Java

2 | 3 |

Conheça o Selenium WebDriver, a principal ferramenta de automação de páginas Web. Nesse contexto, explore a linguagem de programação Java e entenda como o Selenium automatiza as ações diretamente em seu browser.

4 | 5 |

❗❗ O SITE http://automationpractice.com/ INFELIZMENTE ESTÁ FORA DO AR, POR FAVOR, USAR QUALQUER OUTRO SITE PARA EXECUTAR OS COMANDOS DO SELENIUM WEBDRIVE. SUGIRO: https://automationexercise.com/❗❗

6 | 7 |

Features

8 |
    9 |
  1. Configuração de Testes Selenium WebDriver + Java
  2. 10 |
  3. WebDriver
  4. 11 |
  5. Actions
  6. 12 |
  7. WebDriverWait
  8. 13 |
  9. Select
  10. 14 |
15 | 16 |

Demostração da Aplicação

17 |

Antes de começar, você precisará ter instalado em sua máquina as seguintes ferramentas:

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
FerramentaVersão
Java JDK8+
Git2.**
Maven3.**
36 |
** Visando facilitar a demostração da aplicação, recomendo instalar apenas o Eclipse IDE e rodar o projeto através da IDE **
37 | 38 | No Terminal/Console: 39 |
    40 |
  1. Faça um clone do projeto na sua máquina: git clone https://github.com/cami-la testes_selenium_webdriver_java_curso.git
  2. 41 |
  3. Entre na pasta raiz do projeto
  4. 42 |
  5. Execute o comando: mvn test
  6. 43 |
44 | 45 |

Materiais Complementares

46 | 54 | 55 |

Autor

56 | 57 | 58 | 59 |
60 | Camila Cavalcante
61 | 62 | Feito com ❤️ por Cami-la 👋🏽 Entre em contato! 63 | 64 | [![Linkedin Badge](https://img.shields.io/badge/-Camila-blue?style=flat-square&logo=Linkedin&logoColor=white&link=https://www.linkedin.com/in/cami-la/)](https://www.linkedin.com/in/cami-la/) 65 | [![Gmail Badge](https://img.shields.io/badge/-camiladsantoscavalcante@gmail.com-c14438?style=flat-square&logo=Gmail&logoColor=white&link=mailto:camiladsantoscavalcante@gmail.com)](mailto:camiladsantoscavalcante@gmail.com) 66 |
67 |

Contribuindo

68 | 69 | Este repositório foi criado para fins de estudo, então contribua com ele.
70 | Se te ajudei de alguma forma, ficarei feliz em saber. E caso você conheça alguém que se identifique com o conteúdo, não deixe de compatilhar. 71 | 72 | Se possível: 73 | 74 | ⭐️ Star o projeto 75 | 76 | 🐛 Encontrar e relatar issues 77 | -------------------------------------------------------------------------------- /drivers/chromedriver: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cami-la/testes_selenium_webdriver_java_curso/74bb633663006b7a4c5912d02053239f3e5477ba/drivers/chromedriver -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | dev.camila 8 | automation-pratice-selenium 9 | 0.0.1-SNAPSHOT 10 | jar 11 | 12 | automation-pratice-selenium 13 | http://www.example.com 14 | 15 | 16 | UTF-8 17 | 11 18 | ${java.version} 19 | ${java.version} 20 | ${java.version} 21 | 22 | 5.6.2 23 | 24 | 25 | 3.2.2 26 | 3.1.0 27 | 3.1.0 28 | 3.8.1 29 | 3.0.0-M5 30 | 3.2.0 31 | 3.0.0-M1 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | org.seleniumhq.selenium 41 | selenium-chrome-driver 42 | 4.5.0 43 | 44 | 45 | org.seleniumhq.selenium 46 | selenium-support 47 | 4.5.0 48 | 49 | 50 | org.junit.jupiter 51 | junit-jupiter-api 52 | ${junit} 53 | test 54 | 55 | 56 | org.junit.jupiter 57 | junit-jupiter-engine 58 | ${junit} 59 | test 60 | 61 | 62 | org.junit.jupiter 63 | junit-jupiter-params 64 | ${junit} 65 | test 66 | 67 | 68 | 69 | 70 | 71 | 72 | maven-clean-plugin 73 | 3.1.0 74 | 75 | 76 | maven-resources-plugin 77 | 3.1.0 78 | 79 | 80 | maven-compiler-plugin 81 | 3.8.1 82 | 83 | 84 | maven-surefire-plugin 85 | 3.0.0-M4 86 | 87 | 88 | maven-jar-plugin 89 | 3.2.0 90 | 91 | 92 | maven-install-plugin 93 | 3.0.0-M1 94 | 95 | 96 | org.apache.maven.plugins 97 | maven-shade-plugin 98 | ${maven.shade} 99 | 100 | 101 | package 102 | 103 | shade 104 | 105 | 106 | 107 | 109 | dev.camila.automation.pratice.selenium.App 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /src/main/java/dev/camila/automation/pratice/selenium/App.java: -------------------------------------------------------------------------------- 1 | package dev.camila.automation.pratice.selenium; 2 | 3 | public class App { 4 | 5 | public static void main(String[] args) { 6 | } 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/test/java/dev/camila/automation/pratice/selenium/AppTest.java: -------------------------------------------------------------------------------- 1 | package dev.camila.automation.pratice.selenium; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertTrue; 4 | 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | import org.openqa.selenium.WebDriver; 8 | import org.openqa.selenium.chrome.ChromeDriver; 9 | 10 | public class AppTest { 11 | private WebDriver driver; 12 | 13 | @Test 14 | public void helloSelenium() { 15 | //https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/ 16 | System.setProperty("webdriver.chrome.driver","drivers/chromedriver"); 17 | driver = new ChromeDriver(); 18 | driver.manage().window().maximize(); 19 | driver.get("http://automationpractice.com/index.php"); 20 | 21 | String currentUrl = driver.getCurrentUrl(); 22 | String expected = "http://automationpractice.com/index.php"; 23 | 24 | Assertions.assertEquals(expected, currentUrl); 25 | 26 | driver.quit(); 27 | } 28 | 29 | 30 | @Test 31 | public void shouldAnswerWithTrue() { 32 | assertTrue(true); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/dev/camila/automation/pratice/selenium/LoginTest.java: -------------------------------------------------------------------------------- 1 | package dev.camila.automation.pratice.selenium; 2 | 3 | import org.junit.jupiter.api.AfterEach; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | import org.openqa.selenium.By; 8 | import org.openqa.selenium.WebDriver; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.chrome.ChromeDriver; 11 | 12 | class LoginTest { 13 | private WebDriver driver; 14 | 15 | @BeforeEach 16 | void setUp() throws Exception { 17 | System.setProperty("webdriver.chrome.driver","drivers/chromedriver"); 18 | driver = new ChromeDriver(); 19 | driver.manage().window().maximize(); 20 | driver.get("http://automationpractice.com/index.php?controller=authentication&back=my-account"); 21 | } 22 | 23 | @AfterEach 24 | void tearDown() throws Exception { 25 | driver.quit(); 26 | } 27 | 28 | @Test 29 | void test() { 30 | WebElement emailAddressElement = driver.findElement(By.id("email")); 31 | emailAddressElement.sendKeys("camilajavadev123@gmail.com"); 32 | 33 | WebElement passwordElement = driver.findElement(By.name("passwd")); 34 | passwordElement.sendKeys("123456@Ca"); 35 | 36 | WebElement submitBtnElement = driver.findElement(By.xpath("//*[@id=\"SubmitLogin\"]")); 37 | submitBtnElement.click(); 38 | 39 | WebElement tagMyAccount = driver.findElement(By.tagName("h1")); 40 | String textTagH1 = tagMyAccount.getText(); 41 | 42 | Assertions.assertTrue(textTagH1.equals("MY ACCOUNT")); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/dev/camila/automation/pratice/selenium/pages/BasePage.java: -------------------------------------------------------------------------------- 1 | package dev.camila.automation.pratice.selenium.pages; 2 | 3 | import java.time.Duration; 4 | 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.NoSuchElementException; 7 | import org.openqa.selenium.WebDriver; 8 | import org.openqa.selenium.WebElement; 9 | import org.openqa.selenium.chrome.ChromeDriver; 10 | import org.openqa.selenium.interactions.Actions; 11 | import org.openqa.selenium.support.ui.ExpectedConditions; 12 | import org.openqa.selenium.support.ui.Select; 13 | import org.openqa.selenium.support.ui.WebDriverWait; 14 | 15 | public abstract class BasePage { 16 | private WebDriver driver; 17 | private Actions action; 18 | private WebDriverWait wait; 19 | private Select select; 20 | 21 | public BasePage() { 22 | System.setProperty("webdriver.chrome.driver", "drivers/chromedriver"); 23 | driver = new ChromeDriver(); 24 | driver.manage().window().maximize(); 25 | } 26 | 27 | public void visit(String url) { 28 | this.driver.get(url); 29 | } 30 | 31 | public String getCurrentUrl() { 32 | return this.driver.getCurrentUrl(); 33 | } 34 | 35 | public void quitWebDriver() { 36 | this.driver.quit(); 37 | } 38 | 39 | public WebElement findElement(By locator) { 40 | return this.driver.findElement(locator); 41 | } 42 | 43 | public void type(String input, By locator) { 44 | this.driver.findElement(locator).sendKeys(input); 45 | } 46 | 47 | public Boolean isDisplayed(By locator) { 48 | try { 49 | return this.driver.findElement(locator).isDisplayed(); 50 | } catch (NoSuchElementException e) { 51 | return false; 52 | } 53 | } 54 | 55 | public void click(By locator) { 56 | this.driver.findElement(locator).click(); 57 | } 58 | 59 | public String getText(By locator) { 60 | return this.driver.findElement(locator).getText(); 61 | } 62 | 63 | public void actionMoveToElementPerform(By locator) { 64 | if (this.action == null) { 65 | this.action = new Actions(this.driver); 66 | } 67 | WebElement element = this.driver.findElement(locator); 68 | action.moveToElement(element).perform(); 69 | } 70 | 71 | public void actionMoveToElementClickPerform(By locator) { 72 | if (this.action == null) { 73 | this.action = new Actions(this.driver); 74 | } 75 | WebElement element = this.driver.findElement(locator); 76 | action.moveToElement(element).click().build().perform(); 77 | } 78 | 79 | public String getTextByAttribute(By locator, String attributeName) { 80 | return this.driver.findElement(locator).getAttribute(attributeName); 81 | } 82 | 83 | public WebElement waitVisibilityOfElementLocated(By locator, Duration time) { 84 | wait = new WebDriverWait(driver, time); 85 | return wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); 86 | } 87 | 88 | public WebElement waitVisibilityOfElementLocated(By locator) { 89 | wait = new WebDriverWait(driver, Duration.ofSeconds(10)); 90 | return wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); 91 | } 92 | 93 | public Boolean isContainedInPageSource(String message) { 94 | return driver.getPageSource().contains(message); 95 | } 96 | 97 | public void selectByValue(By locator, String value) { 98 | select = new Select(findElement(locator)); 99 | select.selectByValue(value); 100 | } 101 | 102 | public void clear(By locator) { 103 | this.driver.findElement(locator).clear(); 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/test/java/dev/camila/automation/pratice/selenium/pages/DressesPage.java: -------------------------------------------------------------------------------- 1 | package dev.camila.automation.pratice.selenium.pages; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | public class DressesPage extends BasePage { 6 | //Locators 7 | private By menuDressesLocator = By.cssSelector("#block_top_menu > ul > li:nth-child(2) > a"); 8 | private By submenuCasualDressesLocator = By.cssSelector("#block_top_menu > ul > li:nth-child(2) > ul > li:nth-child(1) > a"); 9 | private By titleCasualDressesPageLocator = By.className("cat-name"); 10 | 11 | public void viewCasualDressesPage() { 12 | if(super.isDisplayed(menuDressesLocator)) { 13 | super.actionMoveToElementPerform(menuDressesLocator); 14 | super.actionMoveToElementClickPerform(submenuCasualDressesLocator); 15 | } else { 16 | System.out.println("menu dresses was not found"); 17 | } 18 | } 19 | 20 | public String getTitlePage() { 21 | return super.getText(titleCasualDressesPageLocator); 22 | } 23 | 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/dev/camila/automation/pratice/selenium/pages/LoginPage.java: -------------------------------------------------------------------------------- 1 | package dev.camila.automation.pratice.selenium.pages; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | public class LoginPage extends BasePage { 6 | //Locators 7 | private By emailAddressLocator = By.id("email"); 8 | private By passwordLocator = By.name("passwd"); 9 | private By submitBtnLocator = By.xpath("//*[@id=\"SubmitLogin\"]"); 10 | private By tagMyAccountLocator = By.tagName("h1"); 11 | 12 | 13 | public void signin() { 14 | if(super.isDisplayed(emailAddressLocator)) { 15 | super.type("camilajavadev123@gmail.com", emailAddressLocator); 16 | super.type("123456@Ca", passwordLocator); 17 | super.click(submitBtnLocator); 18 | } else { 19 | System.out.println("email textbox was not present"); 20 | } 21 | } 22 | 23 | public String getMyAccountMessage() { 24 | return super.getText(tagMyAccountLocator); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/dev/camila/automation/pratice/selenium/pages/RegisterPage.java: -------------------------------------------------------------------------------- 1 | package dev.camila.automation.pratice.selenium.pages; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | public class RegisterPage extends BasePage { 6 | //Locators 7 | private By emailAddressLocator = By.id("email_create"); 8 | private By submitBtnLocator = By.id("SubmitCreate"); 9 | private By emailLocator = By.id("email"); 10 | private By alertAdditionalInformationLocator = By.xpath("/html/body/div[1]/div[2]/div/div[3]/div/div/form/div[2]/p[11]"); 11 | private By firstNameLocator = By.id("firstname"); 12 | private By lastNameLocator = By.id("lastname"); 13 | //Locators YOUR PERSONAL INFORMATION 14 | private By genderFemaleLocator = By.id("id_gender2"); 15 | private By customerFirstNameLocator = By.id("customer_firstname"); 16 | private By customerLastNameLocator = By.id("customer_lastname"); 17 | private By passwordLocator = By.id("passwd"); 18 | private By daysLocator = By.id("days"); 19 | private By monthsLocator = By.id("months"); 20 | private By yearsLocator = By.id("years"); 21 | private By newsletterLocator = By.id("newsletter"); 22 | private By receiveOffersLocator = By.id("uniform-optin"); 23 | //Locators YOUR ADDRESS 24 | private By companyLocator = By.id("company"); 25 | private By address1Locator = By.id("address1"); 26 | private By address2Locator = By.id("address2"); 27 | private By cityLocator = By.id("city"); 28 | private By stateLocator = By.id("id_state"); 29 | private By postCodeLocator = By.id("postcode"); 30 | private By countryLocator = By.id("id_country"); 31 | private By additionalInformationLocator = By.name("other"); 32 | private By homePhoneLocator = By.id("phone"); 33 | private By mobilePhoneLocator = By.id("phone_mobile"); 34 | private By futureAddressLocator = By.id("alias"); 35 | private By registerBtnLocator = By.id("submitAccount"); 36 | private By welcomeMessageLocator = By.cssSelector("#center_column > p"); 37 | 38 | 39 | public void insertEmailToRegister() { 40 | if(super.isDisplayed(emailAddressLocator)) { 41 | type("camila002@email.com", emailAddressLocator); 42 | click(submitBtnLocator); 43 | } else { 44 | System.out.println("email textbox was not present"); 45 | } 46 | } 47 | 48 | public String getEmailNewAccount() { 49 | super.waitVisibilityOfElementLocated(alertAdditionalInformationLocator); 50 | return super.getTextByAttribute(this.emailLocator, "value"); 51 | } 52 | 53 | public void fillOutForm() { 54 | this.insertEmailToRegister(); 55 | super.waitVisibilityOfElementLocated(additionalInformationLocator); 56 | if(super.isDisplayed(genderFemaleLocator)) { 57 | super.click(genderFemaleLocator); 58 | super.type("Camila", customerFirstNameLocator); 59 | super.type("Cavalcante", customerLastNameLocator); 60 | super.type("1234@", passwordLocator); 61 | super.selectByValue(daysLocator, "13"); 62 | super.selectByValue(monthsLocator, "1"); 63 | super.selectByValue(yearsLocator, "1994"); 64 | super.click(newsletterLocator); 65 | super.click(receiveOffersLocator); 66 | super.type("DIO", companyLocator); 67 | super.type("Street Name, 123", address1Locator); 68 | super.type("xxxxx", address2Locator); 69 | super.type("Recife", cityLocator); 70 | super.selectByValue(stateLocator, "32"); 71 | super.selectByValue(countryLocator, "21"); 72 | super.type("12345", postCodeLocator); 73 | super.type("Additionl Information Test", additionalInformationLocator); 74 | super.type("99999999", homePhoneLocator); 75 | super.type("99999999", mobilePhoneLocator); 76 | super.clear(futureAddressLocator); 77 | String addressLocatorFuture = getTextByAttribute(address1Locator, "value"); 78 | super.type(addressLocatorFuture, futureAddressLocator); 79 | super.click(registerBtnLocator); 80 | } else { 81 | System.out.println("message was not found."); 82 | } 83 | } 84 | 85 | public String getWelcomeMessage() { 86 | super.waitVisibilityOfElementLocated(welcomeMessageLocator); 87 | return super.getText(welcomeMessageLocator); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/test/java/dev/camila/automation/pratice/selenium/tests/DressesPageTest.java: -------------------------------------------------------------------------------- 1 | package dev.camila.automation.pratice.selenium.tests; 2 | 3 | import org.junit.jupiter.api.AfterEach; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import dev.camila.automation.pratice.selenium.pages.DressesPage; 9 | 10 | class DressesPageTest { 11 | private DressesPage dressesPage; 12 | private final String URL = "http://automationpractice.com/index.php"; 13 | 14 | @BeforeEach 15 | void setUp() throws Exception { 16 | this.dressesPage = new DressesPage(); 17 | this.dressesPage.visit(this.URL); 18 | } 19 | 20 | @AfterEach 21 | void tearDown() throws Exception { 22 | //this.dressesPage.quitWebDriver(); 23 | } 24 | 25 | @Test 26 | void test() { 27 | //when 28 | this.dressesPage.viewCasualDressesPage(); 29 | 30 | //then 31 | Assertions.assertEquals("CASUAL DRESSES ", this.dressesPage.getTitlePage()); 32 | Assertions.assertFalse(this.URL.equals(dressesPage.getCurrentUrl())); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/dev/camila/automation/pratice/selenium/tests/LoginPageTest.java: -------------------------------------------------------------------------------- 1 | package dev.camila.automation.pratice.selenium.tests; 2 | 3 | import org.junit.jupiter.api.AfterEach; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import dev.camila.automation.pratice.selenium.pages.LoginPage; 9 | 10 | class LoginPageTest { 11 | private LoginPage loginPage; 12 | private final String URL = "http://automationpractice.com/index.php?controller=authentication&back=my-account"; 13 | 14 | @BeforeEach 15 | void setUp() throws Exception { 16 | this.loginPage = new LoginPage(); 17 | this.loginPage.visit(this.URL); 18 | } 19 | 20 | @AfterEach 21 | void tearDown() throws Exception { 22 | this.loginPage.quitWebDriver(); 23 | } 24 | 25 | @Test 26 | void test() { 27 | //when 28 | this.loginPage.signin(); 29 | 30 | //then 31 | Assertions.assertTrue(this.loginPage.getMyAccountMessage().equals("MY ACCOUNT")); 32 | Assertions.assertFalse(this.loginPage.getCurrentUrl().equals(this.URL)); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/dev/camila/automation/pratice/selenium/tests/RegisterPageTest.java: -------------------------------------------------------------------------------- 1 | package dev.camila.automation.pratice.selenium.tests; 2 | 3 | import org.junit.jupiter.api.AfterEach; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import dev.camila.automation.pratice.selenium.pages.RegisterPage; 9 | 10 | class RegisterPageTest { 11 | private RegisterPage registerPage; 12 | private final String URL = "http://automationpractice.com/index.php?controller=authentication&back=my-account"; 13 | 14 | @BeforeEach 15 | void setUp() throws Exception { 16 | this.registerPage = new RegisterPage(); 17 | this.registerPage.visit(this.URL); 18 | } 19 | 20 | @AfterEach 21 | void tearDown() throws Exception { 22 | this.registerPage.quitWebDriver(); 23 | } 24 | 25 | @Test 26 | void test() { 27 | //when 28 | this.registerPage.insertEmailToRegister(); 29 | 30 | //then 31 | String expected = "camila002@email.com"; 32 | String actual = this.registerPage.getEmailNewAccount(); 33 | Assertions.assertEquals(expected, actual); 34 | } 35 | 36 | @Test 37 | void test2() { 38 | //when 39 | this.registerPage.fillOutForm(); 40 | 41 | //then 42 | String expected = "Welcome to your account. Here you can manage all of your personal information and orders."; 43 | String actual = this.registerPage.getWelcomeMessage(); 44 | Assertions.assertEquals(expected, actual); 45 | 46 | String actualUrl = this.registerPage.getCurrentUrl(); 47 | Assertions.assertFalse(this.URL.equals(actualUrl)); 48 | } 49 | 50 | } 51 | --------------------------------------------------------------------------------