├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── run-selenium.sh
├── src
├── test
│ ├── java
│ │ ├── com
│ │ │ └── cd
│ │ │ │ └── acceptance
│ │ │ │ └── dsl
│ │ │ │ ├── Channels.java
│ │ │ │ ├── Channel.java
│ │ │ │ ├── CucumberDsl.java
│ │ │ │ ├── drivers
│ │ │ │ ├── BookShopDriver.java
│ │ │ │ ├── BookShopDrivers.java
│ │ │ │ ├── MyLocalBookStoreBookShopDriver.java
│ │ │ │ ├── ChannelFinder.java
│ │ │ │ ├── AmazonBookShopDriver.java
│ │ │ │ └── BookDepositoryBookShopDriver.java
│ │ │ │ ├── Dsl.java
│ │ │ │ ├── TestAnnotationFinderTest.java
│ │ │ │ ├── Params.java
│ │ │ │ └── BookShoppingDsl.java
│ │ └── feature
│ │ │ ├── AddBookToBasketTest.java
│ │ │ └── AddBookToBasketSteps.java
│ ├── resources
│ │ └── feature
│ │ │ └── OrderBook.feature
│ └── acceptance
│ │ └── com
│ │ └── cd
│ │ └── acceptance
│ │ ├── examples
│ │ ├── ExampleAmazonAcceptanceTest.java
│ │ ├── ExampleBookStoreAcceptanceTest.java
│ │ └── ExampleMyLocalBookStoreAcceptanceTest.java
│ │ └── utils
│ │ └── PollWithTimeOut.java
└── main
│ └── java
│ └── com
│ └── cd
│ └── acceptance
│ └── examples
│ ├── Book.java
│ └── MyLocalBookStore.java
├── .idea
├── vcs.xml
└── libraries
│ ├── Gradle__junit_junit_4_12.xml
│ └── Gradle__info_cukes_cucumber_junit_1_2_5.xml
├── gradlew.bat
├── acceptance-testing.iml
└── gradlew
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'acceptance-testing'
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davef77/acceptance-testing/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/run-selenium.sh:
--------------------------------------------------------------------------------
1 |
2 | docker run -d -p 4444:4444 selenium/standalone-chrome
3 | #docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome:3.0.1-aluminum
--------------------------------------------------------------------------------
/src/test/java/com/cd/acceptance/dsl/Channels.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.dsl;
2 |
3 | public enum Channels {
4 | Unknown,
5 | Amazon,
6 | BookDepository,
7 | MyLocalBookStore;
8 | }
9 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/test/java/feature/AddBookToBasketTest.java:
--------------------------------------------------------------------------------
1 | package feature;
2 |
3 | import org.junit.runner.RunWith;
4 |
5 | import cucumber.api.junit.Cucumber;
6 |
7 | @RunWith(Cucumber.class)
8 | public class AddBookToBasketTest
9 | {
10 | }
11 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Nov 08 12:03:59 GMT 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
7 |
--------------------------------------------------------------------------------
/src/test/java/com/cd/acceptance/dsl/Channel.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.dsl;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.RetentionPolicy;
5 |
6 | /**
7 | * Copyright (c) Continuous Delivery Ltd. 2016
8 | */
9 | @Retention(RetentionPolicy.RUNTIME)
10 | public @interface Channel
11 | {
12 | Channels[] value() default Channels.Unknown;
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/src/test/java/com/cd/acceptance/dsl/CucumberDsl.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.dsl;
2 |
3 | import com.cd.acceptance.dsl.drivers.BookShopDrivers;
4 |
5 | /**
6 | * Copyright (c) Continuous Delivery Ltd. 2016
7 | */
8 | public class CucumberDsl
9 | {
10 | public BookShoppingDsl shopping;
11 |
12 | public CucumberDsl()
13 | {
14 | shopping = new BookShoppingDsl(new BookShopDrivers());
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/test/java/com/cd/acceptance/dsl/drivers/BookShopDriver.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.dsl.drivers;
2 |
3 | /**
4 | * Copyright (c) Continuous Delivery Ltd. 2016
5 | */
6 | public interface BookShopDriver
7 | {
8 | void findBooks(String title);
9 |
10 | void selectBook(String author);
11 |
12 | void addSelectedItemToShoppingBasket();
13 |
14 | void assertListedInShoppingBasket(String item);
15 | }
16 |
--------------------------------------------------------------------------------
/src/test/java/com/cd/acceptance/dsl/Dsl.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.dsl;
2 |
3 | import com.cd.acceptance.dsl.drivers.BookShopDrivers;
4 | import org.junit.Before;
5 |
6 | /**
7 | * Copyright (c) Continuous Delivery Ltd. 2016
8 | */
9 | public class Dsl
10 | {
11 | public BookShoppingDsl shopping;
12 |
13 | @Before
14 | public void setUp()
15 | {
16 | shopping = new BookShoppingDsl(new BookShopDrivers());
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/test/resources/feature/OrderBook.feature:
--------------------------------------------------------------------------------
1 | Feature: Add Book to Shopping-Basket
2 | As a book-buyer
3 | I would like to select a book and add it to my shopping-basket
4 | So that I can pay for it later
5 |
6 | Scenario:
7 | Given I search for books about "Continuous Delivery"
8 | And I select a book by "David Farley"
9 |
10 | When I add my selected book to my shopping-basket
11 |
12 | Then I can see the book "Continuous Delivery" listed in my shopping-basket
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__junit_junit_4_12.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/main/java/com/cd/acceptance/examples/Book.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.examples;
2 |
3 | /**
4 | * Copyright (c) Continuous Delivery Ltd. 2016
5 | */
6 | public class Book
7 | {
8 | private final String title;
9 | private final String author;
10 |
11 | public Book(String title, String author)
12 | {
13 | this.title = title;
14 | this.author = author;
15 | }
16 |
17 | public boolean isWrittenBy(String author)
18 | {
19 | return this.author.contains(author);
20 | }
21 |
22 | public String title()
23 | {
24 | return title;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__info_cukes_cucumber_junit_1_2_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/test/java/com/cd/acceptance/dsl/TestAnnotationFinderTest.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.dsl;
2 |
3 | import com.cd.acceptance.dsl.drivers.ChannelFinder;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 |
7 | import java.util.Arrays;
8 |
9 | import static com.cd.acceptance.dsl.Channels.*;
10 |
11 | /**
12 | * Copyright (c) Continuous Delivery Ltd. 2016
13 | */
14 | public class TestAnnotationFinderTest extends Dsl
15 | {
16 | @Channel({Amazon, BookDepository})
17 | @Test
18 | public void shouldReportChannelList() throws Exception
19 | {
20 | Assert.assertEquals(Arrays.asList("Amazon", "BookDepository"), ChannelFinder.listChannels());
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/test/java/com/cd/acceptance/dsl/Params.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.dsl;
2 |
3 | /**
4 | * Copyright (c) Continuous Delivery Ltd. 2016
5 | */
6 | public class Params
7 | {
8 | private final String[] args;
9 |
10 | public Params(String[] args)
11 | {
12 | this.args = args;
13 | }
14 |
15 | public String Optional(String name, String defaultValue)
16 | {
17 | for (String arg : args)
18 | {
19 | int index = arg.indexOf(name + ": ");
20 | if (index != -1)
21 | {
22 | return arg.substring(index + name.length() + 2);
23 | }
24 | }
25 | return defaultValue;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/acceptance/com/cd/acceptance/examples/ExampleAmazonAcceptanceTest.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.examples;
2 |
3 | import com.cd.acceptance.dsl.Channel;
4 | import com.cd.acceptance.dsl.Dsl;
5 | import org.junit.Before;
6 | import org.junit.Test;
7 |
8 | import static com.cd.acceptance.dsl.Channels.Amazon;
9 |
10 | /**
11 | * Copyright (c) Continuous Delivery Ltd. 2016
12 | */
13 | public class ExampleAmazonAcceptanceTest extends Dsl
14 | {
15 | @Test
16 | @Channel(Amazon)
17 | public void shouldAddBookToShoppingBasket() throws Exception
18 | {
19 | shopping.searchForBook("title: Continuous Delivery");
20 | shopping.selectBook("author: David Farley");
21 |
22 | shopping.addSelectedItemToShoppingBasket();
23 |
24 | shopping.assertItemListedInShoppingBasket("item: Continuous Delivery");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/test/acceptance/com/cd/acceptance/examples/ExampleBookStoreAcceptanceTest.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.examples;
2 |
3 | import com.cd.acceptance.dsl.Channel;
4 | import com.cd.acceptance.dsl.Dsl;
5 | import org.junit.Before;
6 | import org.junit.Test;
7 |
8 | import static com.cd.acceptance.dsl.Channels.Amazon;
9 | import static com.cd.acceptance.dsl.Channels.BookDepository;
10 |
11 | /**
12 | * Copyright (c) Continuous Delivery Ltd. 2016
13 | */
14 | public class ExampleBookStoreAcceptanceTest extends Dsl
15 | {
16 | @Test
17 | @Channel({BookDepository, Amazon})
18 | public void shouldAddBookToShoppingBasket() throws Exception
19 | {
20 | shopping.searchForBook("title: Continuous Delivery");
21 | shopping.selectBook("author: David Farley");
22 |
23 | shopping.addSelectedItemToShoppingBasket();
24 |
25 | shopping.assertItemListedInShoppingBasket("item: Continuous Delivery");
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/test/acceptance/com/cd/acceptance/examples/ExampleMyLocalBookStoreAcceptanceTest.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.examples;
2 |
3 | import com.cd.acceptance.dsl.Channel;
4 | import com.cd.acceptance.dsl.Dsl;
5 | import org.junit.Test;
6 |
7 | import static com.cd.acceptance.dsl.Channels.Amazon;
8 | import static com.cd.acceptance.dsl.Channels.BookDepository;
9 | import static com.cd.acceptance.dsl.Channels.MyLocalBookStore;
10 |
11 | /**
12 | * Copyright (c) Continuous Delivery Ltd. 2016
13 | */
14 | public class ExampleMyLocalBookStoreAcceptanceTest extends Dsl
15 | {
16 | @Test
17 | @Channel({MyLocalBookStore, BookDepository, Amazon})
18 | public void shouldAddBookToShoppingBasket() throws Exception
19 | {
20 | shopping.searchForBook("title: Continuous Delivery");
21 | shopping.selectBook("author: David Farley");
22 |
23 | shopping.addSelectedItemToShoppingBasket();
24 |
25 | shopping.assertItemListedInShoppingBasket("item: Continuous Delivery");
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/cd/acceptance/examples/MyLocalBookStore.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.examples;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * Copyright (c) Continuous Delivery Ltd. 2016
8 | */
9 | public class MyLocalBookStore
10 | {
11 | private List allBooks = new ArrayList<>();
12 | private List shoppingBasket = new ArrayList<>();
13 |
14 |
15 | public void addBook(Book book)
16 | {
17 | allBooks.add(book);
18 | }
19 |
20 | public List findBooksByTitle(String title)
21 | {
22 | List books = new ArrayList<>();
23 |
24 | for (Book book : allBooks)
25 | {
26 | if (book.title().contains(title))
27 | {
28 | books.add(book);
29 | }
30 | }
31 | return books;
32 | }
33 |
34 | public void addToBasket(Book selectedBook)
35 | {
36 | shoppingBasket.add(selectedBook);
37 | }
38 |
39 | public List listBasketItems()
40 | {
41 | return shoppingBasket;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/test/java/feature/AddBookToBasketSteps.java:
--------------------------------------------------------------------------------
1 | package feature;
2 |
3 | import com.cd.acceptance.dsl.CucumberDsl;
4 | import cucumber.api.java.en.Given;
5 | import cucumber.api.java.en.Then;
6 | import cucumber.api.java.en.When;
7 |
8 | /**
9 | * Copyright (c) Continuous Delivery Ltd. 2016
10 | */
11 | public class AddBookToBasketSteps
12 | {
13 | private CucumberDsl dsl = new CucumberDsl();
14 |
15 | @Given("^I search for books about \"([^\"]*)\"$")
16 | public void i_search_for_books_about(String subject) throws Throwable {
17 | dsl.shopping.searchForBook(subject);
18 | }
19 |
20 | @Given("^I select a book by \"([^\"]*)\"$")
21 | public void i_select_a_book_by(String author) throws Throwable {
22 | dsl.shopping.selectBook(author);
23 | }
24 |
25 | @When("^I add my selected book to my shopping-basket$")
26 | public void i_add_my_selected_book_to_my_shopping_basket() throws Throwable {
27 | dsl.shopping.addSelectedItemToShoppingBasket();
28 | }
29 |
30 | @Then("^I can see the book \"([^\"]*)\" listed in my shopping-basket$")
31 | public void i_can_see_the_book_listed_in_my_shopping_basket(String title) throws Throwable {
32 | dsl.shopping.assertItemListedInShoppingBasket(title);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/test/java/com/cd/acceptance/dsl/BookShoppingDsl.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.dsl;
2 |
3 | import com.cd.acceptance.dsl.drivers.BookShopDrivers;
4 |
5 | /**
6 | * Copyright (c) Continuous Delivery Ltd. 2016
7 | */
8 | public class BookShoppingDsl
9 | {
10 | private final BookShopDrivers driver;
11 |
12 | public BookShoppingDsl(BookShopDrivers drivers)
13 | {
14 | this.driver = drivers;
15 | }
16 |
17 | public void searchForBook(String... args)
18 | {
19 | Params params = new Params(args);
20 | String title = params.Optional("title", "Continuous Delivery");
21 |
22 | driver.findBooks(title);
23 | }
24 |
25 | public void selectBook(String... args)
26 | {
27 | Params params = new Params(args);
28 | String author = params.Optional("author", "David Farley");
29 |
30 | driver.selectBook(author);
31 | }
32 |
33 | public void addSelectedItemToShoppingBasket()
34 | {
35 | driver.addSelectedItemToShoppingBasket();
36 | }
37 |
38 | public void assertItemListedInShoppingBasket(String... args)
39 | {
40 | Params params = new Params(args);
41 | String item = params.Optional("item", "Continuous Delivery");
42 |
43 | driver.assertListedInShoppingBasket(item);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/com/cd/acceptance/dsl/drivers/BookShopDrivers.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.dsl.drivers;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | /**
8 | * Copyright (c) Continuous Delivery Ltd. 2016
9 | */
10 | public class BookShopDrivers implements BookShopDriver
11 | {
12 | private Map drivers = new HashMap();
13 |
14 | public BookShopDrivers()
15 | {
16 | drivers.put("Amazon", new AmazonBookShopDriver());
17 | drivers.put("BookDepository", new BookDepositoryBookShopDriver());
18 | drivers.put("MyLocalBookStore", new MyLocalBookStoreBookShopDriver());
19 | drivers.put("default", new MyLocalBookStoreBookShopDriver());
20 | }
21 |
22 | private BookShopDriver driver()
23 | {
24 | List channels = ChannelFinder.listChannels();
25 |
26 | return drivers.get(channels.get(0));
27 | }
28 |
29 | @Override
30 | public void findBooks(String title)
31 | {
32 | driver().findBooks(title);
33 | }
34 |
35 | @Override
36 | public void selectBook(String author)
37 | {
38 | driver().selectBook(author);
39 | }
40 |
41 | @Override
42 | public void addSelectedItemToShoppingBasket()
43 | {
44 | driver().addSelectedItemToShoppingBasket();
45 | }
46 |
47 | @Override
48 | public void assertListedInShoppingBasket(String item)
49 | {
50 | driver().assertListedInShoppingBasket(item);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/test/acceptance/com/cd/acceptance/utils/PollWithTimeOut.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.utils;
2 |
3 | import org.openqa.selenium.WebElement;
4 |
5 | import java.util.List;
6 | import java.util.function.IntConsumer;
7 | import java.util.function.Supplier;
8 |
9 | /**
10 | * Copyright (c) Continuous Delivery Ltd. 2016
11 | */
12 | public class PollWithTimeOut
13 | {
14 | private long duration;
15 | private long waitDuration = 10L;
16 | private long start;
17 |
18 | public static PollWithTimeOut await()
19 | {
20 | return new PollWithTimeOut();
21 | }
22 |
23 | public PollWithTimeOut atMost(long millis)
24 | {
25 | duration = millis;
26 |
27 | return this;
28 | }
29 |
30 |
31 | public void until(Supplier> supplier, IntConsumer consumer)
32 | {
33 | List found;
34 | start = System.currentTimeMillis();
35 |
36 | do
37 | {
38 | found = supplier.get();
39 |
40 | } while (found.size() == 0 && !timedOut());
41 |
42 | consumer.accept(found.size());
43 | }
44 |
45 | private boolean timedOut()
46 | {
47 | long now = System.currentTimeMillis();
48 | boolean isTimedOut = now - start >= duration;
49 |
50 | if (!isTimedOut)
51 | try
52 | {
53 | Thread.sleep(waitDuration);
54 | }
55 | catch (InterruptedException e)
56 | {
57 | // Intentionally Ignored
58 | }
59 |
60 | return isTimedOut;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/test/java/com/cd/acceptance/dsl/drivers/MyLocalBookStoreBookShopDriver.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.dsl.drivers;
2 |
3 | import com.cd.acceptance.examples.Book;
4 | import com.cd.acceptance.examples.MyLocalBookStore;
5 | import org.junit.Assert;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Copyright (c) Continuous Delivery Ltd. 2016
11 | */
12 | public class MyLocalBookStoreBookShopDriver implements BookShopDriver
13 | {
14 | private MyLocalBookStore store = new MyLocalBookStore();
15 | private List booksByTitle;
16 | private Book selectedBook;
17 |
18 | public MyLocalBookStoreBookShopDriver()
19 | {
20 | store.addBook(new Book("Continuous Delivery", "David Farley & Jez Humble"));
21 | store.addBook(new Book("Continuous Delivery for Dummies", "Someone Else"));
22 | store.addBook(new Book("Continuous Delivery of Insulin", "Another Person"));
23 | }
24 |
25 |
26 | @Override
27 | public void findBooks(String title)
28 | {
29 | booksByTitle = store.findBooksByTitle(title);
30 | }
31 |
32 | @Override
33 | public void selectBook(String author)
34 | {
35 | for (Book book : booksByTitle)
36 | {
37 | if (book.isWrittenBy(author))
38 | {
39 | selectedBook = book;
40 | }
41 | }
42 | }
43 |
44 | @Override
45 | public void addSelectedItemToShoppingBasket()
46 | {
47 | store.addToBasket(selectedBook);
48 | }
49 |
50 | @Override
51 | public void assertListedInShoppingBasket(String item)
52 | {
53 | List basket = store.listBasketItems();
54 |
55 | for (Book book : basket)
56 | {
57 | if (item.equals(book.title()))
58 | {
59 | return;
60 | }
61 | }
62 |
63 | Assert.fail(String.format("Item '%s' not found in shopping basket", item));
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/com/cd/acceptance/dsl/drivers/ChannelFinder.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.dsl.drivers;
2 |
3 |
4 | import com.cd.acceptance.dsl.Channel;
5 | import com.cd.acceptance.dsl.Channels;
6 | import org.junit.Test;
7 |
8 | import java.lang.annotation.Annotation;
9 | import java.lang.reflect.Method;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | /**
14 | * Copyright (c) Continuous Delivery Ltd. 2016
15 | */
16 | public class ChannelFinder
17 | {
18 | public static List listChannels()
19 | {
20 | ArrayList channels = new ArrayList();
21 |
22 | Method testMethod = findTestMethod();
23 |
24 | if (testMethod != null)
25 | {
26 | Channel c = testMethod.getAnnotation(Channel.class);
27 |
28 | for (Channels channel : c.value())
29 | {
30 | channels.add(channel.name());
31 | }
32 | }
33 | else
34 | {
35 | channels.add("default");
36 | }
37 |
38 | return channels;
39 | }
40 |
41 | private static Method findTestMethod()
42 | {
43 | StackTraceElement[] elements = new Throwable().fillInStackTrace().getStackTrace();
44 |
45 | for (int i = 1; i < elements.length; i++)
46 | {
47 | StackTraceElement element = elements[i];
48 |
49 | try
50 | {
51 | Class clz = Class.forName(element.getClassName());
52 | Method method = clz.getMethod(element.getMethodName(), new Class[0]);
53 |
54 | for (Annotation annotation : method.getAnnotations())
55 | {
56 | if (annotation.annotationType() == Test.class)
57 | {
58 | return method;
59 | }
60 | }
61 | }
62 | catch (NoSuchMethodException ignored)
63 | {
64 |
65 | }
66 | catch (SecurityException ignored)
67 | {
68 |
69 | }
70 | catch (ClassNotFoundException ignored)
71 | {
72 |
73 | }
74 |
75 | }
76 | return null;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/src/test/java/com/cd/acceptance/dsl/drivers/AmazonBookShopDriver.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.dsl.drivers;
2 |
3 |
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.openqa.selenium.remote.DesiredCapabilities;
8 | import org.openqa.selenium.remote.RemoteWebDriver;
9 |
10 | import java.net.MalformedURLException;
11 | import java.net.URL;
12 | import java.util.List;
13 |
14 | import static junit.framework.TestCase.assertEquals;
15 |
16 | /**
17 | * Copyright (c) Continuous Delivery Ltd. 2016
18 | */
19 | public class AmazonBookShopDriver implements BookShopDriver
20 | {
21 |
22 | private final static String BOOKSHOP_URL = "http://www.amazon.co.uk";
23 |
24 | private WebDriver driver;
25 |
26 | public AmazonBookShopDriver()
27 | {
28 | }
29 |
30 | @Override
31 | public void findBooks(String title)
32 | {
33 | gotoPage(BOOKSHOP_URL, "Amazon.co.uk: Low Prices in Electronics, Books, Sports Equipment & more");
34 | WebElement searchBox = driver().findElement(By.id("twotabsearchtextbox"));
35 |
36 | searchBox.sendKeys(title + "\n");
37 | }
38 |
39 | @Override
40 | public void selectBook(String author)
41 | {
42 | WebElement book = driver().findElement(By.xpath(String.format("//div[@class=\"a-row a-spacing-none\"]/span/a[text()='%s']/../../../div/a[contains(@class, 's-access-detail-page')]", author)));
43 |
44 | book.click();
45 | }
46 |
47 | @Override
48 | public void addSelectedItemToShoppingBasket()
49 | {
50 | WebElement buyButton = driver().findElement(By.id("add-to-cart-button"));
51 |
52 | buyButton.click();
53 | }
54 |
55 | @Override
56 | public void assertListedInShoppingBasket(String item)
57 | {
58 | gotoPage("https://www.amazon.co.uk/gp/cart/view.html/ref=nav_cart", "Amazon.co.uk Shopping Basket");
59 |
60 | List found = driver().findElements(By.xpath("//span[@class=\"a-list-item\"]/*[contains(., \"Continuous Delivery\")]"));
61 |
62 | assertEquals(String.format("Item '%s' not found in shopping basket", item), 1, found.size());
63 | }
64 |
65 | private void gotoPage(String page, String expectedTitle)
66 | {
67 | driver().get(page);
68 |
69 | assertEquals(expectedTitle, driver().getTitle());
70 | }
71 |
72 | private WebDriver driver()
73 | {
74 | if (driver == null)
75 | {
76 | try
77 | {
78 | driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub/"), DesiredCapabilities.chrome());
79 | }
80 | catch (MalformedURLException e)
81 | {
82 | e.printStackTrace();
83 | }
84 | }
85 | return driver;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/test/java/com/cd/acceptance/dsl/drivers/BookDepositoryBookShopDriver.java:
--------------------------------------------------------------------------------
1 | package com.cd.acceptance.dsl.drivers;
2 |
3 |
4 | import org.openqa.selenium.By;
5 | import org.openqa.selenium.WebDriver;
6 | import org.openqa.selenium.WebElement;
7 | import org.openqa.selenium.remote.DesiredCapabilities;
8 | import org.openqa.selenium.remote.RemoteWebDriver;
9 |
10 | import java.net.MalformedURLException;
11 | import java.net.URL;
12 |
13 | import static com.cd.acceptance.utils.PollWithTimeOut.await;
14 | import static junit.framework.TestCase.assertEquals;
15 |
16 | /**
17 | * Copyright (c) Continuous Delivery Ltd. 2016
18 | */
19 | public class BookDepositoryBookShopDriver implements BookShopDriver
20 | {
21 |
22 | private final static String BOOKSHOP_URL = "http://www.bookdepository.com/";
23 |
24 | private WebDriver driver;
25 |
26 | @Override
27 | public void findBooks(String title)
28 | {
29 | gotoPage(BOOKSHOP_URL, "Book Depository: Millions of books with free delivery worldwide");
30 | WebElement searchBox = driver().findElement(By.name("searchTerm"));
31 |
32 | searchBox.sendKeys(title + "\n");
33 | }
34 |
35 |
36 | @Override
37 | public void selectBook(String author)
38 | {
39 | WebElement book = driver().findElement(By.xpath(String.format("//div[@class=\"book-item\"]/div/p/a[text()='%s']/../../../div[@class=\"item-info\"]/h3/a", getAuthor(author))));
40 |
41 | book.click();
42 | }
43 |
44 | @Override
45 | public void addSelectedItemToShoppingBasket()
46 | {
47 | WebElement buyButton = driver().findElement(By.className("add-to-basket"));
48 |
49 | buyButton.click();
50 | }
51 |
52 | @Override
53 | public void assertListedInShoppingBasket(String item)
54 | {
55 | gotoPage("https://www.bookdepository.com/basket", "Your basket");
56 |
57 | await()
58 | .atMost(1000)
59 | .until(() -> driver().findElements(By.xpath("//div[@class=\"basket-item\"]/*[contains(., \"Continuous Delivery\")]")),
60 | found -> assertEquals(String.format("Item '%s' not found in shopping basket", item), 1, found));
61 | }
62 |
63 | private void gotoPage(String url, String expectedTitle)
64 | {
65 | driver().get(url);
66 |
67 | String title = driver().getTitle();
68 |
69 | assertEquals(expectedTitle, title);
70 | }
71 |
72 | private String getAuthor(String author)
73 | {
74 | if ("David Farley".equals(author))
75 | return "Jez Humble";
76 | else
77 | return author;
78 | }
79 |
80 | private WebDriver driver()
81 | {
82 | if (driver == null)
83 | {
84 | try
85 | {
86 | driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub/"), DesiredCapabilities.chrome());
87 | }
88 | catch (MalformedURLException e)
89 | {
90 | e.printStackTrace();
91 | }
92 | }
93 |
94 | return driver;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/acceptance-testing.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------