Skip to content
Merged
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# JenkinsQA - testing local Jenkins
# JenkinsQA - framework for testing local Jenkins
## Java, TestNg additional Cucumber

9 changes: 2 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.8.0</version>
<version>7.9.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.14.1</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.5.3</version>
<version>4.20.0</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/school/redrover/runner/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ protected void beforeMethod(Method method) {

@AfterMethod
protected void afterMethod(Method method, ITestResult testResult) {
if (ProjectUtils.isServerRun() && !testResult.isSuccess()) {
ProjectUtils.takeScreenshot(driver, method.getName(), this.getClass().getName());
if (!testResult.isSuccess() && ProjectUtils.isServerRun()) {
ProjectUtils.takeScreenshot(getDriver(), testResult);
}

if (methodsOrder.isGroupFinished(method) && !(!ProjectUtils.isServerRun() && !testResult.isSuccess() && !ProjectUtils.closeBrowserIfError())) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/school/redrover/runner/CucumberDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public static void before(Scenario scenario) {

@After
public static void after(Scenario scenario) {
if(scenario.isFailed() && ProjectUtils.isServerRun()) {
ProjectUtils.takeScreenshot(driver, scenario.getName(), "CucumberTest");
}
// if(scenario.isFailed() && ProjectUtils.isServerRun()) {
// ProjectUtils.takeScreenshot(driver, scenario.getName(), "CucumberTest");
// }

JenkinsUtils.logout(driver);
driver.quit();
Expand Down
20 changes: 11 additions & 9 deletions src/test/java/school/redrover/runner/ProjectUtils.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package school.redrover.runner;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.io.FileHandler;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.testng.ITestResult;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Properties;

Expand Down Expand Up @@ -74,7 +76,7 @@ private static void initProperties() {
}
}

WebDriverManager.chromedriver().setup();
// WebDriverManager.chromedriver().setup();
}

static boolean isServerRun() {
Expand Down Expand Up @@ -125,14 +127,14 @@ public static void logf(String str, Object... arr) {
System.out.printf(str, arr);
System.out.println();
}

static File takeScreenshot(WebDriver driver, String methodName, String className) {
File file = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
static void takeScreenshot(WebDriver driver, ITestResult testResult) {
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(file, new File(String.format("screenshots/%s.%s.png", className, methodName)));
Files.createDirectories(Paths.get("screenshots"));
FileHandler.copy(screenshot, new File("screenshots/" + testResult.getInstanceName() + "." + testResult.getName() + ".png"));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return file;
}

}
Loading