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

Develop #12

Open
wants to merge 6 commits 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
61 changes: 61 additions & 0 deletions src/main/java/com/sawyereffect/steps/Hooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.sawyereffect.steps;

import com.sawyereffect.util.DriverFactory;
import cucumber.api.Scenario;
import cucumber.api.java.After;
import cucumber.api.java.AfterStep;
import cucumber.api.java.Before;
import cucumber.api.java.BeforeStep;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;


public class Hooks {
private static final String TAKE_SCREENSHOT = "Screenshot";
private final Logger logger = LoggerFactory.getLogger(Hooks.class);
private DriverFactory driverFactory;
private WebDriver driver;

@Before
public void setupDriver() throws IOException {
driverFactory = new DriverFactory();
driver = driverFactory.getDriver();
}

@After
public void quitDriver(Scenario scenario) throws IOException {

if (driver != null && (scenario.isFailed() || scenario.getName().contains(TAKE_SCREENSHOT))) {

logger.debug("Taking screenshot of scenario {}", scenario.getName());

try {
final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
} catch (WebDriverException e){
logger.error("Not able to take screenshot", e);

}
}

if (driverFactory != null) {
driverFactory.destroyDriver();
}
}

@BeforeStep
public void beforeStep(Scenario scenario) {
logger.debug("Executing before every step {}", scenario.getName());
}

@AfterStep
public void afterStep(Scenario scenario) {
logger.debug("Executing after every step {}", scenario.getName());
}
}
44 changes: 2 additions & 42 deletions src/main/java/com/sawyereffect/steps/StartingSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,20 @@

import com.sawyereffect.util.DriverFactory;
import com.sawyereffect.util.PropertyReader;
import cucumber.api.Scenario;
import cucumber.api.java.After;
import cucumber.api.java.AfterStep;
import cucumber.api.java.Before;
import cucumber.api.java.BeforeStep;
import cucumber.api.java.en.Given;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class StartingSteps {
public class StartingSteps extends DriverFactory{

private static final String TAKE_SCREENSHOT = "Screenshot";
private final Logger logger = LoggerFactory.getLogger(StartingSteps.class);
private DriverFactory driverFactory;
private WebDriver driver;
private final PropertyReader reader = PropertyReader.getPropertyReader();

@Before
public void setupDriver() throws IOException {
driverFactory = new DriverFactory();
driver = driverFactory.getDriver();
}
private final WebDriver driver = getDriver();

@Given("^User is in google main page$")
public void user_is_on_home_page() throws Throwable {
Expand All @@ -54,30 +40,4 @@ private void waitForPageLogoToLoad() {
By.id("hplogo")));
}


@After
public void quitDriver(Scenario scenario) throws IOException {

if (driver != null && (scenario.isFailed() || scenario.getName().contains(TAKE_SCREENSHOT))) {

logger.debug("Taking screenshot of scenario {}", scenario.getName());

final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}

if (driverFactory != null) {
driverFactory.destroyDriver();
}
}

@BeforeStep
public void beforeStep(Scenario scenario) {
logger.debug("Executing before every step {}", scenario.getName());
}

@AfterStep
public void afterStep(Scenario scenario) {
logger.debug("Executing after every step {}", scenario.getName());
}
}