Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml

Prepared release and bumped version to 2.1.0
  • Loading branch information
Marcel Pfotenhauer committed Aug 22, 2018
2 parents 9225ba0 + 2a05ab4 commit e7ce1b5
Show file tree
Hide file tree
Showing 13 changed files with 230 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Neodymium 2.0.0
# Neodymium 2.1.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.
Expand Down
1 change: 1 addition & 0 deletions config/browser.properties
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ browserprofile.Galaxy_Note3_Emulation.browser = chrome
browserprofile.Galaxy_Note3_Emulation.chromeEmulationProfile = Samsung Galaxy Note 3

browserprofile.iphone5.name = iphone 5 on saucelabs
browserprofile.iphone5.browser = iphone
browserprofile.iphone5.platform = OS X 10.10
browserprofile.iphone5.version = 8.4
browserprofile.iphone5.deviceName = iPhone 5
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.xceptance</groupId>
<artifactId>neodymium-library</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>

<name>neodymium-library</name>
<url>https://github.com/Xceptance/neodymium-library</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

public class NeodymiumCucumberRunListener extends RunListener
{
public static final String LISTENER_NAME = "allure-selenide-cucumber";

private static final Logger LOGGER = LoggerFactory.getLogger(NeodymiumCucumberRunListener.class);

private List<Failure> failures = new LinkedList<>();

public NeodymiumCucumberRunListener()
{
SelenideLogger.addListener("allure-selenide", new AllureSelenide());
SelenideLogger.addListener(LISTENER_NAME, new AllureSelenide());
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/xceptance/neodymium/NeodymiumRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;

import com.codeborne.selenide.logevents.SelenideLogger;
import com.xceptance.neodymium.module.EnhancedMethod;
import com.xceptance.neodymium.module.StatementBuilder;
import com.xceptance.neodymium.module.order.DefaultStatementRunOrder;
import com.xceptance.neodymium.module.statement.browser.multibrowser.Browser;
import com.xceptance.neodymium.util.Neodymium;

import io.qameta.allure.selenide.AllureSelenide;

/**
* This class executes {@link JUnit4} test classes (aka JUnit Runner) and adds several features to test execution e.g.
* multi {@link Browser browser} and
Expand Down Expand Up @@ -66,9 +69,12 @@
*/
public class NeodymiumRunner extends BlockJUnit4ClassRunner
{
public static final String LISTENER_NAME = "allure-selenide-java";

public NeodymiumRunner(Class<?> klass) throws InitializationError
{
super(klass);
SelenideLogger.addListener(LISTENER_NAME, new AllureSelenide());
}

public enum DescriptionMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ else if ("opera".equals(emulatedBrowser))
}
else
{
capabilities = DesiredCapabilities.firefox();
capabilities = new DesiredCapabilities();
}

/*
Expand Down
75 changes: 75 additions & 0 deletions src/main/java/com/xceptance/neodymium/util/SelenideAddons.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@

import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement;

import com.codeborne.selenide.Condition;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.SelenideElement;
import com.codeborne.selenide.ex.UIAssertionError;
import com.codeborne.selenide.impl.Html;
import com.codeborne.selenide.impl.WebElementsCollectionWrapper;

/**
Expand Down Expand Up @@ -143,4 +147,75 @@ public ElementsCollection get()
// never get here
return null;
}

/**
* The missing regular expression condition for value attributes.<br>
* <br>
* <p>
* Sample: <code>$("input").waitWhile(matchesValue("foo"), 12000)</code>
* </p>
*
* @param text
* The text that should be contained within the value attribute
* @return a Selenide {@link Condition}
* @see #matchValue(String)
*/
public static Condition matchesValue(String text)
{
return matchValue(text);
}

/**
* The missing regular expression condition for value attributes.<br>
* <br>
* <p>
* Sample: Assert that given element's value attribute matches given regular expression
* <code>$("input").should(matchValue("Hello\s*John"))</code>
* </p>
*
* @param regex
* e.g. Kicked.*Chuck Norris - in this case ".*" can contain any characters including spaces, tabs, CR
* etc.
* @return a Selenide {@link Condition}
*/
public static Condition matchValue(final String regex)
{
return new Condition("match value")
{
@Override
public boolean apply(WebElement element)
{
return Html.text.matches(element.getAttribute("value"), regex);
}

@Override
public String toString()
{
return name + " '" + regex + '\'';
}
};
}

/**
* The missing wrapper to generate screenshots and save the html source code if a jUnit assertion fails.<br>
* <br>
* <p>
* Sample: Assert that page title is correct and dump the page source and a screenshot in case of a mismatch
* <code> wrapAssertionError(()-&gt;{Assert.assertEquals("MyPageTitle", Selenide.title());});</code>
* </p>
*
* @param runnable
* The lambda containing an assertion
*/
public static void wrapAssertionError(final Runnable runnable)
{
try
{
runnable.run();
}
catch (AssertionError e)
{
throw UIAssertionError.wrapThrowable(e, System.currentTimeMillis());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.xceptance.neodymium.testclasses.allure;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.codeborne.selenide.logevents.SelenideLogger;
import com.xceptance.neodymium.NeodymiumRunner;
import com.xceptance.neodymium.module.statement.browser.multibrowser.Browser;

@RunWith(NeodymiumRunner.class)
@Browser("Chrome_headless")
public class AllureSelenideListenerIsActiveForJava
{
@Test
public void testWaitingAnimationSelectorUnconfigured()
{
Assert.assertTrue(" AllureSelenide listener is not attached", SelenideLogger.hasListener(NeodymiumRunner.LISTENER_NAME));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import org.junit.Assert;

import com.codeborne.selenide.logevents.SelenideLogger;
import com.xceptance.neodymium.NeodymiumCucumberRunListener;
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;

public class CucumberSupport
{
Expand Down Expand Up @@ -39,4 +42,10 @@ public void validateBrowser(String browserProfileName)
{
Assert.assertEquals(browserProfileName, Neodymium.getBrowserProfileName());
}

@Then("^validate the AllureSelenide listener is active$")
public void validateAllureSelenideListenerIsActive()
{
Assert.assertTrue(" AllureSelenide listener is not attached", SelenideLogger.hasListener(NeodymiumCucumberRunListener.LISTENER_NAME));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.xceptance.neodymium.testclasses.cucumber;

import org.junit.runner.RunWith;

import com.xceptance.neodymium.NeodymiumCucumberRunner;

import cucumber.api.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")
public class CucumberValidateAllureSelenideListenerIsActive
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.xceptance.neodymium.tests;

import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;

import com.xceptance.neodymium.testclasses.allure.AllureSelenideListenerIsActiveForJava;
import com.xceptance.neodymium.testclasses.cucumber.CucumberValidateAllureSelenideListenerIsActive;

public class AllureSelenideListenerTest extends NeodymiumTest
{
@Test
public void testAllureSelenideListenerIsActiveForCucumber()
{
Result result = JUnitCore.runClasses(CucumberValidateAllureSelenideListenerIsActive.class);
checkPass(result, 1, 0, 0);
}

@Test
public void testAllureSelenideListenerIsActiveForJava()
{
Result result = JUnitCore.runClasses(AllureSelenideListenerIsActiveForJava.class);
checkPass(result, 1, 0, 0);
}
}
67 changes: 67 additions & 0 deletions src/test/java/com/xceptance/neodymium/util/SelenideAddonsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.xceptance.neodymium.util;

import static com.codeborne.selenide.Selenide.$;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.ex.ElementShould;
import com.codeborne.selenide.ex.UIAssertionError;
import com.xceptance.neodymium.NeodymiumRunner;
import com.xceptance.neodymium.module.statement.browser.multibrowser.Browser;

@RunWith(NeodymiumRunner.class)
@Browser("Chrome_headless")
public class SelenideAddonsTest
{
@Test
public void testMatchesValueCondition()
{
Selenide.open("https://blog.xceptance.com/");
$("#masthead .search-toggle").click();
$("#search-container .search-field").val("searchphrase").submit();

$("#content .search-field").should(SelenideAddons.matchesValue("earchphras"));
}

@Test
public void testMatchValueCondition()
{
Selenide.open("https://blog.xceptance.com/");
$("#masthead .search-toggle").click();
$("#search-container .search-field").val("searchphrase").submit();

$("#content .search-field").should(SelenideAddons.matchValue("^s.a.c.p.r.s.$"));
$("#content .search-field").should(SelenideAddons.matchValue("\\D+"));
}

@Test(expected = ElementShould.class)
public void testMatchValueConditionError()
{
Selenide.open("https://blog.xceptance.com/");
$("#masthead .search-toggle").click();
$("#search-container .search-field").val("searchphrase").submit();

$("#content .search-field").should(SelenideAddons.matchValue("\\d+"));
}

@Test()
public void testWrapAssertion()
{
Selenide.open("https://blog.xceptance.com/");
SelenideAddons.wrapAssertionError(() -> {
Assert.assertEquals("Passionate Testing | Xceptance Blog", Selenide.title());
});
}

@Test(expected = UIAssertionError.class)
public void testWrapAssertionError()
{
Selenide.open("https://blog.xceptance.com/");
SelenideAddons.wrapAssertionError(() -> {
Assert.assertEquals("MyPageTitle", Selenide.title());
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@SetUpWithBrowserTag
Feature: Set browser via tag

@Chrome_headless
Scenario: Set browsers
Given the browser "Chrome_headless" is setup
Then validate the AllureSelenide listener is active

0 comments on commit e7ce1b5

Please sign in to comment.