Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.*;
import org.testng.annotations.Test;
import org.testng.xml.XmlTest;

import java.io.IOException;
Expand All @@ -20,24 +20,31 @@
import static com.znsio.applitools.integration.ApplitoolsConfigurationManager.*;

public class ApplitoolsInitializer {
private static WebDriver webDriver;
private static AppiumDriver appiumDriver;
protected com.applitools.eyes.selenium.Eyes eyesOnWeb;
protected com.applitools.eyes.appium.Eyes eyesOnApp;
private WebDriver webDriver;
private AppiumDriver appiumDriver;
private com.applitools.eyes.selenium.Eyes eyesOnWeb;
private com.applitools.eyes.appium.Eyes eyesOnApp;
private static BatchInfo batch;
private static Configuration eyesConfig;
private static EyesRunner runner;
private Configuration eyesConfig;
private EyesRunner runner;
private static final Logger LOGGER = Logger.getLogger(ApplitoolsInitializer.class.getName());

public static void driverSetupForApplitoolsInitializer(WebDriver wDriver) {
webDriver = wDriver;
public void driverSetupForApplitoolsInitializer(WebDriver driver) {
if (isPlatformWeb()) {
webDriver = driver;
} else {
appiumDriver = (AppiumDriver) driver;
}
}

public com.applitools.eyes.selenium.Eyes getWebEyes() {
return this.eyesOnWeb;
}

public static void driverSetupForApplitoolsInitializer(AppiumDriver aDriver) {
appiumDriver = aDriver;
public com.applitools.eyes.appium.Eyes getAppEyes() {
return this.eyesOnApp;
}

@BeforeSuite
public void setUpApplitoolsInitializer(XmlTest suite) throws IOException, RuntimeException {

LOGGER.info("@BeforeSuite of ApplitoolsInitializer called");
Expand All @@ -53,8 +60,7 @@ public void setUpApplitoolsInitializer(XmlTest suite) throws IOException, Runtim
}
}

@BeforeMethod
public void initiateApplitoolsInitializer(Method method) {
public void initiateApplitoolsInitializer(Method method, WebDriver webDriver) {
LOGGER.info("@BeforeMethod of ApplitoolsInitializer called: " + method.getName());
if (isPlatformWeb() && isUltraFastGridEnabled()) {
runner = new VisualGridRunner(new RunnerOptions().testConcurrency(getConcurrency()));
Expand All @@ -63,13 +69,12 @@ public void initiateApplitoolsInitializer(Method method) {
}
runner.setDontCloseBatches(true);
if (isPlatformWeb()) {
initiateVisualWebTests(method);
initiateVisualWebTests(method, webDriver);
} else {
initiateVisualAppTests(method);
}
}

@AfterMethod
public void closeApplitoolsInitializer(ITestResult iTestResult) {
LOGGER.info("@AfterMethod of ApplitoolsInitializer called: Waiting for visual validation results of test: " +
iTestResult.getName());
Expand All @@ -78,7 +83,7 @@ public void closeApplitoolsInitializer(ITestResult iTestResult) {
} else {
eyesOnApp.closeAsync();
}
TestResults testResult = new TestResults();
TestResults testResult = new TestResults();
TestResultsSummary allTestResults = runner.getAllTestResults(false);
TestResultContainer[] results = allTestResults.getAllResults();
LOGGER.info(String.format("Number of cross-browser tests run for test: %s: %d%n",
Expand All @@ -95,13 +100,12 @@ public void closeApplitoolsInitializer(ITestResult iTestResult) {
}
}

@AfterSuite
public void closeBatch() {
LOGGER.info("@AfterSuite of ApplitoolsInitializer called: Close Visual Test batch");
batch.setCompleted(true);
}

private void initiateVisualWebTests(Method method) {
private void initiateVisualWebTests(Method method, WebDriver webDriver) {
eyesOnWeb = new com.applitools.eyes.selenium.Eyes(runner);
if (isLogsEnabled()) {
eyesOnWeb.setLogHandler(new StdoutLogHandler(isLogsEnabled()));
Expand Down Expand Up @@ -166,4 +170,4 @@ private void handleFunctionalTestResults(String methodName, TestResults testResu
"because visual validation failed", methodName)));
}
}
}
}