-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 63ba5a5
Showing
20 changed files
with
526 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.example</groupId> | ||
<artifactId>seleniumCore</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.sonatype.sisu</groupId> | ||
<artifactId>sisu-guice</artifactId> | ||
<version>2.1.7</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-firefox-driver</artifactId> | ||
<version>3.141.59</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>htmlunit-driver</artifactId> | ||
<version>2.33.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-java</artifactId> | ||
<version>3.141.59</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-server</artifactId> | ||
<version>3.141.59</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<version>6.9.8</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.cucumber</groupId> | ||
<artifactId>cucumber-testng</artifactId> | ||
<version>6.10.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.cucumber</groupId> | ||
<artifactId>cucumber-java</artifactId> | ||
<version>6.10.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.7.25</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>1.7.25</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.cucumber</groupId> | ||
<artifactId>cucumber-guice</artifactId> | ||
<version>6.8.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.cucumber</groupId> | ||
<artifactId>cucumber-junit</artifactId> | ||
<version>6.10.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<properties> | ||
<maven.compiler.source>15</maven.compiler.source> | ||
<maven.compiler.target>15</maven.compiler.target> | ||
</properties> | ||
|
||
<build> | ||
<sourceDirectory>src</sourceDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.0.0-M5</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven.surefire</groupId> | ||
<artifactId>surefire-junit47</artifactId> | ||
<version>3.0.0-M5</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main.java.core; | ||
|
||
import org.openqa.selenium.WebDriver; | ||
|
||
|
||
public interface BaseDriver { | ||
WebDriver driver(); | ||
|
||
void get(String url); | ||
|
||
void quit(); | ||
|
||
void close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main.java.core; | ||
|
||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
||
public abstract class BasePage { | ||
|
||
protected void wait(WebElement element, WebDriverWait webDriverWait) { | ||
|
||
} | ||
|
||
protected void scrollIntoView(WebElement webElement) { | ||
|
||
} | ||
|
||
protected void navigateBack() { | ||
|
||
} | ||
|
||
protected void getPageTitle(WebDriver.Window window) { | ||
|
||
} | ||
|
||
protected void select(WebElement webElement, String key) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main.java.core.drivers; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.name.Named; | ||
import main.java.core.BaseDriver; | ||
import main.java.exceptions.DriverNotFoundException; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.chrome.ChromeDriver; | ||
import org.openqa.selenium.firefox.FirefoxDriver; | ||
|
||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
public class BaseDriverImpl implements BaseDriver { | ||
|
||
@Inject | ||
@Named("application.driver") | ||
private String driverName; | ||
|
||
private WebDriver webDriver; | ||
|
||
@Override | ||
public WebDriver driver() { | ||
return getNewDriverInstance(); | ||
} | ||
|
||
@Override | ||
public void get(String url) { | ||
webDriver.get(url); | ||
} | ||
|
||
@Override | ||
public void quit() { | ||
|
||
if (webDriver != null) { | ||
webDriver.quit(); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
} | ||
|
||
public WebDriver getNewDriverInstance() { | ||
if (webDriver != null) return webDriver; | ||
switch (driverName) { | ||
case "firefox" -> { | ||
System.setProperty("webdriver.gecko.driver", "src/main/resources/geckodriver"); | ||
webDriver = new FirefoxDriver(); | ||
return webDriver; | ||
} | ||
case "chrome" -> { | ||
System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver"); | ||
webDriver = new ChromeDriver(); | ||
return webDriver; | ||
} | ||
default -> throw new DriverNotFoundException("No such driver found: " + driverName); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main.java.core.modules; | ||
|
||
import com.google.inject.Guice; | ||
import com.google.inject.Injector; | ||
import com.google.inject.Stage; | ||
import io.cucumber.guice.CucumberModules; | ||
import io.cucumber.guice.InjectorSource; | ||
|
||
public class CukeInjectorSource implements InjectorSource { | ||
@Override | ||
public Injector getInjector() { | ||
return Guice.createInjector(Stage.PRODUCTION, CucumberModules.createScenarioModule(), new DriverModule()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main.java.core.modules; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Scopes; | ||
import com.google.inject.name.Names; | ||
import main.java.core.BaseDriver; | ||
import main.java.core.drivers.BaseDriverImpl; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
public class DriverModule extends AbstractModule { | ||
|
||
protected final static Logger MODULE_LOGGER = LoggerFactory.getLogger("ModuleLogger"); | ||
|
||
|
||
@Override | ||
protected void configure() { | ||
MODULE_LOGGER.info("Initialising modules....."); | ||
Properties props = new Properties(); | ||
try { | ||
props.load(new FileInputStream("src/main/resources/application.properties")); | ||
} catch (IOException ioException) { | ||
ioException.printStackTrace(); | ||
} | ||
Names.bindProperties(binder(), props); | ||
bind(BaseDriver.class) | ||
.to(BaseDriverImpl.class) | ||
.in(Scopes.SINGLETON); | ||
bind(BaseDriverImpl.class).in(Scopes.SINGLETON); | ||
MODULE_LOGGER.info("All instanced up and running."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package main.java.exceptions; | ||
|
||
|
||
public class DriverNotFoundException extends RuntimeException { | ||
public DriverNotFoundException(String s) { | ||
throw new RuntimeException(s); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package main.java.pageObjects; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.name.Named; | ||
import main.java.core.BaseDriver; | ||
import main.java.core.BasePage; | ||
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; | ||
|
||
public class ProductPage extends BasePage { | ||
|
||
|
||
private WebDriverWait webDriverWait; | ||
|
||
@Inject | ||
private BaseDriver baseDriver; | ||
|
||
@Inject | ||
@Named("home.page") | ||
private String url; | ||
|
||
@FindBy(css = "span[class='button-content wsb-button-content']") | ||
private WebElement greenTeaTextElement; | ||
|
||
@FindBy(css = "div[id='wsb-element-00000000-0000-0000-0000-000450914895']") | ||
private WebElement teaCollectionElement; | ||
|
||
@FindBy(css = "div[id='wsb-element-00000000-0000-0000-0000-000451934628'") | ||
private WebElement greenTeaProductDescription; | ||
|
||
@Inject | ||
public ProductPage(BaseDriver baseDriver) { | ||
this.webDriverWait = new WebDriverWait(baseDriver.driver(), 60); | ||
PageFactory.initElements(baseDriver.driver(), this); | ||
} | ||
|
||
public ProductPage visitPage() { | ||
this.baseDriver.get(url); | ||
return this; | ||
} | ||
|
||
public String getCollectionList(WebElement webElement) { | ||
this.wait(webElement); | ||
return webElement.getText(); | ||
} | ||
|
||
public ProductPage wait(WebElement webElement) { | ||
this.wait(webElement, webDriverWait); | ||
return this; | ||
} | ||
|
||
@Override | ||
public void wait(WebElement element, WebDriverWait webDriverWait) { | ||
webDriverWait.until(ExpectedConditions.visibilityOf(element)); | ||
} | ||
|
||
@Override | ||
public void scrollIntoView(WebElement webElement) { | ||
|
||
} | ||
|
||
@Override | ||
public void navigateBack() { | ||
|
||
} | ||
|
||
@Override | ||
public void getPageTitle(WebDriver.Window window) { | ||
|
||
} | ||
|
||
@Override | ||
public void select(WebElement webElement, String key) { | ||
} | ||
|
||
public WebElement getGreenTeaTextElement() { | ||
return greenTeaTextElement; | ||
} | ||
|
||
public WebElement getTeaCollectionElement() { | ||
return teaCollectionElement; | ||
} | ||
|
||
public WebElement getGreenTeaProductDescription() { | ||
return greenTeaProductDescription; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package main.java.stateProviders; | ||
|
||
import com.google.inject.Inject; | ||
import main.java.core.BaseDriver; | ||
|
||
public class StateSharingHelper { | ||
|
||
@Inject | ||
BaseDriver baseDriver; | ||
} |
Oops, something went wrong.