Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added source, libs and README #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
281 changes: 128 additions & 153 deletions README.md

Large diffs are not rendered by default.

Binary file added libs/byte-buddy-1.8.15.jar
Binary file not shown.
Binary file added libs/client-combined-3.141.59.jar
Binary file not shown.
Binary file added libs/commons-exec-1.3.jar
Binary file not shown.
Binary file added libs/guava-25.0-jre.jar
Binary file not shown.
Binary file added libs/okhttp-3.11.0.jar
Binary file not shown.
Binary file added libs/okio-1.14.0.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions shootproof/selenium/locators/HomePageLocators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package shootproof.selenium.locators;

public class HomePageLocators {
public static final String TOP_MOST_GET_STARTED_BTN = "//p[@id='navbar-button-trigger']/a";
public static final String BOTTOM_MOST_GET_YOUR_FREE_GALLERY_BTN = "//div[@id='try-free']/div[@class='container']/p[2]/a";
}
26 changes: 26 additions & 0 deletions shootproof/selenium/pages/BasePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package shootproof.selenium.pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

import shootproof.selenium.utils.Constants;

public class BasePage {
private WebDriver webDriver;

public BasePage (WebDriver webDriver) {
this.webDriver = webDriver;
}

protected WebDriver getWebDriver () {
return this.webDriver;
}

protected WebElement waitOnCondition(ExpectedCondition<WebElement> condition){
WebDriverWait wait = new WebDriverWait(this.getWebDriver(), Constants.FIVE_SECS);
WebElement element = wait.until(condition);
return element;
}
}
59 changes: 59 additions & 0 deletions shootproof/selenium/pages/HomePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package shootproof.selenium.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;

import shootproof.selenium.locators.HomePageLocators;

public class HomePage extends BasePage{
public HomePage(WebDriver targetWebDriver) {
super(targetWebDriver);
}

public void lauch() {
this.getWebDriver().get("https://shootproof.com/");
}

public void scrollToPageBottom() {
((JavascriptExecutor) this.getWebDriver()).executeScript("window.scrollTo(0, document.body.scrollHeight)");
}

public void waitForTopMostGetStartedBtnToDisplay() {
this.waitOnCondition(ExpectedConditions.visibilityOfElementLocated(By.xpath(HomePageLocators.TOP_MOST_GET_STARTED_BTN)));
}

public boolean isBottomMostGetYourFreeGalleryBtnDisplayed() {
WebElement bottomMostGetStartedBtn = this.getWebDriver().findElement(By.xpath(HomePageLocators.BOTTOM_MOST_GET_YOUR_FREE_GALLERY_BTN));
return bottomMostGetStartedBtn.isDisplayed();
}

public boolean isBottomMostGetYourFreeGalleryBtnClickable() {
try {
this.waitOnCondition(ExpectedConditions.elementToBeClickable(By.xpath(HomePageLocators.BOTTOM_MOST_GET_YOUR_FREE_GALLERY_BTN)));
return true;
} catch (TimeoutException e) {
return false;
}
}

public void scrollBottomMostGetYourFreeGalleryBtnIntoView(){
WebElement bottomMostGetStartedBtn = this.getWebDriver().findElement(By.xpath(HomePageLocators.BOTTOM_MOST_GET_YOUR_FREE_GALLERY_BTN));
JavascriptExecutor jse2 = (JavascriptExecutor)this.getWebDriver();
jse2.executeScript("arguments[0].scrollIntoView()", bottomMostGetStartedBtn);
}

public void clickTopMostGetStartedBtn() {
WebElement topMostGetStartedBtn = this.getWebDriver().findElement(By.xpath(HomePageLocators.TOP_MOST_GET_STARTED_BTN));
topMostGetStartedBtn.click();
}

public void clickBottomMostGetYourFreeGalleryBtn() {
WebElement bottomMostGetStartedBtn = this.getWebDriver().findElement(By.xpath(HomePageLocators.BOTTOM_MOST_GET_YOUR_FREE_GALLERY_BTN));
bottomMostGetStartedBtn.click();
}

}
39 changes: 39 additions & 0 deletions shootproof/selenium/tests/BaseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package shootproof.selenium.tests;

import java.net.URL;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;

public class BaseTest{
private WebDriver targetWebDriver;

@BeforeSuite (alwaysRun = true)
@Parameters({"browser","version"})
protected void setupSuite(String browserName, String browserVersion) throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(browserName);
capabilities.setVersion(browserVersion);

try{
targetWebDriver = new RemoteWebDriver(
new URL("http://localhost:4444/wd/hub"),
capabilities);
}catch(Exception e) {
throw new Exception("Exception is thrown during test setup: " + e.getMessage());
}
}

protected WebDriver getTargetWebDriver() {
return targetWebDriver;
}

@AfterSuite (alwaysRun = true)
protected void teardownSuite (){
targetWebDriver.close();
}
}
36 changes: 36 additions & 0 deletions shootproof/selenium/tests/TestGetStartedButtonsOnHomePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package shootproof.selenium.tests;

import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import shootproof.selenium.pages.HomePage;
import shootproof.selenium.utils.Constants;

public class TestGetStartedButtonsOnHomePage extends BaseTest{
private HomePage homepage;

@BeforeMethod
public void launchHomepage() {
homepage = new HomePage(this.getTargetWebDriver());
homepage.lauch();
}

@Test
public void testClickTopMostGetStartedButton() {
homepage.waitForTopMostGetStartedBtnToDisplay();
homepage.clickTopMostGetStartedBtn();
}

@Test
public void testClickBottomMostGetYourFreeGalleryButton() throws InterruptedException {
homepage.scrollToPageBottom();
Assert.assertTrue(homepage.isBottomMostGetYourFreeGalleryBtnDisplayed(), "Get Started button is Not showing up at the bottom of the page");
int num_retry = 0;
while (num_retry < Constants.MAX_RETRIES && !homepage.isBottomMostGetYourFreeGalleryBtnClickable()) {
homepage.scrollBottomMostGetYourFreeGalleryBtnIntoView();
}
homepage.clickBottomMostGetYourFreeGalleryBtn();
}

}
10 changes: 10 additions & 0 deletions shootproof/selenium/utils/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package shootproof.selenium.utils;

public class Constants {
public static int THREE_SECS = 3;
public static int FIVE_SECS = 5;
public static int TEN_SECS = 10;

public static int MAX_RETRIES = 3;

}
17 changes: 17 additions & 0 deletions testng.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="ShootProofChromeTestSuite" verbose="10">

<parameter name="browser" value="chrome"/>
<parameter name="version" value="73.0"/>

<test name="ChromeTest" preserve-order="true">
<classes>
<class name="shootproof.selenium.tests.TestGetStartedButtonsOnHomePage">
<methods>
<include name="testClickTopMostGetStartedButton" />
<include name="testClickBottomMostGetYourFreeGalleryButton" />
</methods>
</class>
</classes>
</test>
</suite>