diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c37f338 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar +.idea diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2b5dc25 --- /dev/null +++ b/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + org.example + rv-zalenium + 1.0-SNAPSHOT + + + 7.1.0 + 3.141.59 + 7.3.0 + + + + + org.testng + testng + ${testng.version} + test + + + org.seleniumhq.selenium + selenium-java + ${selenium.version} + + + io.appium + java-client + ${java.client.version} + + + + diff --git a/rv-zalenium.iml b/rv-zalenium.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/rv-zalenium.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/src/main/java/pages/GooglePage.java b/src/main/java/pages/GooglePage.java new file mode 100644 index 0000000..d0e8747 --- /dev/null +++ b/src/main/java/pages/GooglePage.java @@ -0,0 +1,44 @@ +package pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +/** + * @author Razvan Vancea + */ +public class GooglePage { + + private WebDriver driver; + private WebDriverWait wait; + + @FindBy(name = "q") + private WebElement searchTextField; + + @FindBy(name = "btnK") + private WebElement searchBtn; + + public GooglePage(WebDriver driver){ + this.driver = driver; + wait = new WebDriverWait(driver, 15); + PageFactory.initElements(driver, this); + } + + public void goTo(String url){ + driver.get(url); + wait.until(ExpectedConditions.visibilityOf(searchBtn)); + } + + public void searchFor(String text){ + wait.until(ExpectedConditions.elementToBeClickable(searchTextField)); + searchTextField.click(); + searchTextField.sendKeys(text); + } + + public void clickSearchBtn(){ + searchBtn.click(); + } +} diff --git a/src/main/java/pages/GoogleResultsPage.java b/src/main/java/pages/GoogleResultsPage.java new file mode 100644 index 0000000..5359a90 --- /dev/null +++ b/src/main/java/pages/GoogleResultsPage.java @@ -0,0 +1,30 @@ +package pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +/** + * @author Razvan Vancea + */ +public class GoogleResultsPage { + private WebDriver driver; + private WebDriverWait wait; + + @FindBy(xpath = "//h3[@text()='Zalenium - A flexible and scalable Selenium Grid.']") + private WebElement zaleniumTextResult; + + public GoogleResultsPage(WebDriver driver){ + this.driver = driver; + wait = new WebDriverWait(driver, 30); + PageFactory.initElements(driver, this); + } + + public void clickZaleniumResult(){ + wait.until(ExpectedConditions.visibilityOf(zaleniumTextResult)); + zaleniumTextResult.click(); + } +} diff --git a/src/main/java/pages/ZaleniumPage.java b/src/main/java/pages/ZaleniumPage.java new file mode 100644 index 0000000..6b1b8e6 --- /dev/null +++ b/src/main/java/pages/ZaleniumPage.java @@ -0,0 +1,39 @@ +package pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +/** + * @author Razvan Vancea + */ +public class ZaleniumPage { + + private WebDriver driver; + private WebDriverWait wait; + + @FindBy(xpath = "//a[@text()='Docker']") + private WebElement dockerLink; + + @FindBy(xpath = "//h3[@text()='Starting Zalenium']") + private WebElement startingZaleniumText; + + public ZaleniumPage(WebDriver driver){ + this.driver = driver; + wait = new WebDriverWait(driver, 30); + PageFactory.initElements(driver, this); + } + + public void clickDockerLink(){ + wait.until(ExpectedConditions.visibilityOf(dockerLink)); + dockerLink.click(); + } + + public WebElement getStartingZaleniumText(){ + wait.until(ExpectedConditions.visibilityOf(startingZaleniumText)); + return startingZaleniumText; + } +} diff --git a/src/test/java/BaseTest.java b/src/test/java/BaseTest.java new file mode 100644 index 0000000..3c3d1f6 --- /dev/null +++ b/src/test/java/BaseTest.java @@ -0,0 +1,34 @@ +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxOptions; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; + +import java.net.MalformedURLException; +import java.net.URL; + +/** + * @author Razvan Vancea + */ +public class BaseTest { + protected WebDriver driver; + + @BeforeTest + public void setupDriver(){ + DesiredCapabilities capabilities; + capabilities = DesiredCapabilities.chrome(); + String host = "http://localhost:4444/wd/hub"; + try { + this.driver = new RemoteWebDriver(new URL(host), capabilities); + } catch (MalformedURLException e){ + e.printStackTrace(); + } + } + + @AfterTest + public void tearDown(){ + this.driver.quit(); + } +} diff --git a/src/test/java/ZaleniumTest.java b/src/test/java/ZaleniumTest.java new file mode 100644 index 0000000..5faf051 --- /dev/null +++ b/src/test/java/ZaleniumTest.java @@ -0,0 +1,26 @@ +import org.testng.Assert; +import org.testng.annotations.Test; +import pages.GooglePage; +import pages.GoogleResultsPage; +import pages.ZaleniumPage; + +/** + * @author Razvan Vancea + */ +public class ZaleniumTest extends BaseTest { + + + @Test + public void assertDocumentation(){ + GooglePage googlePage = new GooglePage(driver); + GoogleResultsPage googleResultsPage = new GoogleResultsPage(driver); + ZaleniumPage zaleniumPage = new ZaleniumPage(driver); + + googlePage.goTo("https://www.google.ro"); + googlePage.searchFor("Zalenium docs"); + googlePage.clickSearchBtn(); + googleResultsPage.clickZaleniumResult(); + zaleniumPage.clickDockerLink(); + Assert.assertTrue(zaleniumPage.getStartingZaleniumText().isDisplayed()); + } +}