diff --git a/README.md b/README.md index b2fa22519..8e49ebba7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Maven Central](https://img.shields.io/maven-central/v/com.xceptance/neodymium-library.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.xceptance%22%20AND%20a:%22neodymium-library%22) [![Join the chat at https://gitter.im/neodymium-library/community](https://badges.gitter.im/neodymium-library/community.svg)](https://gitter.im/neodymium-library/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -# Neodymium v3.3.1 +# Neodymium v3.4.0 Neodymium tries to solve your typical and most pressing UI test automation problems by combining JUnit, WebDriver, BDD/Cucumber, and proper reporting. It gives you ready to use templates, assembles well-known open source projects, and enhances this all with additional functionality that is often missing. Neodymium is basically the combination of state of the art open source test libraries with additionally glue to make it stick reliably together. diff --git a/config/ai.properties b/config/ai.properties index a1a6ee5e7..0b314ef67 100644 --- a/config/ai.properties +++ b/config/ai.properties @@ -14,7 +14,7 @@ #neodymium.ai.FORMAT = png ######################################################################### -# Global flag to turn visual asserations off, nothing will be done, all code is skipped +# Global flag to turn visual assertions off, nothing will be done, all code is skipped neodymium.ai.enabled = false # Result directory for the image output, relative to the test suite @@ -25,7 +25,7 @@ neodymium.ai.resultDirectory = results/ai # The ID is used in the creation of the folder structure for the results. neodymium.ai.ID = localmachine -# Bound to the choosen test case or not. +# Bound to the chosen test case or not. # If the flag is true the name of the used test case will be used for localization. # The value false let the network unbound and can be used for different testcases neodymium.ai.TESTCASE_BOUND = true @@ -49,8 +49,8 @@ neodymium.ai.WAITINGTIME = 1000 # procedural value between 0 - 1.00 percent neodymium.ai.INTENDED_PERCENTAGE_MATCH = 0.80 -# Color will also be used for image comparison, useful for websides with much almost same size content. -# Constent is every element on the webside. +# Color will also be used for image comparison, useful for websites with much almost same size content. +# Content is every element on the website. neodymium.ai.USE_COLOR_FOR_COMPARISON = true # Parameter for enabling down scaling from screenshots or not, this can drastically change @@ -68,7 +68,7 @@ neodymium.ai.PERCENTAGE_DIFFERENCE = 0.2 # value for the learning algorithm allowed values are between 0.0 - 1.0 # affect the learn speed of the neural network, greater values are for faster learning -# but the accurancy can decrease with higher values +# but the accuracy can decrease with higher values neodymium.ai.LEARNING_RATE = 0.3 # image format for saving diff --git a/config/neodymium.properties b/config/neodymium.properties index 1b98de017..8f4ab0658 100644 --- a/config/neodymium.properties +++ b/config/neodymium.properties @@ -85,7 +85,7 @@ # Neodymium context properties # ############################# -# The following setting reassemble responsive design breakpoints. They determine at which page width a site is considered to be displayed on a small, medium, large oder extra large device. +# The following setting reassemble responsive design breakpoints. They determine at which page width a site is considered to be displayed on a small, medium, large or extra large device. # You can use the by calling e.g. Neodymium.isSmallDesktop() # # neodymium.context.device.breakpoint.small = 576 @@ -98,7 +98,7 @@ # JavaScriptUtils properties # ############################# -# The following properties are taken into account if you use functions form the JavaScripUtils class. +# The following properties are taken into account if you use functions form the JavaScriptUtils class. # # neodymium.javaScriptUtils.timeout = 2000 # neodymium.javaScriptUtils.pollingInterval = 200 diff --git a/config/visualassertion.properties b/config/visualassertion.properties index 7b6372bdd..63a9d83a7 100644 --- a/config/visualassertion.properties +++ b/config/visualassertion.properties @@ -1,4 +1,4 @@ -# Global flag to turn visual asserations off, nothing will be done, all code is skipped +# Global flag to turn visual assertions off, nothing will be done, all code is skipped neodymium.visualassertion.enabled=true # Result directory for the image output, relative to the test suite @@ -20,7 +20,7 @@ neodymium.visualassertion.mark.blocksize.x=10 neodymium.visualassertion.mark.blocksize.y=10 ## How the marking should look like - marking type -# box: Draw a box with blocksize, the difference box might not be in the center, it is effectivly +# box: Draw a box with blocksize, the difference box might not be in the center, it is effectively # the comparison box used in the algorithm. # marker: Use yellow highlighter and mark different pixels in red too neodymium.visualassertion.mark.type=marker diff --git a/pom.xml b/pom.xml index 5d9fa9809..c5fa56c17 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.xceptance neodymium-library - 3.3.1 + 3.4.0 neodymium-library https://github.com/Xceptance/neodymium-library @@ -55,8 +55,8 @@ 1.8 2.22.1 2.12.1 - 4.3.1 - 2.11.2 + 4.7.2 + 2.12.1 @@ -202,7 +202,7 @@ org.yaml snakeyaml - 1.24 + 1.25 io.cucumber @@ -242,12 +242,12 @@ com.google.guava guava - 27.1-jre + 28.1-jre com.codeborne selenide - 5.2.3 + 5.2.8 net.lightbody.bmp @@ -258,12 +258,12 @@ org.apache.commons commons-csv - 1.6 + 1.7 org.apache.commons commons-text - 1.6 + 1.7 org.apache.commons @@ -273,7 +273,7 @@ org.slf4j slf4j-api - 1.7.26 + 1.7.28 org.apache.logging.log4j diff --git a/src/main/java/com/xceptance/neodymium/NeodymiumCucumberRunner.java b/src/main/java/com/xceptance/neodymium/NeodymiumCucumberRunner.java index c272818ce..1e63c4c6a 100644 --- a/src/main/java/com/xceptance/neodymium/NeodymiumCucumberRunner.java +++ b/src/main/java/com/xceptance/neodymium/NeodymiumCucumberRunner.java @@ -5,7 +5,7 @@ import org.junit.runner.notification.RunNotifier; import org.junit.runners.model.InitializationError; -import cucumber.api.junit.Cucumber; +import io.cucumber.junit.Cucumber; public class NeodymiumCucumberRunner extends Cucumber { @@ -18,7 +18,7 @@ public NeodymiumCucumberRunner(Class clazz) throws InitializationError, IOExc public void run(RunNotifier notifier) { // we add our own run listener in order to attach screenshots taken by Selenide to the Allure report - // this also neccessary to clear the context between tests + // this also necessary to clear the context between tests notifier.addListener(new NeodymiumCucumberRunListener()); super.run(notifier); } diff --git a/src/main/java/com/xceptance/neodymium/NeodymiumRunner.java b/src/main/java/com/xceptance/neodymium/NeodymiumRunner.java index 4bb74f4f6..eef31443a 100644 --- a/src/main/java/com/xceptance/neodymium/NeodymiumRunner.java +++ b/src/main/java/com/xceptance/neodymium/NeodymiumRunner.java @@ -94,7 +94,7 @@ public enum DescriptionMode @Override protected Statement methodBlock(FrameworkMethod method) { - // This will build a default JUnit statement which runs excactly one of the test methods including before/after + // This will build a default JUnit statement which runs exactly one of the test methods including before/after // methods. This call will also create the test class instance in which this method will be invoked. Statement methodStatement = super.methodBlock(method); // We need this particular test class instance for our own statements but we can not access it from here. @@ -160,7 +160,7 @@ protected List computeTestMethods() // super.computeTestMethods will return all methods that are annotated with @Test for (FrameworkMethod testAnnotatedMethod : super.computeTestMethods()) { - // these lists contain all the builders and data that will be responsible for a partiuclar method + // these lists contain all the builders and data that will be responsible for a particular method List builderList = new LinkedList<>(); List> builderDataList = new LinkedList<>(); diff --git a/src/main/java/com/xceptance/neodymium/module/statement/browser/BrowserStatement.java b/src/main/java/com/xceptance/neodymium/module/statement/browser/BrowserStatement.java index 66b893a24..b8cc83b03 100644 --- a/src/main/java/com/xceptance/neodymium/module/statement/browser/BrowserStatement.java +++ b/src/main/java/com/xceptance/neodymium/module/statement/browser/BrowserStatement.java @@ -3,7 +3,6 @@ import java.net.MalformedURLException; import java.text.MessageFormat; import java.util.Arrays; -import java.util.Collection; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; @@ -16,6 +15,7 @@ import org.junit.runners.model.TestClass; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.support.events.EventFiringWebDriver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -154,7 +154,7 @@ public void setUpTest(String browserTag) } catch (final MalformedURLException e) { - throw new RuntimeException("An error occured during URL creation. See nested exception.", e); + throw new RuntimeException("An error occurred during URL creation. See nested exception.", e); } if (webdriver != null) { @@ -184,60 +184,42 @@ private void initSelenideConfiguration() } public void teardown(boolean testFailed) + { + teardown(testFailed, false, webdriver); + } + + public void teardown(boolean testFailed, boolean preventReuse, WebDriver webDriver) { BrowserConfiguration browserConfiguration = multibrowserConfiguration.getBrowserProfiles().get(Neodymium.getBrowserProfileName()); - if (testFailed && Neodymium.configuration().keepBrowserOpenOnFailure() && !browserConfiguration.isHeadless()) + // keep browser open + if ((browserConfiguration != null && !browserConfiguration.isHeadless()) + && ((Neodymium.configuration().keepBrowserOpenOnFailure() && testFailed) || Neodymium.configuration().keepBrowserOpen())) { - // test failed and we want to leave the browser instance open - // don't quit the webdriver, just remove references LOGGER.debug("Keep browser open"); - Neodymium.setDriver(null); - Neodymium.setBrowserProfileName(null); - Neodymium.setBrowserName(null); - return; + // nothing to do } - - if (Neodymium.configuration().reuseWebDriver()) + // reuse + else if (Neodymium.configuration().reuseWebDriver() && !preventReuse && isWebDriverStillOpen(webDriver)) { LOGGER.debug("Put browser into cache"); WebDriverCache.instance.putWebDriver(browserTag, webdriver); } + // close the WebDriver else { - if (browserConfiguration.isHeadless() || !Neodymium.configuration().keepBrowserOpen()) + LOGGER.debug("Teardown browser"); + if (webDriver != null) { - LOGGER.debug("Teardown browser"); - if (webdriver != null) - webdriver.quit(); + webDriver.quit(); } } + Neodymium.setDriver(null); Neodymium.setBrowserProfileName(null); Neodymium.setBrowserName(null); } - public static void quitCachedBrowser() - { - if (!Neodymium.configuration().keepBrowserOpen()) - { - Collection allWebdriver = WebDriverCache.instance.getAllWebdriver(); - - for (WebDriver wd : allWebdriver) - { - try - { - LOGGER.debug("Quit web driver: " + wd.toString()); - wd.quit(); - } - catch (Exception e) - { - LOGGER.debug("Error on quitting web driver", e); - } - } - } - } - @Override public List createIterationData(TestClass testClass, FrameworkMethod method) { @@ -321,7 +303,6 @@ public List findClassBrowserAnnotation(Class clazz) { return browserAnnotations; } - } @Override @@ -350,4 +331,22 @@ public List getBrowserTags() return tags; } + + private boolean isWebDriverStillOpen(WebDriver webDriver) + { + if (webDriver == null) + { + return false; + } + try + { + RemoteWebDriver driver = (RemoteWebDriver) ((EventFiringWebDriver) webDriver).getWrappedDriver(); + return driver.getSessionId() != null; + } + catch (Exception e) + { + LOGGER.warn("Couldn't detect if the WebDriver is still open!", e); + return true; + } + } } diff --git a/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/BrowserRunnerHelper.java b/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/BrowserRunnerHelper.java index bc4ee122d..04732e5fc 100644 --- a/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/BrowserRunnerHelper.java +++ b/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/BrowserRunnerHelper.java @@ -133,7 +133,7 @@ else if (windowWidth > 0 && windowHeight > 0) } catch (final WebDriverException e) { - // on saucelabs in some cases like iphone emulation you cant resize the browser. + // on saucelabs in some cases like iphone emulation you can't resize the browser. // they throw an unchecked WebDriverException with the message "Not yet implemented" // if we catch an exception we check the message. if another message is set we throw the exception else // we suppress it @@ -165,7 +165,7 @@ private static FirefoxBinary createFirefoxBinary(final String pathToBrowser) * Instantiate the {@link WebDriver} according to the configuration read from {@link Browser} annotations. * * @param config - * {@link BrowserConfiguration} that describes the descired browser instance + * {@link BrowserConfiguration} that describes the desired browser instance * @return {@link WebDriver} the instance of the browser described in {@link BrowserConfiguration} * @throws MalformedURLException * if Selenium grid is diff --git a/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/WebDriverCache.java b/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/WebDriverCache.java index 6372d0017..fe8fe1e64 100644 --- a/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/WebDriverCache.java +++ b/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/WebDriverCache.java @@ -7,6 +7,8 @@ import java.util.Map.Entry; import org.openqa.selenium.WebDriver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A cache to hold different instances of {@link WebDriver}. Instances are kept in a synchronized {@link HashMap} which @@ -18,15 +20,17 @@ */ public class WebDriverCache { + public static Logger LOGGER = LoggerFactory.getLogger(WebDriverCache.class); + public static final WebDriverCache instance = new WebDriverCache(); private static final Map cache = Collections.synchronizedMap(new HashMap<>()); /** - * The private constructor of the {@link WebDriverCache}. Creates the synchronized {@link HashMap} instance and add's a - * VM shutdown hook to clean up the cache and close the cached {@link WebDriver} gracefully if the - * neodymium.webDriver.keepBrowserOpen property is set to false in property file "browser.properties". See - * config folder + * The private constructor of the {@link WebDriverCache}. Creates the synchronized {@link HashMap} instance and + * add's a VM shutdown hook to clean up the cache and close the cached {@link WebDriver} gracefully if the + * neodymium.webDriver.keepBrowserOpen property is set to false in property file "browser.properties". + * See config folder */ private WebDriverCache() { @@ -46,8 +50,9 @@ public WebDriver getWebDriverForBrowserTag(String browserTag) } /** - * Put's the instance of a {@link WebDriver} into the cache and uses browserTag to reference it. If there is already an - * {@link WebDriver} stored in the cache with the same browsreTag {@link String} then the instance will be overwritten. + * Put's the instance of a {@link WebDriver} into the cache and uses browserTag to reference it. If there is already + * an {@link WebDriver} stored in the cache with the same browserTag {@link String} then the instance will be + * overwritten. * * @param browserTag * a {@link String} that will be used to reference the cached {@link WebDriver} @@ -105,7 +110,6 @@ public boolean removeWebDriver(WebDriver driver) removed = true; } } - return removed; } } @@ -119,4 +123,37 @@ public Collection getAllWebdriver() { return Collections.unmodifiableCollection(cache.values()); } + + /** + * This function can be used within a function of a JUnit test case that is annotated with @AfterClass to clear the + * WebDriverCache of the WebDrivers ready for reuse. + *

+ * Attention: It is save to run this function during a sequential test execution. It can have repercussions + * (e.g. longer test duration) in a parallel execution environment. + * + *

+     * @AfterClass
+     * public void afterClass()
+     * {
+     *     WebDriverCache.quitCachedBrowsers();
+     * }
+     * 
+ **/ + public static void quitCachedBrowsers() + { + Collection allWebdriver = instance.getAllWebdriver(); + for (WebDriver wd : allWebdriver) + { + try + { + LOGGER.debug("Quit web driver: " + wd.toString()); + wd.quit(); + instance.removeWebDriver(wd); + } + catch (Exception e) + { + LOGGER.debug("Error on quitting web driver", e); + } + } + } } diff --git a/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/WebDriverCacheCleanupHook.java b/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/WebDriverCacheCleanupHook.java index 0244e18d7..7e7a939ea 100644 --- a/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/WebDriverCacheCleanupHook.java +++ b/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/WebDriverCacheCleanupHook.java @@ -3,8 +3,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.xceptance.neodymium.module.statement.browser.BrowserStatement; - public class WebDriverCacheCleanupHook extends Thread { @@ -14,6 +12,6 @@ public class WebDriverCacheCleanupHook extends Thread public void run() { LOGGER.debug("All tests finished. Quit cached browser"); - BrowserStatement.quitCachedBrowser(); + WebDriverCache.quitCachedBrowsers(); } } diff --git a/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/configuration/BrowserConfigurationMapper.java b/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/configuration/BrowserConfigurationMapper.java index f0fbb28e9..2171a06e8 100644 --- a/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/configuration/BrowserConfigurationMapper.java +++ b/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/configuration/BrowserConfigurationMapper.java @@ -29,6 +29,12 @@ public class BrowserConfigurationMapper private static final String SCREEN_RESOLUTION = "screenResolution"; + private static final String MAXIMUM_DURATION = "maxDuration"; + + private static final String IDLE_TIMEOUT = "idleTimeout"; + + private static final String SELENIUM_VERSION = "seleniumVersion"; + private static final String BROWSER_RESOLUTION = "browserResolution"; private static final String CHROME_EMULATION_PROFILE = "chromeEmulationProfile"; @@ -110,7 +116,7 @@ else if ("opera".equals(emulatedBrowser)) } /* - * SauceLabs configuration + * SauceLabs/TestingBot configuration */ String emulatedPlatform = browserProfileConfiguration.get(PLATFORM); if (!StringUtils.isEmpty(emulatedPlatform)) @@ -128,21 +134,67 @@ else if ("opera".equals(emulatedBrowser)) if (!StringUtils.isEmpty(emulatedDeviceName)) capabilities.setCapability("deviceName", emulatedDeviceName); - String emulatedDeviceOrienation = browserProfileConfiguration.get(DEVICE_ORIENTATION); - if (!StringUtils.isEmpty(emulatedDeviceOrienation)) - capabilities.setCapability("deviceOrientation", emulatedDeviceOrienation); + String emulatedDeviceOrientation = browserProfileConfiguration.get(DEVICE_ORIENTATION); + if (!StringUtils.isEmpty(emulatedDeviceOrientation)) + capabilities.setCapability("deviceOrientation", emulatedDeviceOrientation); String emulatedDeviceScreenResolution = browserProfileConfiguration.get(SCREEN_RESOLUTION); if (!StringUtils.isEmpty(emulatedDeviceScreenResolution)) { // SauceLabs capabilities.setCapability("screenResolution", emulatedDeviceScreenResolution); - // testingBot + // TestingBot capabilities.setCapability("screen-resolution", emulatedDeviceScreenResolution); } - // appium + String emulatedMaximumTestDuration = browserProfileConfiguration.get(MAXIMUM_DURATION); + if (!StringUtils.isEmpty(emulatedMaximumTestDuration)) + { + int maxDura = 0; + try + { + maxDura = Integer.parseInt(emulatedMaximumTestDuration); + } + catch (Exception e) + { + throw new RuntimeException(MAXIMUM_DURATION + " configured within the browser profiles couldn't be parsed into an int value. Given value: \"" + + emulatedMaximumTestDuration + "\"", e); + } + // SauceLabs + capabilities.setCapability("maxDuration", maxDura); + // TestingBot + capabilities.setCapability("maxduration", maxDura); + } + + String emulatedIdleTimeout = browserProfileConfiguration.get(IDLE_TIMEOUT); + if (!StringUtils.isEmpty(emulatedIdleTimeout)) + { + int idleTim = 0; + try + { + idleTim = Integer.parseInt(emulatedIdleTimeout); + } + catch (Exception e) + { + throw new RuntimeException(IDLE_TIMEOUT + " configured within the browser profiles couldn't be parsed into an int value. Given value: \"" + + emulatedIdleTimeout + "\"", e); + } + // SauceLabs + capabilities.setCapability("idleTimeout", idleTim); + // TestingBot + capabilities.setCapability("idletimeout", idleTim); + } + + String emulatedSeleniumVersion = browserProfileConfiguration.get(SELENIUM_VERSION); + if (!StringUtils.isEmpty(emulatedSeleniumVersion)) + { + // SauceLabs + capabilities.setCapability("seleniumVersion", emulatedSeleniumVersion); + // TestingBot + capabilities.setCapability("selenium-version", emulatedSeleniumVersion); + } + // appium String appiumVersion = browserProfileConfiguration.get(APPIUM_VERSION); if (!StringUtils.isEmpty(appiumVersion)) capabilities.setCapability(APPIUM_VERSION, appiumVersion); @@ -151,13 +203,13 @@ else if ("opera".equals(emulatedBrowser)) if (!StringUtils.isEmpty(browserName)) capabilities.setCapability(BROWSER_NAME, browserName); - String plattformVersion = browserProfileConfiguration.get(PLATFORM_VERSION); - if (!StringUtils.isEmpty(plattformVersion)) - capabilities.setCapability(PLATFORM_VERSION, plattformVersion); + String platformVersion = browserProfileConfiguration.get(PLATFORM_VERSION); + if (!StringUtils.isEmpty(platformVersion)) + capabilities.setCapability(PLATFORM_VERSION, platformVersion); - String plattformName = browserProfileConfiguration.get(PLATFORM_NAME); - if (!StringUtils.isEmpty(plattformName)) - capabilities.setCapability(PLATFORM_NAME, plattformName); + String platformName = browserProfileConfiguration.get(PLATFORM_NAME); + if (!StringUtils.isEmpty(platformName)) + capabilities.setCapability(PLATFORM_NAME, platformName); String app = browserProfileConfiguration.get(APP); if (!StringUtils.isEmpty(app)) @@ -167,9 +219,9 @@ else if ("opera".equals(emulatedBrowser)) if (!StringUtils.isEmpty(automationName)) capabilities.setCapability(AUTOMATION_NAME, automationName); - String oriantation = browserProfileConfiguration.get(ORIENTATION); - if (!StringUtils.isEmpty(oriantation)) - capabilities.setCapability(ORIENTATION, oriantation); + String orientation = browserProfileConfiguration.get(ORIENTATION); + if (!StringUtils.isEmpty(orientation)) + capabilities.setCapability(ORIENTATION, orientation); /* * Chrome device emulation diff --git a/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/configuration/TestEnvironment.java b/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/configuration/TestEnvironment.java index 7dac37252..325c57dee 100644 --- a/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/configuration/TestEnvironment.java +++ b/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/configuration/TestEnvironment.java @@ -33,7 +33,7 @@ protected TestEnvironment(Properties properties, String baseKey) proxyHost = properties.getProperty(baseKey + ".proxy.host"); if (StringUtils.isBlank(proxyHost)) { - throw new RuntimeException("The proxy host configured for evironment: \"" + baseKey + "\" needs to be set."); + throw new RuntimeException("The proxy host configured for environment: \"" + baseKey + "\" needs to be set."); } String port = properties.getProperty(baseKey + ".proxy.port"); @@ -45,12 +45,12 @@ protected TestEnvironment(Properties properties, String baseKey) } catch (NumberFormatException e) { - throw new RuntimeException("The proxy port configured for evironment: \"" + baseKey + "\" needs to be an Integer."); + throw new RuntimeException("The proxy port configured for environment: \"" + baseKey + "\" needs to be an Integer."); } } else { - throw new RuntimeException("The proxy port configured for evironment: \"" + baseKey + "\" needs to be set."); + throw new RuntimeException("The proxy port configured for environment: \"" + baseKey + "\" needs to be set."); } proxyUsername = properties.getProperty(baseKey + ".proxy.username"); proxyPassword = properties.getProperty(baseKey + ".proxy.password"); diff --git a/src/main/java/com/xceptance/neodymium/module/statement/parameter/ParameterStatement.java b/src/main/java/com/xceptance/neodymium/module/statement/parameter/ParameterStatement.java index 70ffc7eff..bd81d2d82 100644 --- a/src/main/java/com/xceptance/neodymium/module/statement/parameter/ParameterStatement.java +++ b/src/main/java/com/xceptance/neodymium/module/statement/parameter/ParameterStatement.java @@ -182,7 +182,7 @@ else if (fieldType == boolean.class || fieldType == Boolean.class) } catch (Exception e) { - throw new RuntimeException("An error occured during conversion of input string \"" + (String) value + "\" to type " + + throw new RuntimeException("An error occurred during conversion of input string \"" + (String) value + "\" to type " + fieldType.getName() + " for field \"" + field.getName() + "\"", e); } } diff --git a/src/main/java/com/xceptance/neodymium/module/statement/testdata/DataFile.java b/src/main/java/com/xceptance/neodymium/module/statement/testdata/DataFile.java new file mode 100644 index 000000000..9d38c5867 --- /dev/null +++ b/src/main/java/com/xceptance/neodymium/module/statement/testdata/DataFile.java @@ -0,0 +1,26 @@ +package com.xceptance.neodymium.module.statement.testdata; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * This annotation can be used to override the data sets file location. Usually, this file is expected to be named as + * the test case and to be located in the same package in the resource folder. + *

+ * The file referred to by this annotation needs to reside within the resource path. Provide the full path to the file + * relative to the resource folder, including the file extension. + * + * @author m.pfotenhauer + */ +@Retention(RUNTIME) +@Target( +{ + TYPE +}) +public @interface DataFile +{ + String value() default ""; +} diff --git a/src/main/java/com/xceptance/neodymium/module/statement/testdata/DataSet.java b/src/main/java/com/xceptance/neodymium/module/statement/testdata/DataSet.java index 5aa3752ab..bdeefb948 100644 --- a/src/main/java/com/xceptance/neodymium/module/statement/testdata/DataSet.java +++ b/src/main/java/com/xceptance/neodymium/module/statement/testdata/DataSet.java @@ -1,7 +1,8 @@ package com.xceptance.neodymium.module.statement.testdata; -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.*; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; @@ -23,9 +24,9 @@ */ @Retention(RUNTIME) @Target( - { - TYPE, METHOD - }) +{ + TYPE, METHOD +}) @Repeatable(DataSets.class) public @interface DataSet { diff --git a/src/main/java/com/xceptance/neodymium/module/statement/testdata/TestdataStatement.java b/src/main/java/com/xceptance/neodymium/module/statement/testdata/TestdataStatement.java index cab6fb9d7..929604a71 100644 --- a/src/main/java/com/xceptance/neodymium/module/statement/testdata/TestdataStatement.java +++ b/src/main/java/com/xceptance/neodymium/module/statement/testdata/TestdataStatement.java @@ -53,7 +53,6 @@ public TestdataStatement(Statement next, TestdataStatementData parameter) testData.put(newDataEntry.getKey(), newDataEntry.getValue()); } } - } public TestdataStatement() @@ -134,7 +133,7 @@ private List processDuplicates(List iterations) { // now the funny part, we encountered an duplicated object - // always set the first occurance of an object to 1 + // always set the first occurrence of an object to 1 TestdataStatementData existingObject = (TestdataStatementData) object; existingObject.setIterationIndex(1); diff --git a/src/main/java/com/xceptance/neodymium/module/statement/testdata/util/TestDataUtils.java b/src/main/java/com/xceptance/neodymium/module/statement/testdata/util/TestDataUtils.java index 7ee41bbcb..38856d6dc 100644 --- a/src/main/java/com/xceptance/neodymium/module/statement/testdata/util/TestDataUtils.java +++ b/src/main/java/com/xceptance/neodymium/module/statement/testdata/util/TestDataUtils.java @@ -24,6 +24,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.xceptance.neodymium.module.statement.testdata.DataFile; + /** * Utility class for test data handling. * @@ -52,17 +54,36 @@ public static List> getDataSets(final Class testClass) th // no specific file -> try the usual suspects final Set fileNames = new LinkedHashSet(); - final String dottedName = testClass.getName(); - final String slashedName = dottedName.replace('.', '/'); + DataFile dataFile = testClass.getAnnotation(DataFile.class); + String filePath = dataFile != null ? dataFile.value() : null; + + if (StringUtils.isBlank(filePath)) + { + final String dottedName = testClass.getName(); + final String slashedName = dottedName.replace('.', '/'); - String[] filetype = new String[] + String[] filetype = new String[] { - ".csv", ".json", ".xml" + ".csv", ".json", ".xml" }; - for (final String fileExtension : filetype) + for (final String fileExtension : filetype) + { + fileNames.add(slashedName + fileExtension); + fileNames.add(dottedName + fileExtension); + } + } + else { - fileNames.add(slashedName + fileExtension); - fileNames.add(dottedName + fileExtension); + InputStream inputStream = testClass.getResourceAsStream("/" + filePath); + if (inputStream != null) + { + fileNames.add(filePath); + } + else + { + throw new RuntimeException("The data file:\"" + filePath + "\" provided within the test class:\"" + testClass.getSimpleName() + + "\" can't be read."); + } } List dataSetFileDirs = new LinkedList<>(); diff --git a/src/main/java/com/xceptance/neodymium/util/Neodymium.java b/src/main/java/com/xceptance/neodymium/util/Neodymium.java index 5e54ecbab..05f923424 100644 --- a/src/main/java/com/xceptance/neodymium/util/Neodymium.java +++ b/src/main/java/com/xceptance/neodymium/util/Neodymium.java @@ -40,7 +40,7 @@ public class Neodymium // our data for anywhere access private final Map data = new HashMap<>(); - public final static String TEMPORARY_CONFIG_FILE_PROPTERY_NAME = "neodymium.temporaryConfigFile"; + public final static String TEMPORARY_CONFIG_FILE_PROPERTY_NAME = "neodymium.temporaryConfigFile"; /** * Constructor @@ -48,9 +48,9 @@ public class Neodymium private Neodymium() { // the property needs to be a valid URI in order to satisfy the Owner framework - if (null == ConfigFactory.getProperty(TEMPORARY_CONFIG_FILE_PROPTERY_NAME)) + if (null == ConfigFactory.getProperty(TEMPORARY_CONFIG_FILE_PROPERTY_NAME)) { - ConfigFactory.setProperty(TEMPORARY_CONFIG_FILE_PROPTERY_NAME, "file:this/path/should/never/exist/noOneShouldCreateMe.properties"); + ConfigFactory.setProperty(TEMPORARY_CONFIG_FILE_PROPERTY_NAME, "file:this/path/should/never/exist/noOneShouldCreateMe.properties"); } configuration = ConfigFactory.create(NeodymiumConfiguration.class, System.getProperties(), System.getenv()); localization = NeodymiumLocalization.build(configuration.localizationFile()); @@ -279,7 +279,7 @@ public static boolean isTablet() /** * Desktop of any kind? * - * @return boolean value indicating whether it is a device desktop (isLargeDesktop() or isExtaLargeDesktop()) or not + * @return boolean value indicating whether it is a device desktop (isLargeDesktop() or isExtraLargeDesktop()) or not * @see Neodymium */ public static boolean isDesktop() diff --git a/src/main/java/com/xceptance/neodymium/util/SelenideAddons.java b/src/main/java/com/xceptance/neodymium/util/SelenideAddons.java index 09fcc0a31..2f5606da8 100644 --- a/src/main/java/com/xceptance/neodymium/util/SelenideAddons.java +++ b/src/main/java/com/xceptance/neodymium/util/SelenideAddons.java @@ -4,6 +4,7 @@ import java.util.function.Supplier; import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; import org.openqa.selenium.By; import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.WebElement; @@ -266,10 +267,21 @@ public static void wrapAssertionError(final Runnable runnable) catch (AssertionError e) { Driver driver = WebDriverRunner.driver(); - SelenideLogger.commitStep(new SelenideLog("Assertion error", e.getMessage()), e); + String message = "No error message provided by the Assertion."; + if (StringUtils.isNotBlank(e.getMessage())) + { + message = e.getMessage(); + } + else + { + AssertionError wrapper = new AssertionError(message, e.getCause()); + wrapper.setStackTrace(e.getStackTrace()); + e = wrapper; + } + SelenideLogger.commitStep(new SelenideLog("Assertion error", message), e); if (!driver.config().assertionMode().equals(AssertionMode.SOFT)) { - throw UIAssertionError.wrap(driver, e, System.currentTimeMillis()); + throw UIAssertionError.wrap(driver, e, 0); } } } diff --git a/src/main/java/com/xceptance/neodymium/util/WebDriverUtils.java b/src/main/java/com/xceptance/neodymium/util/WebDriverUtils.java index 54544a971..4fbe18662 100644 --- a/src/main/java/com/xceptance/neodymium/util/WebDriverUtils.java +++ b/src/main/java/com/xceptance/neodymium/util/WebDriverUtils.java @@ -7,8 +7,9 @@ import org.apache.commons.lang3.StringUtils; import com.xceptance.neodymium.module.statement.browser.BrowserStatement; +import com.xceptance.neodymium.module.statement.browser.multibrowser.WebDriverCache; -import cucumber.api.Scenario; +import io.cucumber.core.api.Scenario; public class WebDriverUtils { @@ -61,6 +62,26 @@ public static void setUpWithBrowserTag(Scenario scenario) browserStatement.get().setUpTest(browserProfileName); } + /** + * This function can be used within a function of a JUnit test case that is annotated with @After to prevent the + * reuse of the current WebDriver + * + *
+     * @After
+     * public void after()
+     * {
+     *     if (someConditionIsFulfilled)
+     *     {
+     *         WebDriverUtils.preventReuseAndTearDown();
+     *     }
+     * }
+     * 
+ **/ + public static void preventReuseAndTearDown() + { + browserStatement.get().teardown(false, true, Neodymium.getDriver()); + } + /** * @param scenario * Scenario is a Cucumber API class that can be gathered in hooks via dependency injection @@ -87,6 +108,26 @@ public static void tearDown(boolean isFailed) browserStatement.get().teardown(isFailed); } + /** + * This function can be used within a function of a JUnit test case that is annotated with @AfterClass to clear the + * WebDriverCache of the WebDrivers ready for reuse. + *

+ * Attention: It is save to run this function during a sequential test execution. It can have repercussions + * (e.g. longer test duration) in a parallel execution environment. + * + *

+     * @AfterClass
+     * public void afterClass()
+     * {
+     *     WebDriverUtils.quitReusableCachedBrowsers();
+     * }
+     * 
+ **/ + public static void quitReusableCachedBrowsers() + { + WebDriverCache.quitCachedBrowsers(); + } + static String getFirstMatchingBrowserTag(Scenario scenario) { Collection scenarioTags = scenario.getSourceTagNames(); diff --git a/src/main/java/com/xceptance/neodymium/util/YamlProperties.java b/src/main/java/com/xceptance/neodymium/util/YamlProperties.java index d3f28a214..a0f3a59fd 100644 --- a/src/main/java/com/xceptance/neodymium/util/YamlProperties.java +++ b/src/main/java/com/xceptance/neodymium/util/YamlProperties.java @@ -61,7 +61,7 @@ private String buildKey(final Deque state) * @param entry * the entry * @param state - * the current staate of the stack + * the current state of the stack */ private void handleTypes(final Object entry, final Deque state) { diff --git a/src/main/java/com/xceptance/neodymium/visual/ai/AI.java b/src/main/java/com/xceptance/neodymium/visual/ai/AI.java index b8e889310..942a75dee 100644 --- a/src/main/java/com/xceptance/neodymium/visual/ai/AI.java +++ b/src/main/java/com/xceptance/neodymium/visual/ai/AI.java @@ -227,7 +227,7 @@ public void execute(final WebDriver webdriver, String testCaseName, String actio Assert.assertNotNull("Screenshot couldn't be taken by the WebDriver", screenshot); // if the network is not done with training check the training folder for changes - // if there are changes, all unknwon images get loaded + // if there are changes, all unknown images get loaded imgList.add(screenshot); if (Constants.NETWORK_MODE) { diff --git a/src/main/java/com/xceptance/neodymium/visual/ai/NetworkTrainer.java b/src/main/java/com/xceptance/neodymium/visual/ai/NetworkTrainer.java index 7bd9b9a9c..26e6841b8 100644 --- a/src/main/java/com/xceptance/neodymium/visual/ai/NetworkTrainer.java +++ b/src/main/java/com/xceptance/neodymium/visual/ai/NetworkTrainer.java @@ -105,7 +105,7 @@ public static void main(String[] args) PerceptronLearning pl = new PerceptronLearning(an); pl.setLearningRate(Constants.LEARNING_RATE); - double resultVerfication = 0.0; + double resultVerification = 0.0; for (PatternHelper pattern : patternList) { pl.run(pattern.getPatternList()); @@ -113,11 +113,11 @@ public static void main(String[] args) for (PatternHelper pattern : patternList) { - resultVerfication += an.checkForRecognitionAsDouble(pattern.getPatternList()); + resultVerification += an.checkForRecognitionAsDouble(pattern.getPatternList()); System.out.println("Recognized value of image " + pattern.getTagName() + " = " + an.checkForRecognitionAsString(pattern.getPatternList()) + " %"); } - System.out.println("Selftest value summed: " + (resultVerfication / patternList.size())); + System.out.println("Selftest value summed: " + (resultVerification / patternList.size())); an.setInternalParameter(im.getAverageMetric()); an.Save(networkFile.toString()); diff --git a/src/main/java/com/xceptance/neodymium/visual/ai/core/FloatRange.java b/src/main/java/com/xceptance/neodymium/visual/ai/core/FloatRange.java index ac06c38f5..137947f2b 100644 --- a/src/main/java/com/xceptance/neodymium/visual/ai/core/FloatRange.java +++ b/src/main/java/com/xceptance/neodymium/visual/ai/core/FloatRange.java @@ -46,7 +46,7 @@ public class FloatRange implements Serializable { /** - * Auto genreated serial number. + * Auto generated serial number. */ private static final long serialVersionUID = 1L; @@ -186,4 +186,4 @@ public String toString() * Maximum Value. */ private float max; -} \ No newline at end of file +} diff --git a/src/main/java/com/xceptance/neodymium/visual/ai/corner/Fast9.java b/src/main/java/com/xceptance/neodymium/visual/ai/corner/Fast9.java index 6760c6ef8..c82989208 100644 --- a/src/main/java/com/xceptance/neodymium/visual/ai/corner/Fast9.java +++ b/src/main/java/com/xceptance/neodymium/visual/ai/corner/Fast9.java @@ -140,7 +140,7 @@ public Fast9(int threshold) * @param threshold * Threshold. * @param suppress - * Supress. + * Suppress. */ public Fast9(int threshold, boolean suppress) { diff --git a/src/main/java/com/xceptance/neodymium/visual/ai/corner/FastCornersDetector.java b/src/main/java/com/xceptance/neodymium/visual/ai/corner/FastCornersDetector.java index 8c2478ce3..d76bde07d 100644 --- a/src/main/java/com/xceptance/neodymium/visual/ai/corner/FastCornersDetector.java +++ b/src/main/java/com/xceptance/neodymium/visual/ai/corner/FastCornersDetector.java @@ -152,7 +152,7 @@ public FastCornersDetector(Algorithm algorithm) * @param threshold * Threshold. * @param suppress - * Supress. + * Suppress. */ public FastCornersDetector(int threshold, boolean suppress) { @@ -166,7 +166,7 @@ public FastCornersDetector(int threshold, boolean suppress) * @param threshold * Threshold. * @param suppress - * Supress. + * Suppress. * @param algorithm * Algorithm. */ diff --git a/src/main/java/com/xceptance/neodymium/visual/ai/image/FastBitmap.java b/src/main/java/com/xceptance/neodymium/visual/ai/image/FastBitmap.java index 8770f7abc..5cc14761d 100644 --- a/src/main/java/com/xceptance/neodymium/visual/ai/image/FastBitmap.java +++ b/src/main/java/com/xceptance/neodymium/visual/ai/image/FastBitmap.java @@ -60,7 +60,7 @@ public class FastBitmap { /** - * Coodinate system. + * Coordinate system. */ public static enum CoordinateSystem { diff --git a/src/main/java/com/xceptance/neodymium/visual/ai/image/HistogramStatistics.java b/src/main/java/com/xceptance/neodymium/visual/ai/image/HistogramStatistics.java index 1465fd3f8..38c8e601d 100644 --- a/src/main/java/com/xceptance/neodymium/visual/ai/image/HistogramStatistics.java +++ b/src/main/java/com/xceptance/neodymium/visual/ai/image/HistogramStatistics.java @@ -96,7 +96,7 @@ public static double Entropy(int[] values) * Values. * @param percent * Values percentage around median. - * @return Returns the range which containes specifies percentage of values. + * @return Returns the range which contains specified percentage of values. */ public static IntRange GetRange(int[] values, double percent) { diff --git a/src/main/java/com/xceptance/neodymium/visual/ai/machine_learning/Network.java b/src/main/java/com/xceptance/neodymium/visual/ai/machine_learning/Network.java index cf90425ef..67cb6c780 100644 --- a/src/main/java/com/xceptance/neodymium/visual/ai/machine_learning/Network.java +++ b/src/main/java/com/xceptance/neodymium/visual/ai/machine_learning/Network.java @@ -114,7 +114,7 @@ public Layer getLayer() /** * Get Network's output vector. - * + * * @return Network's output vector. */ public ArrayList getOutput() @@ -218,11 +218,11 @@ public boolean onSelfTest(ArrayList validationList, Boolean flag) if (flag) { // compute the summed value for already seen pattern - double resultVerfication = 0.0; + double resultVerification = 0.0; for (PatternHelper element : internalList) { - resultVerfication += layer.computeSum(element.getPatternList()); + resultVerification += layer.computeSum(element.getPatternList()); } // compute the summed value for counter examples @@ -231,13 +231,13 @@ public boolean onSelfTest(ArrayList validationList, Boolean flag) { resultValidation += layer.computeSum(element.getPatternList()); } - System.out.println("Selftest value training dir: " + (resultVerfication / internalList.size())); + System.out.println("Selftest value training dir: " + (resultVerification / internalList.size())); System.out.println("Selftest value validation dir: " + (resultValidation / internalList.size())); int validationSize = (validationList.size() != 0 ? validationList.size() : 1); // check if the summed value for recognition is near the intended barrier // and check if the summed counter example value is under the intended barrier - if ((resultVerfication / internalList.size()) >= Constants.INTENDED_PERCENTAGE_MATCH && + if ((resultVerification / internalList.size()) >= Constants.INTENDED_PERCENTAGE_MATCH && resultValidation / validationSize < Constants.INTENDED_PERCENTAGE_MATCH) { // disable self test for further use diff --git a/src/main/java/com/xceptance/neodymium/visual/ai/machine_learning/Neuron.java b/src/main/java/com/xceptance/neodymium/visual/ai/machine_learning/Neuron.java index a2c21de19..4d746c152 100644 --- a/src/main/java/com/xceptance/neodymium/visual/ai/machine_learning/Neuron.java +++ b/src/main/java/com/xceptance/neodymium/visual/ai/machine_learning/Neuron.java @@ -86,7 +86,7 @@ public class Neuron implements Serializable /** * Get the range. * - * @return range FloatRagne value + * @return range FloatRange value */ public static FloatRange getRange() { diff --git a/src/main/java/com/xceptance/neodymium/visual/ai/pre_processing/PreProcessing.java b/src/main/java/com/xceptance/neodymium/visual/ai/pre_processing/PreProcessing.java index 662a70f46..d0c892672 100644 --- a/src/main/java/com/xceptance/neodymium/visual/ai/pre_processing/PreProcessing.java +++ b/src/main/java/com/xceptance/neodymium/visual/ai/pre_processing/PreProcessing.java @@ -158,7 +158,7 @@ private void findGroups(List edges, FastBitmap currentImage) } /** - * Auto generatef serial number. + * Auto generated serial number. */ private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/xceptance/neodymium/visual/ai/util/Helper.java b/src/main/java/com/xceptance/neodymium/visual/ai/util/Helper.java index 1aa57dc0f..5cf8a8298 100644 --- a/src/main/java/com/xceptance/neodymium/visual/ai/util/Helper.java +++ b/src/main/java/com/xceptance/neodymium/visual/ai/util/Helper.java @@ -202,7 +202,7 @@ public static void setImageParameter() * Transform a given image to an BufferedImkage with with exact same width and height as the original. * * @param img - * Image to transform into BuferedImage. + * Image to transform into BufferedImage. * @param imageType * Chosen int value of the target ImageType. * @return bi BufferedImage @@ -281,11 +281,11 @@ public static FastBitmap imageToFastImage(Image img, String tagName) */ public static BufferedImage ArrayToBufferedImage(double[][] array, int imageType) { - int xLenght = array.length; + int xLength = array.length; int yLength = array[0].length; - BufferedImage b = new BufferedImage(xLenght, yLength, imageType); + BufferedImage b = new BufferedImage(xLength, yLength, imageType); - for (int x = 0; x < xLenght; x++) + for (int x = 0; x < xLength; x++) { for (int y = 0; y < yLength; y++) { @@ -480,13 +480,13 @@ public static ArrayList loadAllImagesScaled_FastBitmap(String path) * * @param path * String full path name to the folder - * @param heigth + * @param height * int value for scaling * @param width * int value for scaling * @return ArrayList all found BufferedImages in the folder */ - public static ArrayList loadAllImagesScaled_BufferedImage(String path, int heigth, int width) + public static ArrayList loadAllImagesScaled_BufferedImage(String path, int height, int width) { ArrayList pictureList = new ArrayList<>(); File[] list = scanFolder(path); @@ -495,7 +495,7 @@ public static ArrayList loadAllImagesScaled_BufferedImage(String for (File element : list) { BufferedImage tempimage = loadImage(path + File.separator + element.getName()); - pictureList.add(imageToBufferedImageScaled(tempimage, BufferedImage.TYPE_INT_RGB, heigth, width)); + pictureList.add(imageToBufferedImageScaled(tempimage, BufferedImage.TYPE_INT_RGB, height, width)); } } return pictureList; diff --git a/src/test/java/com/xceptance/neodymium/module/statement/browser/multibrowser/configuration/BadProxyEnvironmentConfiguration.java b/src/test/java/com/xceptance/neodymium/module/statement/browser/multibrowser/configuration/BadProxyEnvironmentConfiguration.java index f60925ac3..1687436a0 100644 --- a/src/test/java/com/xceptance/neodymium/module/statement/browser/multibrowser/configuration/BadProxyEnvironmentConfiguration.java +++ b/src/test/java/com/xceptance/neodymium/module/statement/browser/multibrowser/configuration/BadProxyEnvironmentConfiguration.java @@ -20,7 +20,7 @@ public void testProxyWithoutHost() } catch (RuntimeException e) { - Assert.assertEquals("The proxy host configured for evironment: \"browserprofile.testEnvironment.badProxy\" needs to be set.", e.getMessage()); + Assert.assertEquals("The proxy host configured for environment: \"browserprofile.testEnvironment.badProxy\" needs to be set.", e.getMessage()); } } @@ -36,7 +36,7 @@ public void testProxyWithoutPort() } catch (RuntimeException e) { - Assert.assertEquals("The proxy port configured for evironment: \"browserprofile.testEnvironment.badProxy\" needs to be set.", e.getMessage()); + Assert.assertEquals("The proxy port configured for environment: \"browserprofile.testEnvironment.badProxy\" needs to be set.", e.getMessage()); } } @@ -53,7 +53,7 @@ public void testProxyWithCharacterPort() } catch (RuntimeException e) { - Assert.assertEquals("The proxy port configured for evironment: \"browserprofile.testEnvironment.badProxy\" needs to be an Integer.", + Assert.assertEquals("The proxy port configured for environment: \"browserprofile.testEnvironment.badProxy\" needs to be an Integer.", e.getMessage()); } } diff --git a/src/test/java/com/xceptance/neodymium/testclasses/context/ContextGetsCleared.java b/src/test/java/com/xceptance/neodymium/testclasses/context/ContextGetsCleared.java index 5b268a65f..4d92b311f 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/context/ContextGetsCleared.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/context/ContextGetsCleared.java @@ -27,7 +27,7 @@ public void test1() throws Exception @SuppressDataSets public void test2() throws Exception { - // supressing data sets makes sure we dont + // suppressing data sets makes sure we don't Assert.assertNull(Neodymium.dataValue("key1")); } } diff --git a/src/test/java/com/xceptance/neodymium/testclasses/context/OverrideNeodymiumConfiguration.java b/src/test/java/com/xceptance/neodymium/testclasses/context/OverrideNeodymiumConfiguration.java index f843cf892..a41c6747c 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/context/OverrideNeodymiumConfiguration.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/context/OverrideNeodymiumConfiguration.java @@ -14,13 +14,13 @@ public class OverrideNeodymiumConfiguration { @Test - public void testStandarConfigurationStillAvailable() throws Exception + public void testStandardConfigurationStillAvailable() throws Exception { Assert.assertEquals("/some/opera/path/just/for/test/purpose", Neodymium.configuration().getOperaDriverPath()); } @Test - public void testConfigurationContainsOveriddenParts() throws Exception + public void testConfigurationContainsOverriddenParts() throws Exception { Assert.assertEquals("/some/phantomjs/path/just/for/test/newPurpose", Neodymium.configuration().getPhantomJsDriverPath()); } diff --git a/src/test/java/com/xceptance/neodymium/testclasses/context/cucumbercontextclear/CucumberContextGetsCleared.java b/src/test/java/com/xceptance/neodymium/testclasses/context/cucumbercontextclear/CucumberContextGetsCleared.java index aadbcf492..18e249455 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/context/cucumbercontextclear/CucumberContextGetsCleared.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/context/cucumbercontextclear/CucumberContextGetsCleared.java @@ -4,7 +4,7 @@ import com.xceptance.neodymium.NeodymiumCucumberRunner; -import cucumber.api.CucumberOptions; +import io.cucumber.junit.CucumberOptions; @RunWith(NeodymiumCucumberRunner.class) @CucumberOptions(features = "src/test/resources/com/xceptance/neodymium/testclasses/context/cucumbercontextclear", glue = "com/xceptance/neodymium/testclasses/context/cucumbercontextclear") diff --git a/src/test/java/com/xceptance/neodymium/testclasses/context/cucumbercontextclear/CucumberContextSteps.java b/src/test/java/com/xceptance/neodymium/testclasses/context/cucumbercontextclear/CucumberContextSteps.java index 4f3021df5..7adb338fc 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/context/cucumbercontextclear/CucumberContextSteps.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/context/cucumbercontextclear/CucumberContextSteps.java @@ -6,10 +6,10 @@ import com.xceptance.neodymium.util.NeodymiumConfiguration; import com.xceptance.neodymium.util.WebDriverUtils; -import cucumber.api.Scenario; -import cucumber.api.java.After; -import cucumber.api.java.Before; -import cucumber.api.java.en.Given; +import io.cucumber.core.api.Scenario; +import io.cucumber.java.After; +import io.cucumber.java.Before; +import io.cucumber.java.en.Given; public class CucumberContextSteps { diff --git a/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTag.java b/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTag.java index f0b1c86fb..491b27bfa 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTag.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTag.java @@ -4,7 +4,7 @@ import com.xceptance.neodymium.NeodymiumCucumberRunner; -import cucumber.api.CucumberOptions; +import io.cucumber.junit.CucumberOptions; @RunWith(NeodymiumCucumberRunner.class) @CucumberOptions(features = "src/test/resources/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTag.feature", glue = "com/xceptance/neodymium/testclasses/cucumber") diff --git a/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTagFail.java b/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTagFail.java index 4787da4ad..85498a397 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTagFail.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTagFail.java @@ -4,11 +4,10 @@ import com.xceptance.neodymium.NeodymiumCucumberRunner; -import cucumber.api.CucumberOptions; +import io.cucumber.junit.CucumberOptions; @RunWith(NeodymiumCucumberRunner.class) -@CucumberOptions(features = "src/test/resources/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTagFail.feature", - glue = "com/xceptance/neodymium/testclasses/cucumber", plugin = "null_summary") +@CucumberOptions(features = "src/test/resources/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTagFail.feature", glue = "com/xceptance/neodymium/testclasses/cucumber", plugin = "null_summary") public class CucumberSetBrowserViaTagFail { } diff --git a/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTestData.java b/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTestData.java index 60392326e..d166f3e53 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTestData.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTestData.java @@ -4,7 +4,7 @@ import com.xceptance.neodymium.NeodymiumCucumberRunner; -import cucumber.api.CucumberOptions; +import io.cucumber.junit.CucumberOptions; @RunWith(NeodymiumCucumberRunner.class) @CucumberOptions(features = "src/test/resources/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTestData.feature", glue = "com/xceptance/neodymium/testclasses/cucumber") diff --git a/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTestDataFail.java b/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTestDataFail.java index f5fd4d75a..399fc1a8a 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTestDataFail.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTestDataFail.java @@ -4,11 +4,10 @@ import com.xceptance.neodymium.NeodymiumCucumberRunner; -import cucumber.api.CucumberOptions; +import io.cucumber.junit.CucumberOptions; @RunWith(NeodymiumCucumberRunner.class) -@CucumberOptions(features = "src/test/resources/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTestDataFail.feature", - glue = "com/xceptance/neodymium/testclasses/cucumber", plugin = "null_summary") +@CucumberOptions(features = "src/test/resources/com/xceptance/neodymium/testclasses/cucumber/CucumberSetBrowserViaTestDataFail.feature", glue = "com/xceptance/neodymium/testclasses/cucumber", plugin = "null_summary") public class CucumberSetBrowserViaTestDataFail { } diff --git a/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSupport.java b/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSupport.java index ba1b10562..775c3462a 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSupport.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberSupport.java @@ -7,11 +7,11 @@ import com.xceptance.neodymium.util.Neodymium; import com.xceptance.neodymium.util.WebDriverUtils; -import cucumber.api.Scenario; -import cucumber.api.java.After; -import cucumber.api.java.Before; -import cucumber.api.java.en.Given; -import cucumber.api.java.en.Then; +import io.cucumber.core.api.Scenario; +import io.cucumber.java.After; +import io.cucumber.java.Before; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; public class CucumberSupport { diff --git a/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberValidateAllureSelenideListenerIsActive.java b/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberValidateAllureSelenideListenerIsActive.java index bf5e12559..304236fd8 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberValidateAllureSelenideListenerIsActive.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/cucumber/CucumberValidateAllureSelenideListenerIsActive.java @@ -4,7 +4,7 @@ import com.xceptance.neodymium.NeodymiumCucumberRunner; -import cucumber.api.CucumberOptions; +import io.cucumber.junit.CucumberOptions; @RunWith(NeodymiumCucumberRunner.class) @CucumberOptions(features = "src/test/resources/com/xceptance/neodymium/testclasses/cucumber/CucumberValidateAllureSelenideListenerIsActive.feature", glue = "com/xceptance/neodymium/testclasses/cucumber", plugin = "null_summary") diff --git a/src/test/java/com/xceptance/neodymium/testclasses/data/file/json/CanReadDataSetJson.java b/src/test/java/com/xceptance/neodymium/testclasses/data/file/json/CanReadDataSetJson.java new file mode 100644 index 000000000..cfbc39d10 --- /dev/null +++ b/src/test/java/com/xceptance/neodymium/testclasses/data/file/json/CanReadDataSetJson.java @@ -0,0 +1,25 @@ +package com.xceptance.neodymium.testclasses.data.file.json; + +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.xceptance.neodymium.NeodymiumRunner; +import com.xceptance.neodymium.module.statement.testdata.DataFile; +import com.xceptance.neodymium.util.Neodymium; + +@RunWith(NeodymiumRunner.class) +@DataFile("com/xceptance/neodymium/testclasses/data/set/json/CanReadDataSetJson.json") +public class CanReadDataSetJson +{ + @Test + public void test() + { + Map data = Neodymium.getData(); + Assert.assertEquals(2, data.size()); + Assert.assertEquals("Json Value1", data.get("testParam1")); + Assert.assertEquals("Json Value2", data.get("testParam2")); + } +} diff --git a/src/test/java/com/xceptance/neodymium/testclasses/data/file/xml/CanNotReadDataSetXml.java b/src/test/java/com/xceptance/neodymium/testclasses/data/file/xml/CanNotReadDataSetXml.java new file mode 100644 index 000000000..a2f08d384 --- /dev/null +++ b/src/test/java/com/xceptance/neodymium/testclasses/data/file/xml/CanNotReadDataSetXml.java @@ -0,0 +1,19 @@ +package com.xceptance.neodymium.testclasses.data.file.xml; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.xceptance.neodymium.NeodymiumRunner; +import com.xceptance.neodymium.module.statement.testdata.DataFile; +import com.xceptance.neodymium.util.Neodymium; + +@RunWith(NeodymiumRunner.class) +@DataFile("can/not/read/data/set/xml/DoesNotExist.xml") +public class CanNotReadDataSetXml +{ + @Test() + public void test() + { + Neodymium.getData(); + } +} diff --git a/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.java b/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.java index 0f3b2cb98..203be4480 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.java @@ -252,13 +252,13 @@ private void expectException(Runnable function, Class expec caughtException = e; } - String caughtExeptionName = "no exception!"; + String caughtExceptionName = "no exception!"; if (caughtException != null) - caughtExeptionName = caughtException.getClass().toString(); + caughtExceptionName = caughtException.getClass().toString(); if (caughtException == null || caughtException.getClass() != expectedException) { - Assert.fail(MessageFormat.format("Expected exception {0} but caught {1}", expectedException.toString(), caughtExeptionName)); + Assert.fail(MessageFormat.format("Expected exception {0} but caught {1}", expectedException.toString(), caughtExceptionName)); } } diff --git a/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.java b/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.java index fa2ddc17f..77f3b6d7f 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.java @@ -252,13 +252,13 @@ private void expectException(Runnable function, Class expec caughtException = e; } - String caughtExeptionName = "no exception!"; + String caughtExceptionName = "no exception!"; if (caughtException != null) - caughtExeptionName = caughtException.getClass().toString(); + caughtExceptionName = caughtException.getClass().toString(); if (caughtException == null || caughtException.getClass() != expectedException) { - Assert.fail(MessageFormat.format("Expected exception {0} but caught {1}", expectedException.toString(), caughtExeptionName)); + Assert.fail(MessageFormat.format("Expected exception {0} but caught {1}", expectedException.toString(), caughtExceptionName)); } } diff --git a/src/test/java/com/xceptance/neodymium/testclasses/multibrowser/EnvironmentAndBrowserConfiguration.java b/src/test/java/com/xceptance/neodymium/testclasses/multibrowser/EnvironmentAndBrowserConfiguration.java index 6072d4747..6a9e41a03 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/multibrowser/EnvironmentAndBrowserConfiguration.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/multibrowser/EnvironmentAndBrowserConfiguration.java @@ -11,7 +11,7 @@ public class EnvironmentAndBrowserConfiguration { @Test - public void testEnvionmentApi() + public void testEnvironmentApi() { TestEnvironment environment = MultibrowserConfiguration.getInstance().getTestEnvironment("unittest"); diff --git a/src/test/java/com/xceptance/neodymium/testclasses/parameter/ParameterFieldButNoGenerator.java b/src/test/java/com/xceptance/neodymium/testclasses/parameter/ParameterFieldButNoGenerator.java index c1add3b43..bdd2be6d0 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/parameter/ParameterFieldButNoGenerator.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/parameter/ParameterFieldButNoGenerator.java @@ -11,7 +11,7 @@ public class ParameterFieldButNoGenerator { /** - * Neodymium emulates JUnit's parmeterized runner with a few differences. Running this test with JUnits parameterized + * Neodymium emulates JUnit's parameterized runner with a few differences. Running this test with JUnits parameterized * runner will fail since this runner expects an generator function. Neodymium on the other site handles parameters as * optional. So if there is no generator function but parameterized members it just will ignore these annotation and run * only the test methods. So the only thing to test in absence of a generator is that the members don't change their diff --git a/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateClearReuseWebDriverCache.java b/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateClearReuseWebDriverCache.java new file mode 100644 index 000000000..bf16bfcdd --- /dev/null +++ b/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateClearReuseWebDriverCache.java @@ -0,0 +1,93 @@ +package com.xceptance.neodymium.testclasses.webDriver; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import org.aeonbits.owner.ConfigFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; + +import com.xceptance.neodymium.NeodymiumRunner; +import com.xceptance.neodymium.module.statement.browser.multibrowser.Browser; +import com.xceptance.neodymium.module.statement.browser.multibrowser.WebDriverCache; +import com.xceptance.neodymium.tests.NeodymiumTest; +import com.xceptance.neodymium.tests.NeodymiumWebDriverTest; +import com.xceptance.neodymium.util.Neodymium; + +@RunWith(NeodymiumRunner.class) +public class ValidateClearReuseWebDriverCache +{ + private static WebDriver webDriver1; + + private static File tempConfigFile; + + @BeforeClass + public static void beforeClass() + { + // set up a temporary neodymium.properties + final String fileLocation = "config/temp-ValidateClearReuseWebDriverCache-neodymium.properties"; + tempConfigFile = new File("./" + fileLocation); + Map properties = new HashMap<>(); + properties.put("neodymium.webDriver.reuseDriver", "true"); + NeodymiumTest.writeMapToPropertiesFile(properties, tempConfigFile); + ConfigFactory.setProperty(Neodymium.TEMPORARY_CONFIG_FILE_PROPERTY_NAME, "file:" + fileLocation); + + Assert.assertNull(webDriver1); + Assert.assertNull(Neodymium.getDriver()); + } + + @Before + public void before() + { + if (webDriver1 == null) + { + webDriver1 = Neodymium.getDriver(); + } + else + { + Assert.assertNotNull(Neodymium.getDriver()); + } + Assert.assertNotNull(webDriver1); + } + + @Test + @Browser("Chrome_headless") + public void test1() + { + Assert.assertEquals(webDriver1, Neodymium.getDriver()); + Assert.assertNotNull(webDriver1); + } + + @Test + @Browser("Chrome_headless") + public void test2() + { + Assert.assertEquals(webDriver1, Neodymium.getDriver()); + Assert.assertNotNull(webDriver1); + } + + @After + public void after() + { + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver1); + } + + @AfterClass + public static void afterClass() + { + Assert.assertEquals(1, WebDriverCache.instance.getAllWebdriver().size()); + WebDriverCache.quitCachedBrowsers(); + Assert.assertEquals(0, WebDriverCache.instance.getAllWebdriver().size()); + + NeodymiumWebDriverTest.assertWebDriverClosed(webDriver1); + + NeodymiumTest.deleteTempFile(tempConfigFile); + } +} diff --git a/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateKeepWebDriverOpen.java b/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateKeepWebDriverOpen.java new file mode 100644 index 000000000..4770072e6 --- /dev/null +++ b/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateKeepWebDriverOpen.java @@ -0,0 +1,100 @@ +package com.xceptance.neodymium.testclasses.webDriver; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import org.aeonbits.owner.ConfigFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; + +import com.xceptance.neodymium.NeodymiumRunner; +import com.xceptance.neodymium.module.statement.browser.multibrowser.Browser; +import com.xceptance.neodymium.tests.NeodymiumTest; +import com.xceptance.neodymium.tests.NeodymiumWebDriverTest; +import com.xceptance.neodymium.util.Neodymium; + +@RunWith(NeodymiumRunner.class) +public class ValidateKeepWebDriverOpen +{ + private static WebDriver webDriver1; + + private static WebDriver webDriver2; + + private static File tempConfigFile; + + @BeforeClass + public static void beforeClass() + { + // set up a temporary neodymium.properties + final String fileLocation = "config/temp-ValidateReuseWebDriver-neodymium.properties"; + tempConfigFile = new File("./" + fileLocation); + Map properties = new HashMap<>(); + properties.put("neodymium.webDriver.keepBrowserOpen", "true"); + NeodymiumTest.writeMapToPropertiesFile(properties, tempConfigFile); + ConfigFactory.setProperty(Neodymium.TEMPORARY_CONFIG_FILE_PROPERTY_NAME, "file:" + fileLocation); + + Assert.assertNull(webDriver1); + Assert.assertNull(Neodymium.getDriver()); + } + + @Before + public void before() + { + if (webDriver1 == null) + { + webDriver1 = Neodymium.getDriver(); + } + else if (webDriver2 == null) + { + webDriver2 = Neodymium.getDriver(); + } + else + { + Assert.assertNotNull(Neodymium.getDriver()); + } + Assert.assertNotNull(webDriver1); + } + + @Test + @Browser("Chrome_1024x768") + public void test1() + { + Assert.assertEquals(webDriver1, Neodymium.getDriver()); + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver1); + } + + @Test + @Browser("Chrome_1024x768") + public void test2() + { + Assert.assertNotEquals(webDriver1, webDriver2); + Assert.assertEquals(webDriver2, Neodymium.getDriver()); + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver1); + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver2); + } + + @After + public void after() + { + NeodymiumWebDriverTest.assertWebDriverAlive(Neodymium.getDriver()); + } + + @AfterClass + public static void afterClass() + { + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver1); + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver2); + webDriver1.quit(); + webDriver2.quit(); + NeodymiumWebDriverTest.assertWebDriverClosed(webDriver1); + NeodymiumWebDriverTest.assertWebDriverClosed(webDriver2); + NeodymiumTest.deleteTempFile(tempConfigFile); + } +} diff --git a/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateKeepWebDriverOpenOnFailure.java b/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateKeepWebDriverOpenOnFailure.java new file mode 100644 index 000000000..4ecec8d7f --- /dev/null +++ b/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateKeepWebDriverOpenOnFailure.java @@ -0,0 +1,114 @@ +package com.xceptance.neodymium.testclasses.webDriver; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import org.aeonbits.owner.ConfigFactory; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; + +import com.codeborne.selenide.Condition; +import com.codeborne.selenide.Selenide; +import com.xceptance.neodymium.NeodymiumRunner; +import com.xceptance.neodymium.module.statement.browser.multibrowser.Browser; +import com.xceptance.neodymium.tests.NeodymiumTest; +import com.xceptance.neodymium.tests.NeodymiumWebDriverTest; +import com.xceptance.neodymium.util.Neodymium; + +@RunWith(NeodymiumRunner.class) +@Browser("Chrome_1024x768") +public class ValidateKeepWebDriverOpenOnFailure +{ + private static WebDriver webDriver1; + + private static WebDriver webDriver2; + + private static WebDriver webDriver3; + + private static File tempConfigFile; + + @BeforeClass + public static void beforeClass() + { + // set up a temporary neodymium.properties + final String fileLocation = "config/temp-ValidateKeepWebDriverOpenOnFailure-neodymium.properties"; + tempConfigFile = new File("./" + fileLocation); + Map properties = new HashMap<>(); + properties.put("neodymium.webDriver.keepBrowserOpenOnFailure", "true"); + NeodymiumTest.writeMapToPropertiesFile(properties, tempConfigFile); + ConfigFactory.setProperty(Neodymium.TEMPORARY_CONFIG_FILE_PROPERTY_NAME, "file:" + fileLocation); + + Assert.assertNull(webDriver1); + Assert.assertNull(Neodymium.getDriver()); + } + + @Before + public void before() + { + if (webDriver1 == null) + { + webDriver1 = Neodymium.getDriver(); + } + else if (webDriver2 == null) + { + webDriver2 = Neodymium.getDriver(); + } + else if (webDriver3 == null) + { + webDriver3 = Neodymium.getDriver(); + } + else + { + Assert.assertNotNull(Neodymium.getDriver()); + } + Assert.assertNotNull(webDriver1); + } + + @Test + public void test1() + { + Assert.assertEquals(webDriver1, Neodymium.getDriver()); + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver1); + } + + @Test + public void test2() + { + Assert.assertNotEquals(webDriver1, webDriver2); + Assert.assertEquals(webDriver2, Neodymium.getDriver()); + NeodymiumWebDriverTest.assertWebDriverClosed(webDriver1); + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver2); + + Selenide.$("#cantFindMe").should(Condition.exist); + } + + @Test + public void test3() + { + Assert.assertNotEquals(webDriver1, webDriver2); + Assert.assertNotEquals(webDriver2, webDriver3); + Assert.assertNotEquals(webDriver1, webDriver3); + Assert.assertEquals(webDriver3, Neodymium.getDriver()); + NeodymiumWebDriverTest.assertWebDriverClosed(webDriver1); + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver2); + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver3); + + } + + @AfterClass + public static void afterClass() + { + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver2); + webDriver2.quit(); + NeodymiumWebDriverTest.assertWebDriverClosed(webDriver1); + NeodymiumWebDriverTest.assertWebDriverClosed(webDriver2); + NeodymiumWebDriverTest.assertWebDriverClosed(webDriver3); + NeodymiumTest.deleteTempFile(tempConfigFile); + } +} diff --git a/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidatePreventReuseWebDriver.java b/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidatePreventReuseWebDriver.java new file mode 100644 index 000000000..217b0e6db --- /dev/null +++ b/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidatePreventReuseWebDriver.java @@ -0,0 +1,129 @@ +package com.xceptance.neodymium.testclasses.webDriver; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import org.aeonbits.owner.ConfigFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; + +import com.xceptance.neodymium.NeodymiumRunner; +import com.xceptance.neodymium.module.statement.browser.multibrowser.Browser; +import com.xceptance.neodymium.module.statement.browser.multibrowser.WebDriverCache; +import com.xceptance.neodymium.tests.NeodymiumTest; +import com.xceptance.neodymium.tests.NeodymiumWebDriverTest; +import com.xceptance.neodymium.util.Neodymium; +import com.xceptance.neodymium.util.WebDriverUtils; + +@RunWith(NeodymiumRunner.class) +public class ValidatePreventReuseWebDriver +{ + private static WebDriver webDriver1; + + private static WebDriver webDriver2; + + private static WebDriver webDriver3; + + private static File tempConfigFile; + + @BeforeClass + public static void beforeClass() + { + // set up a temporary neodymium.properties + final String fileLocation = "config/temp-ValidateReuseWebDriver-neodymium.properties"; + tempConfigFile = new File("./" + fileLocation); + Map properties = new HashMap<>(); + properties.put("neodymium.webDriver.reuseDriver", "true"); + NeodymiumTest.writeMapToPropertiesFile(properties, tempConfigFile); + ConfigFactory.setProperty(Neodymium.TEMPORARY_CONFIG_FILE_PROPERTY_NAME, "file:" + fileLocation); + + Assert.assertNull(webDriver1); + Assert.assertNull(Neodymium.getDriver()); + } + + @Before + public void before() + { + if (webDriver1 == null) + { + webDriver1 = Neodymium.getDriver(); + } + else if (webDriver2 == null) + { + webDriver2 = Neodymium.getDriver(); + } + else if (webDriver3 == null) + { + webDriver3 = Neodymium.getDriver(); + } + else + { + Assert.assertNotNull(Neodymium.getDriver()); + } + Assert.assertNotNull(webDriver1); + } + + @Test + @Browser("Chrome_headless") + public void test1() + { + Assert.assertEquals(webDriver1, Neodymium.getDriver()); + Assert.assertNotNull(webDriver1); + Assert.assertNotEquals(webDriver1, webDriver2); + + Assert.assertEquals(0, WebDriverCache.instance.getAllWebdriver().size()); + } + + @Test + @Browser("Chrome_headless") + public void test2() + { + Assert.assertEquals(webDriver2, Neodymium.getDriver()); + Assert.assertNotNull(webDriver1); + Assert.assertNotNull(webDriver2); + Assert.assertNotEquals(webDriver1, webDriver2); + + Assert.assertEquals(0, WebDriverCache.instance.getAllWebdriver().size()); + } + + @Test + @Browser("Chrome_headless") + public void test3() + { + Assert.assertEquals(webDriver3, Neodymium.getDriver()); + Assert.assertNotNull(webDriver1); + Assert.assertNotNull(webDriver2); + Assert.assertNotNull(webDriver3); + Assert.assertNotEquals(webDriver1, webDriver2); + Assert.assertEquals(webDriver2, webDriver3); + + Assert.assertEquals(0, WebDriverCache.instance.getAllWebdriver().size()); + } + + @After + public void after() + { + if (webDriver2 == null) + { + WebDriverUtils.preventReuseAndTearDown(); + } + } + + @AfterClass + public static void afterClass() + { + NeodymiumWebDriverTest.assertWebDriverClosed(webDriver1); + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver2); + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver3); + Assert.assertEquals(1, WebDriverCache.instance.getAllWebdriver().size()); + + NeodymiumTest.deleteTempFile(tempConfigFile); + } +} diff --git a/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateReuseWebDriver.java b/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateReuseWebDriver.java new file mode 100644 index 000000000..fedc6fcd6 --- /dev/null +++ b/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateReuseWebDriver.java @@ -0,0 +1,86 @@ +package com.xceptance.neodymium.testclasses.webDriver; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import org.aeonbits.owner.ConfigFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; + +import com.xceptance.neodymium.NeodymiumRunner; +import com.xceptance.neodymium.module.statement.browser.multibrowser.Browser; +import com.xceptance.neodymium.tests.NeodymiumTest; +import com.xceptance.neodymium.tests.NeodymiumWebDriverTest; +import com.xceptance.neodymium.util.Neodymium; + +@RunWith(NeodymiumRunner.class) +public class ValidateReuseWebDriver +{ + private static WebDriver webDriver1; + + private static File tempConfigFile; + + @BeforeClass + public static void beforeClass() + { + // set up a temporary neodymium.properties + final String fileLocation = "config/temp-ValidateReuseWebDriver-neodymium.properties"; + tempConfigFile = new File("./" + fileLocation); + Map properties = new HashMap<>(); + properties.put("neodymium.webDriver.reuseDriver", "true"); + NeodymiumTest.writeMapToPropertiesFile(properties, tempConfigFile); + ConfigFactory.setProperty(Neodymium.TEMPORARY_CONFIG_FILE_PROPERTY_NAME, "file:" + fileLocation); + + Assert.assertNull(webDriver1); + Assert.assertNull(Neodymium.getDriver()); + } + + @Before + public void before() + { + if (webDriver1 == null) + { + webDriver1 = Neodymium.getDriver(); + } + else + { + Assert.assertNotNull(Neodymium.getDriver()); + } + Assert.assertNotNull(webDriver1); + } + + @Test + @Browser("Chrome_headless") + public void test1() + { + Assert.assertEquals(webDriver1, Neodymium.getDriver()); + Assert.assertNotNull(webDriver1); + } + + @Test + @Browser("Chrome_headless") + public void test2() + { + Assert.assertEquals(webDriver1, Neodymium.getDriver()); + Assert.assertNotNull(webDriver1); + } + + @After + public void after() + { + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver1); + } + + @AfterClass + public static void afterClass() + { + NeodymiumTest.deleteTempFile(tempConfigFile); + } +} diff --git a/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateWebDriverClosed.java b/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateWebDriverClosed.java new file mode 100644 index 000000000..ed01f78a4 --- /dev/null +++ b/src/test/java/com/xceptance/neodymium/testclasses/webDriver/ValidateWebDriverClosed.java @@ -0,0 +1,79 @@ +package com.xceptance.neodymium.testclasses.webDriver; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; + +import com.xceptance.neodymium.NeodymiumRunner; +import com.xceptance.neodymium.module.statement.browser.multibrowser.Browser; +import com.xceptance.neodymium.tests.NeodymiumWebDriverTest; +import com.xceptance.neodymium.util.Neodymium; + +@RunWith(NeodymiumRunner.class) +public class ValidateWebDriverClosed +{ + private static WebDriver webDriver1; + + private static WebDriver webDriver2; + + @BeforeClass + public static void beforeClass() + { + Assert.assertNull(webDriver1); + Assert.assertNull(Neodymium.getDriver()); + } + + @Before + public void before() + { + if (webDriver1 == null) + { + webDriver1 = Neodymium.getDriver(); + } + else if (webDriver2 == null) + { + webDriver2 = Neodymium.getDriver(); + } + else + { + Assert.assertNotNull(Neodymium.getDriver()); + } + Assert.assertNotNull(webDriver1); + } + + @Test + @Browser("Chrome_headless") + public void test1() + { + Assert.assertEquals(webDriver1, Neodymium.getDriver()); + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver1); + } + + @Test + @Browser("Chrome_headless") + public void test2() + { + Assert.assertNotEquals(webDriver1, Neodymium.getDriver()); + Assert.assertEquals(webDriver2, Neodymium.getDriver()); + NeodymiumWebDriverTest.assertWebDriverClosed(webDriver1); + NeodymiumWebDriverTest.assertWebDriverAlive(webDriver2); + } + + @After + public void after() + { + Assert.assertNotNull(Neodymium.getDriver()); + } + + @AfterClass + public static void afterClass() + { + NeodymiumWebDriverTest.assertWebDriverClosed(webDriver1); + NeodymiumWebDriverTest.assertWebDriverClosed(webDriver2); + } +} diff --git a/src/test/java/com/xceptance/neodymium/tests/BrowserStatementConfigurationTestError.java b/src/test/java/com/xceptance/neodymium/tests/BrowserStatementConfigurationTestError.java new file mode 100644 index 000000000..9d3685445 --- /dev/null +++ b/src/test/java/com/xceptance/neodymium/tests/BrowserStatementConfigurationTestError.java @@ -0,0 +1,80 @@ +package com.xceptance.neodymium.tests; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; + +import com.xceptance.neodymium.module.statement.browser.multibrowser.configuration.MultibrowserConfiguration; + +public class BrowserStatementConfigurationTestError extends NeodymiumTest +{ + + File tempConfigFile; + + @After + public void after() throws IOException + { + deleteTempFile(tempConfigFile); + } + + @Test + public void testParseErrorIdleTimeout() + { + String unparsableInt = "ABC122"; + try + { + Map properties = new HashMap<>(); + properties.put("browserprofile.testEnvironmentFlags.name", "Test Environment Browser"); + properties.put("browserprofile.testEnvironmentFlags.browser", "chrome"); + properties.put("browserprofile.testEnvironmentFlags.idleTimeout", unparsableInt); + + tempConfigFile = File.createTempFile("browser", "", new File("./config/")); + tempFiles.add(tempConfigFile); + writeMapToPropertiesFile(properties, tempConfigFile); + + MultibrowserConfiguration.clearAllInstances(); + MultibrowserConfiguration.getInstance(tempConfigFile.getPath()); + + Assert.assertTrue("This point will not reached if the awaited RuntimeException is thrown.", false); + } + catch (Exception e) + { + Assert.assertTrue(e instanceof RuntimeException); + Assert.assertEquals("idleTimeout configured within the browser profiles couldn't be parsed into an int value. Given value: \"" + + unparsableInt + "\"", e.getMessage()); + } + } + + @Test + public void testParseErrorMaxiumumDuration() + { + String unparsableInt = "ABC122"; + try + { + Map properties = new HashMap<>(); + properties.put("browserprofile.testEnvironmentFlags.name", "Test Environment Browser"); + properties.put("browserprofile.testEnvironmentFlags.browser", "chrome"); + properties.put("browserprofile.testEnvironmentFlags.maxDuration", unparsableInt); + + tempConfigFile = File.createTempFile("browser", "", new File("./config/")); + tempFiles.add(tempConfigFile); + writeMapToPropertiesFile(properties, tempConfigFile); + + MultibrowserConfiguration.clearAllInstances(); + MultibrowserConfiguration.getInstance(tempConfigFile.getPath()); + + Assert.assertTrue("This point will not reached if the awaited RuntimeException is thrown.", false); + } + catch (Exception e) + { + Assert.assertTrue(e instanceof RuntimeException); + Assert.assertEquals("maxDuration configured within the browser profiles couldn't be parsed into an int value. Given value: \"" + + unparsableInt + "\"", e.getMessage()); + } + } +} diff --git a/src/test/java/com/xceptance/neodymium/tests/BrowserStatementTest.java b/src/test/java/com/xceptance/neodymium/tests/BrowserStatementTest.java index 57db95597..0c04f8676 100644 --- a/src/test/java/com/xceptance/neodymium/tests/BrowserStatementTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/BrowserStatementTest.java @@ -13,6 +13,7 @@ import org.junit.runner.JUnitCore; import org.junit.runner.Result; import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.Platform; import org.openqa.selenium.remote.CapabilityType; import com.xceptance.neodymium.module.statement.browser.multibrowser.configuration.BrowserConfiguration; @@ -55,6 +56,18 @@ public static void beforeClass() throws IOException properties.put("browserprofile.multiChrome.browser", "chrome"); properties.put("browserprofile.multiChrome.arguments", " -crash-test ; -window-position=0,0 ;-window-size=1024,768 "); + properties.put("browserprofile.testEnvironmentFlags.name", "Test Environment Browser"); + properties.put("browserprofile.testEnvironmentFlags.browser", "chrome"); + properties.put("browserprofile.testEnvironmentFlags.idleTimeout", "1234"); + properties.put("browserprofile.testEnvironmentFlags.maxDuration", "5678"); + properties.put("browserprofile.testEnvironmentFlags.seleniumVersion", "3.1234"); + properties.put("browserprofile.testEnvironmentFlags.screenResolution", "800x600"); + properties.put("browserprofile.testEnvironmentFlags.platform", "Windows 7"); + properties.put("browserprofile.testEnvironmentFlags.platformName", "Windows 10"); + properties.put("browserprofile.testEnvironmentFlags.deviceName", "MyDevice"); + properties.put("browserprofile.testEnvironmentFlags.deviceOrientation", "portrait"); + properties.put("browserprofile.testEnvironmentFlags.orientation", "landscape"); + File tempConfigFile = File.createTempFile("browser", "", new File("./config/")); tempFiles.add(tempConfigFile); writeMapToPropertiesFile(properties, tempConfigFile); @@ -176,9 +189,10 @@ public void testMultibrowserConfiguration() throws Throwable checkMultiChrome(browserProfiles.get("multiChrome")); checkFirefox(browserProfiles.get("firefox")); checkMultiFirefox(browserProfiles.get("multiFirefox")); + checkTestEnvironment(browserProfiles.get("testEnvironmentFlags")); } - public void checkChrome(BrowserConfiguration config) + private void checkChrome(BrowserConfiguration config) { Assert.assertNotNull(config); Assert.assertEquals("chrome", config.getConfigTag()); @@ -192,7 +206,7 @@ public void checkChrome(BrowserConfiguration config) Assert.assertEquals(list, config.getArguments()); } - public void checkMultiChrome(BrowserConfiguration config) + private void checkMultiChrome(BrowserConfiguration config) { Assert.assertNotNull(config); Assert.assertEquals("multiChrome", config.getConfigTag()); @@ -206,7 +220,7 @@ public void checkMultiChrome(BrowserConfiguration config) Assert.assertEquals(list, config.getArguments()); } - public void checkFirefox(BrowserConfiguration config) + private void checkFirefox(BrowserConfiguration config) { Assert.assertNotNull(config); Assert.assertEquals("firefox", config.getConfigTag()); @@ -219,7 +233,7 @@ public void checkFirefox(BrowserConfiguration config) Assert.assertEquals(list, config.getArguments()); } - public void checkMultiFirefox(BrowserConfiguration config) + private void checkMultiFirefox(BrowserConfiguration config) { Assert.assertNotNull(config); Assert.assertEquals("multiFirefox", config.getConfigTag()); @@ -232,4 +246,26 @@ public void checkMultiFirefox(BrowserConfiguration config) list.add("-height=768"); Assert.assertEquals(list, config.getArguments()); } + + private void checkTestEnvironment(BrowserConfiguration config) + { + Assert.assertNotNull(config); + Assert.assertEquals("testEnvironmentFlags", config.getConfigTag()); + Assert.assertEquals("Test Environment Browser", config.getName()); + MutableCapabilities testCapabilities = config.getCapabilities(); + Assert.assertEquals("chrome", testCapabilities.getBrowserName()); + Assert.assertEquals(1234, testCapabilities.getCapability("idleTimeout")); + Assert.assertEquals(1234, testCapabilities.getCapability("idletimeout")); + Assert.assertEquals(5678, testCapabilities.getCapability("maxDuration")); + Assert.assertEquals(5678, testCapabilities.getCapability("maxduration")); + Assert.assertEquals("3.1234", testCapabilities.getCapability("seleniumVersion")); + Assert.assertEquals("3.1234", testCapabilities.getCapability("selenium-version")); + Assert.assertEquals("800x600", testCapabilities.getCapability("screenResolution")); + Assert.assertEquals("800x600", testCapabilities.getCapability("screen-resolution")); + Assert.assertEquals(Platform.VISTA, testCapabilities.getCapability("platform")); + Assert.assertEquals("Windows 10", testCapabilities.getCapability("platformName")); + Assert.assertEquals("MyDevice", testCapabilities.getCapability("deviceName")); + Assert.assertEquals("portrait", testCapabilities.getCapability("deviceOrientation")); + Assert.assertEquals("landscape", testCapabilities.getCapability("orientation")); + } } diff --git a/src/test/java/com/xceptance/neodymium/tests/CucumberTest.java b/src/test/java/com/xceptance/neodymium/tests/CucumberTest.java index 2d8049b60..381ea4bf6 100644 --- a/src/test/java/com/xceptance/neodymium/tests/CucumberTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/CucumberTest.java @@ -22,7 +22,7 @@ public void testSetBrowserViaTestData() throws Exception public void testSetBrowserViaTestDataFail() throws Exception { Result result = JUnitCore.runClasses(CucumberSetBrowserViaTestDataFail.class); - checkFail(result, 1, 0, 2, null); + checkFail(result, 1, 0, 1, null); } @Test @@ -36,6 +36,6 @@ public void testSetBrowserViaTag() throws Exception public void testSetBrowserViaTagFail() throws Exception { Result result = JUnitCore.runClasses(CucumberSetBrowserViaTagFail.class); - checkFail(result, 1, 0, 2, null); + checkFail(result, 1, 0, 1, null); } } diff --git a/src/test/java/com/xceptance/neodymium/tests/EnvironmentAndBrowserConfigurationTest.java b/src/test/java/com/xceptance/neodymium/tests/EnvironmentAndBrowserConfigurationTest.java index 159b9c43f..b53abfc0f 100644 --- a/src/test/java/com/xceptance/neodymium/tests/EnvironmentAndBrowserConfigurationTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/EnvironmentAndBrowserConfigurationTest.java @@ -30,7 +30,7 @@ public class EnvironmentAndBrowserConfigurationTest extends NeodymiumTest public static final String BROWSERNAME = "My new name for Samsung S3"; - public static final String ENVIRONMENTNAME = "someEnvrionment"; + public static final String ENVIRONMENTNAME = "someEnvironment"; public static final Boolean USEPROXY1 = true; diff --git a/src/test/java/com/xceptance/neodymium/tests/LocalizationInitalizationErrorTest.java b/src/test/java/com/xceptance/neodymium/tests/LocalizationInitializationErrorTest.java similarity index 95% rename from src/test/java/com/xceptance/neodymium/tests/LocalizationInitalizationErrorTest.java rename to src/test/java/com/xceptance/neodymium/tests/LocalizationInitializationErrorTest.java index df8dc7bbb..555f24d32 100644 --- a/src/test/java/com/xceptance/neodymium/tests/LocalizationInitalizationErrorTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/LocalizationInitializationErrorTest.java @@ -14,7 +14,7 @@ import com.xceptance.neodymium.util.Neodymium; @RunWith(NeodymiumRunner.class) -public class LocalizationInitalizationErrorTest extends NeodymiumTest +public class LocalizationInitializationErrorTest extends NeodymiumTest { private static File tempConfigFile; diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumContextTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumContextTest.java index 19f155666..7d8fc49f1 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumContextTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumContextTest.java @@ -41,7 +41,7 @@ public static void setUpNeodymiumConfiguration() throws IOException Map properties2 = new HashMap<>(); properties2.put("neodymium.webDriver.phantomjs.pathToDriverServer", "/some/phantomjs/path/just/for/test/newPurpose"); writeMapToPropertiesFile(properties2, tempConfigFile2); - ConfigFactory.setProperty(Neodymium.TEMPORARY_CONFIG_FILE_PROPTERY_NAME, "file:" + fileLocation); + ConfigFactory.setProperty(Neodymium.TEMPORARY_CONFIG_FILE_PROPERTY_NAME, "file:" + fileLocation); } @Test diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index 12a3df150..b4fa781db 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -35,7 +35,7 @@ public static void cleanUp() /** * delete a temporary test file */ - protected static void deleteTempFile(File tempFile) + public static void deleteTempFile(File tempFile) { if (tempFile.exists()) { diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumWebDriverTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumWebDriverTest.java new file mode 100644 index 000000000..49d349d66 --- /dev/null +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumWebDriverTest.java @@ -0,0 +1,78 @@ +package com.xceptance.neodymium.tests; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.events.EventFiringWebDriver; + +import com.xceptance.neodymium.testclasses.webDriver.ValidateClearReuseWebDriverCache; +import com.xceptance.neodymium.testclasses.webDriver.ValidateKeepWebDriverOpen; +import com.xceptance.neodymium.testclasses.webDriver.ValidateKeepWebDriverOpenOnFailure; +import com.xceptance.neodymium.testclasses.webDriver.ValidatePreventReuseWebDriver; +import com.xceptance.neodymium.testclasses.webDriver.ValidateReuseWebDriver; +import com.xceptance.neodymium.testclasses.webDriver.ValidateWebDriverClosed; + +public class NeodymiumWebDriverTest extends NeodymiumTest +{ + @Test + public void testValidateWebDriverClosed() + { + Result result = JUnitCore.runClasses(ValidateWebDriverClosed.class); + checkPass(result, 2, 0, 0); + } + + @Test + public void testValidateReuseWebDriver() + { + // XVFB or a display needed + Result result = JUnitCore.runClasses(ValidateReuseWebDriver.class); + checkPass(result, 2, 0, 0); + } + + @Test + public void testValidateClearReuseWebDriverCache() + { + // XVFB or a display needed + Result result = JUnitCore.runClasses(ValidateClearReuseWebDriverCache.class); + checkPass(result, 2, 0, 0); + } + + @Test + public void testValidatePreventReuseWebDriver() + { + // XVFB or a display needed + Result result = JUnitCore.runClasses(ValidatePreventReuseWebDriver.class); + checkPass(result, 3, 0, 0); + } + + @Test + public void testValidateKeepWebDriverOpen() + { + Result result = JUnitCore.runClasses(ValidateKeepWebDriverOpen.class); + checkPass(result, 2, 0, 0); + } + + @Test + public void testValidateKeepWebDriverOpenOnFailure() + { + Result result = JUnitCore.runClasses(ValidateKeepWebDriverOpenOnFailure.class); + checkFail(result, 3, 0, 1, null); + } + + public static void assertWebDriverClosed(WebDriver webDriver) + { + Assert.assertNotNull(webDriver); + RemoteWebDriver driver = (RemoteWebDriver) ((EventFiringWebDriver) webDriver).getWrappedDriver(); + Assert.assertNull(driver.getSessionId()); + } + + public static void assertWebDriverAlive(WebDriver webDriver) + { + Assert.assertNotNull(webDriver); + RemoteWebDriver driver = (RemoteWebDriver) ((EventFiringWebDriver) webDriver).getWrappedDriver(); + Assert.assertNotNull(driver.getSessionId()); + } +} diff --git a/src/test/java/com/xceptance/neodymium/tests/ParameterStatementTest.java b/src/test/java/com/xceptance/neodymium/tests/ParameterStatementTest.java index 8bce0fde8..3c0706f9a 100644 --- a/src/test/java/com/xceptance/neodymium/tests/ParameterStatementTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/ParameterStatementTest.java @@ -82,7 +82,7 @@ public void testGeneratorTooMuchElements() @Test public void testGeneratorAutoTypeConversion() { - // test auto type conversion from string to various data types, aswell as arbitrary type injection + // test auto type conversion from string to various data types, as well as arbitrary type injection Result result = JUnitCore.runClasses(GeneratorAutoTypeConversion.class); checkPass(result, 1, 0, 0); } @@ -125,6 +125,6 @@ public void testGeneratorAutoTypeConversionFailsOnWrongInputData() { // test that auto type conversion from string fails if string content can not match Result result = JUnitCore.runClasses(GeneratorAutoTypeConversionFailsOnWrongInputData.class); - checkFail(result, 1, 0, 1, "An error occured during conversion of input string \"true\" to type double for field \"aDouble\""); + checkFail(result, 1, 0, 1, "An error occurred during conversion of input string \"true\" to type double for field \"aDouble\""); } } diff --git a/src/test/java/com/xceptance/neodymium/tests/ProxyConfigurationTest.java b/src/test/java/com/xceptance/neodymium/tests/ProxyConfigurationTest.java index 7542407ea..70a92177c 100644 --- a/src/test/java/com/xceptance/neodymium/tests/ProxyConfigurationTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/ProxyConfigurationTest.java @@ -51,7 +51,7 @@ public static void beforeClass() throws IOException writeMapToPropertiesFile(properties, tempConfigFile); tempFiles.add(tempConfigFile); - ConfigFactory.setProperty(Neodymium.TEMPORARY_CONFIG_FILE_PROPTERY_NAME, "file:" + fileLocation); + ConfigFactory.setProperty(Neodymium.TEMPORARY_CONFIG_FILE_PROPERTY_NAME, "file:" + fileLocation); } @Test diff --git a/src/test/java/com/xceptance/neodymium/tests/TestDataStatementTest.java b/src/test/java/com/xceptance/neodymium/tests/TestDataStatementTest.java index f547baf2c..363005bc5 100644 --- a/src/test/java/com/xceptance/neodymium/tests/TestDataStatementTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/TestDataStatementTest.java @@ -5,6 +5,7 @@ import org.junit.runner.JUnitCore; import org.junit.runner.Result; +import com.xceptance.neodymium.testclasses.data.file.xml.CanNotReadDataSetXml; import com.xceptance.neodymium.testclasses.data.inheritance.child.PackageTestDataInheritance; import com.xceptance.neodymium.testclasses.data.inheritance.child.grandchild.GrandChildPackageTestDataInheritance; import com.xceptance.neodymium.testclasses.data.inheritance.child.grandchild.set.DataSetOverridesPackageData; @@ -104,7 +105,7 @@ public void testCanReadDataSetXML() @Test public void testPackageTestDataInheritance() { - // test inheritacne of package test data + // test inheritance of package test data Result result = JUnitCore.runClasses(PackageTestDataInheritance.class); checkPass(result, 1, 0, 0); } @@ -358,4 +359,19 @@ public void testOnlyImplicitOneDataSet() throws Throwable checkDescription(OnlyImplicitOneDataSet.class, expected); } + @Test + public void testDataFileAnnotation() throws Exception + { + // test package test data csv is read + Result result = JUnitCore.runClasses(com.xceptance.neodymium.testclasses.data.file.json.CanReadDataSetJson.class); + checkPass(result, 1, 0, 0); + } + + @Test + public void testDataFileAnnotationException() throws Exception + { + Result result = JUnitCore.runClasses(CanNotReadDataSetXml.class); + checkFail(result, 1, 0, 1, + "java.lang.RuntimeException: The data file:\"can/not/read/data/set/xml/DoesNotExist.xml\" provided within the test class:\"CanNotReadDataSetXml\" can't be read."); + } } diff --git a/src/test/java/com/xceptance/neodymium/tests/visual/pixel/TestComparator.java b/src/test/java/com/xceptance/neodymium/tests/visual/pixel/TestComparator.java index 86a609ec2..5fb428631 100644 --- a/src/test/java/com/xceptance/neodymium/tests/visual/pixel/TestComparator.java +++ b/src/test/java/com/xceptance/neodymium/tests/visual/pixel/TestComparator.java @@ -17,7 +17,7 @@ public class TestComparator extends ImageTest private final ComparisonAlgorithm algorithm; - private ImageComparison comperator; + private ImageComparison comparator; private MaskImage masker; @@ -64,20 +64,20 @@ public TestComparator to(final String comparisonImageFile) public TestComparator to(final BufferedImage comparisonImage) { this.comparisonImage = comparisonImage; - comperator = new ImageComparison(referenceImage); + comparator = new ImageComparison(referenceImage); return this; } public TestComparator isEqual() { - Assert.assertTrue(comperator.isEqual(comparisonImage, masker, algorithm)); + Assert.assertTrue(comparator.isEqual(comparisonImage, masker, algorithm)); return this; } public TestComparator isNotEqual() { - Assert.assertFalse(comperator.isEqual(comparisonImage, masker, algorithm)); + Assert.assertFalse(comparator.isEqual(comparisonImage, masker, algorithm)); return this; } @@ -99,20 +99,20 @@ public TestComparator hasMarking(final String markingFile) public TestComparator hasMarking(final BufferedImage marking) { - final BufferedImage comperatorDifference = comperator.getMarkedImageWithBoxes(markingSizeX, markingSizeY); + final BufferedImage comparatorDifference = comparator.getMarkedImageWithBoxes(markingSizeX, markingSizeY); final long now = System.currentTimeMillis(); - writeToTmp(comperatorDifference, MessageFormat.format("actual.{0}.png", String.valueOf(now))); + writeToTmp(comparatorDifference, MessageFormat.format("actual.{0}.png", String.valueOf(now))); writeToTmp(marking, MessageFormat.format("expected.{0}.png", String.valueOf(now))); - Assert.assertTrue(imageEqual(comperatorDifference, marking)); + Assert.assertTrue(imageEqual(comparatorDifference, marking)); return this; } public TestComparator hasNoMarking() { - final BufferedImage comperatorDifference = comperator.getMarkedImageWithBoxes(markingSizeX, markingSizeY); - Assert.assertNull(comperatorDifference); + final BufferedImage comparatorDifference = comparator.getMarkedImageWithBoxes(markingSizeX, markingSizeY); + Assert.assertNull(comparatorDifference); return this; } @@ -122,8 +122,8 @@ public MaskImage getMasker() return masker; } - public ImageComparison getComperator() + public ImageComparison getComparator() { - return comperator; + return comparator; } } diff --git a/src/test/java/com/xceptance/neodymium/util/DebugUtilsTest.java b/src/test/java/com/xceptance/neodymium/util/DebugUtilsTest.java index 9e8a50e78..b52a9cb40 100644 --- a/src/test/java/com/xceptance/neodymium/util/DebugUtilsTest.java +++ b/src/test/java/com/xceptance/neodymium/util/DebugUtilsTest.java @@ -1,10 +1,5 @@ package com.xceptance.neodymium.util; -import static com.codeborne.selenide.Condition.exist; -import static com.codeborne.selenide.Condition.visible; -import static com.codeborne.selenide.Selenide.$; -import static com.codeborne.selenide.Selenide.$$; - import java.util.List; import org.junit.Assert; @@ -19,6 +14,12 @@ import com.xceptance.neodymium.NeodymiumRunner; import com.xceptance.neodymium.module.statement.browser.multibrowser.Browser; +import static com.codeborne.selenide.Condition.exist; +import static com.codeborne.selenide.Condition.visible; + +import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Selenide.$$; + @RunWith(NeodymiumRunner.class) @Browser("Chrome_headless") public class DebugUtilsTest @@ -28,7 +29,7 @@ public void testHighlighting() { Selenide.open("https://blog.xceptance.com/"); DebugUtils.injectJavaScript(); - assertJsSucessfullyInjected(); + assertJsSuccessfullyInjected(); final List list = $("body").findElements(By.cssSelector("#masthead")); DebugUtils.highlightElements(list, Neodymium.getDriver()); @@ -50,7 +51,7 @@ public void testHighlightingWithoutImplicitWaitTime() { Selenide.open("https://blog.xceptance.com/"); DebugUtils.injectJavaScript(); - assertJsSucessfullyInjected(); + assertJsSuccessfullyInjected(); final List list = $("body").findElements(By.cssSelector("#masthead")); DebugUtils.highlightElements(list, Neodymium.getDriver()); @@ -70,32 +71,32 @@ public void testWaiting() // one wait due to navigation Selenide.open("https://blog.xceptance.com/"); - Assert.assertEquals(0, eventListener.impliciteWaitCount); + Assert.assertEquals(0, eventListener.implicitWaitCount); // one wait due to find $("body #masthead").should(exist); - Assert.assertEquals(1, eventListener.impliciteWaitCount); - assertJsSucessfullyInjected(); + Assert.assertEquals(1, eventListener.implicitWaitCount); + assertJsSuccessfullyInjected(); // two waits due to chain finding $("body").findElements(By.cssSelector("#content article")); - Assert.assertEquals(3, eventListener.impliciteWaitCount); + Assert.assertEquals(3, eventListener.implicitWaitCount); // two waits due to find and click $("#text-3 h1").click(); - Assert.assertEquals(4, eventListener.impliciteWaitCount); + Assert.assertEquals(4, eventListener.implicitWaitCount); // additional two waits due to find and click $("#masthead .search-toggle").click(); - Assert.assertEquals(5, eventListener.impliciteWaitCount); + Assert.assertEquals(5, eventListener.implicitWaitCount); // three waits due to find and change value (consumes 2 waits) $("#search-container .search-form input.search-field").val("abc"); - Assert.assertEquals(6, eventListener.impliciteWaitCount); + Assert.assertEquals(6, eventListener.implicitWaitCount); // two waits due to find and press enter $("#search-container .search-form input.search-field").pressEnter(); - Assert.assertEquals(7, eventListener.impliciteWaitCount); + Assert.assertEquals(7, eventListener.implicitWaitCount); } @Test @@ -108,7 +109,7 @@ public void testIFrames() throws Exception SelenideElement body = $("body"); body.click(); - assertJsSucessfullyInjected(); + assertJsSuccessfullyInjected(); final List list = $("body").findElements(By.cssSelector("select")); @@ -120,7 +121,7 @@ public void testIFrames() throws Exception $(".neodymium-highlight-box").shouldNot(exist); } - private void assertJsSucessfullyInjected() + private void assertJsSuccessfullyInjected() { Assert.assertTrue(Selenide.executeJavaScript("return !!window.NEODYMIUM")); } diff --git a/src/test/java/com/xceptance/neodymium/util/JavaScriptUtilsTest.java b/src/test/java/com/xceptance/neodymium/util/JavaScriptUtilsTest.java index a89e5af00..61bdb59b6 100644 --- a/src/test/java/com/xceptance/neodymium/util/JavaScriptUtilsTest.java +++ b/src/test/java/com/xceptance/neodymium/util/JavaScriptUtilsTest.java @@ -56,7 +56,7 @@ public void testWaitingAnimationSelectorUnavailableOnPage() } @Test - public void testWaitingJQueryIsRequiered() + public void testWaitingJQueryIsRequired() { Neodymium.configuration().setProperty("neodymium.javaScriptUtils.loading.jQueryIsRequired", "true"); Neodymium.configuration().setProperty("neodymium.javaScriptUtils.timeout", "10000"); @@ -71,7 +71,7 @@ public void testWaitingJQueryIsRequiered() } @Test - public void testWaitingJQueryIsNotRequiered() + public void testWaitingJQueryIsNotRequired() { Neodymium.configuration().setProperty("neodymium.javaScriptUtils.loading.jQueryIsRequired", "false"); Neodymium.configuration().setProperty("neodymium.javaScriptUtils.timeout", "10000"); diff --git a/src/test/java/com/xceptance/neodymium/util/NeodymiumWebDriverTestListener.java b/src/test/java/com/xceptance/neodymium/util/NeodymiumWebDriverTestListener.java index c50bf3c39..3a1f7ce10 100644 --- a/src/test/java/com/xceptance/neodymium/util/NeodymiumWebDriverTestListener.java +++ b/src/test/java/com/xceptance/neodymium/util/NeodymiumWebDriverTestListener.java @@ -11,7 +11,7 @@ public class NeodymiumWebDriverTestListener extends NeodymiumWebDriverListener { - public int impliciteWaitCount = 0; + public int implicitWaitCount = 0; public NeodymiumWebDriverTestListener() { @@ -40,6 +40,6 @@ public NeodymiumWebDriverTestListener() public void beforeFindBy(By by, WebElement element, WebDriver driver) { super.beforeFindBy(by, element, driver); - impliciteWaitCount++; + implicitWaitCount++; } } diff --git a/src/test/java/com/xceptance/neodymium/util/SelenideAddonsTest.java b/src/test/java/com/xceptance/neodymium/util/SelenideAddonsTest.java index 41063ddde..7e00c3d6a 100644 --- a/src/test/java/com/xceptance/neodymium/util/SelenideAddonsTest.java +++ b/src/test/java/com/xceptance/neodymium/util/SelenideAddonsTest.java @@ -133,11 +133,75 @@ public void beforeEvent(LogEvent currentLog) Selenide.open("https://blog.xceptance.com/"); Neodymium.softAssertions(true); - SelenideAddons.wrapAssertionError(() -> { - Assert.assertEquals(errMessage, "MyPageTitle", Selenide.title()); + try + { + + SelenideAddons.wrapAssertionError(() -> { + Assert.assertEquals(errMessage, "MyPageTitle", Selenide.title()); + }); + } + finally + { + Neodymium.softAssertions(false); + SelenideLogger.removeListener("testListener"); + } + } + + @Test + public void testWrapSoftAssertionErrorWithoutMessage() + { + final String errMessage = "No error message provided by the Assertion."; + + SelenideLogger.addListener("testListener", new LogEventListener() + { + @Override + public void afterEvent(LogEvent currentLog) + { + SelenideLog log = (SelenideLog) currentLog; + if (log.getStatus().equals(EventStatus.FAIL)) + { + Assert.assertEquals("Selenide log event not matching", "Assertion error", log.getElement()); + Assert.assertEquals("Selenide log event not matching", log.getSubject(), errMessage); + } + } + + @Override + public void beforeEvent(LogEvent currentLog) + { + // ignore + } }); - Neodymium.softAssertions(false); - SelenideLogger.removeListener("testListener"); + Selenide.open("https://blog.xceptance.com/"); + Neodymium.softAssertions(true); + try + { + SelenideAddons.wrapAssertionError(() -> { + Assert.assertTrue(Selenide.title().startsWith("MyPageTitle")); + }); + } + finally + { + Neodymium.softAssertions(false); + SelenideLogger.removeListener("testListener"); + } + } + + @Test + public void testWrapAssertionErrorWithoutMessage() + { + final String errMessage = "AssertionError: No error message provided by the Assertion."; + try + { + Selenide.open("https://blog.xceptance.com/"); + SelenideAddons.wrapAssertionError(() -> { + Assert.assertTrue(Selenide.title().startsWith("MyPageTitle")); + }); + } + catch (Throwable e) + { + Assert.assertTrue(e instanceof AssertionError); + Assert.assertEquals(errMessage, e.getMessage()); + } } }