diff --git a/.gitignore b/.gitignore index c0d72a23e..eff9411db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -target/* .settings/* .classpath .project @@ -29,3 +28,5 @@ bin/* .coverage/* .kitchen/ .kitchen.local.yml +target +*~ diff --git a/spring-petclinic-it/.DS_Store b/spring-petclinic-it/.DS_Store new file mode 100644 index 000000000..638b0d702 Binary files /dev/null and b/spring-petclinic-it/.DS_Store differ diff --git a/spring-petclinic-it/README.md b/spring-petclinic-it/README.md new file mode 100644 index 000000000..59f752ed1 --- /dev/null +++ b/spring-petclinic-it/README.md @@ -0,0 +1,15 @@ +Requisites: +- Binary repository for GD JBehave Framework + https://nexus.griddynamics.net/nexus/content/repositories/gd_jbehave_framework-snapshots + should be added to Maven repositories in `settings.xml`. + It requires authentication so it should be configured properly. + +Run test against a remote WebDriver: + + mvn -P runTests clean test -Dthreads=1 \ + -Dsuite.all=**/*Suite.java -Dsuite.list=UITestsExampleSuite \ + -Dspring.profiles.active=remote \ + -Dmeta.filters=-not_impl,-not_in_func,-blocked,-non_ci \ + -DREMOTE_WEBDRIVER_URL=http://localhost:4444/wd/hub -Dbrowser.version= \ + -Dpetclinic.url=http://localhost:9966/petclinic + diff --git a/spring-petclinic-it/pom.xml b/spring-petclinic-it/pom.xml new file mode 100644 index 000000000..384726580 --- /dev/null +++ b/spring-petclinic-it/pom.xml @@ -0,0 +1,346 @@ + + + 4.0.0 + + pet_clinic_test_example + pet_clinic_test_example + 1.0-SNAPSHOT + + + **/DefaultWebSuite.java + + + + + + + + ${project.basedir}/src/main/resources/store.properties + + + ${project.basedir}/src/main/resources/pages.properties + + + ${project.basedir}/src/main/resources/browser.properties + + + ${project.basedir}/src/main/resources/jbehave.properties + + UTF-8 + + + 3.8 + 3.6-beta-1 + 2.34.0 + 3.1.1 + 4.11 + 3.2.4.RELEASE + 1.2.17 + 1.3 + 1.0-SNAPSHOT + + + + + + + com.griddynamics.qa + core-framework + ${gdframework.version} + + + com.griddynamics.qa + common-ui-utils + ${gdframework.version} + + + + + org.jbehave.web + jbehave-web-selenium + ${jbehave.web.version} + + + org.seleniumhq.selenium + selenium-java + + + org.jbehave + jbehave-core + + + commons-io + commons-io + + + + + org.jbehave + jbehave-core + ${jbehave.core.version} + resources + zip + + + org.jbehave.site + jbehave-site-resources + ${jbehave.site.version} + zip + + + org.jbehave + jbehave-navigator + ${jbehave.core.version} + + + + + org.seleniumhq.selenium + selenium-java + ${selenium.version} + + + commons-io + commons-io + + + + + + + + + + excludeTesting + + true + + + + + org.jbehave + jbehave-maven-plugin + + true + + + + + + + + + runTests + + false + + + + + org.jbehave + jbehave-maven-plugin + + + org.codehaus.jettison + jettison + 1.3.1 + + + + + ${suite.all} + + + + + + + + + + + + + src/main/java + true + + **/*.java + + + + src/main/resources + true + + + browser-profile + browser-profile + + + + + + org.jbehave + jbehave-maven-plugin + ${jbehave.core.version} + + + unpack-view-resources + process-resources + + unpack-view-resources + + + + embeddable-stories + + test + + run-stories-as-embeddables + + + ${jbehave.ignoreFailureInStories} + ${jbehave.ignoreFailureInView} + ${jbehave.storyTimeoutInSecs} + + + + + + + + log4j + log4j + ${log4j.version} + + + + + org.codehaus.groovy + groovy-all + 1.8.4 + + + + javax.servlet + servlet-api + 2.5 + + + + org.hamcrest + hamcrest-all + ${hamcrest.version} + + + + + + + + + org.codehaus.mojo + properties-maven-plugin + + + read + initialize + + read-project-properties + + + + ${execution.config.file.location} + ${pages.config.file.location} + ${browser.config.file.location} + ${runner.config.file.location} + + true + + + + export + initialize + + set-system-properties + + + + + execution.config.file.location + ${execution.config.file.location} + + + pages.config.file.location + ${pages.config.file.location} + + + runner.config.file.location + ${runner.config.file.location} + + + browser.config.file.location + ${browser.config.file.location} + + + jbehave.ignoreFailureInStories + ${jbehave.ignoreFailureInStories} + + + jbehave.ignoreFailureInView + ${jbehave.ignoreFailureInView} + + + jbehave.storyTimeoutInSecs + ${jbehave.storyTimeoutInSecs} + + + threads + ${threads} + + + meta.filters + ${meta.filters} + + + REMOTE_WEBDRIVER_URL + ${REMOTE_WEBDRIVER_URL} + + + browser + ${browser} + + + remoteWebDriver + ${remoteWebDriver} + + + spring.profiles.active + ${spring.profiles.active} + + + suite.all + ${suite.all} + + + suite.list + ${suite.list} + + + story.list + ${story.list} + + + exclude.story.list + ${exclude.story.list} + + + + + + + + + + \ No newline at end of file diff --git a/spring-petclinic-it/src/main/java/com/griddynamics/web/PetClinicStoreHost.java b/spring-petclinic-it/src/main/java/com/griddynamics/web/PetClinicStoreHost.java new file mode 100644 index 000000000..e6ed2e281 --- /dev/null +++ b/spring-petclinic-it/src/main/java/com/griddynamics/web/PetClinicStoreHost.java @@ -0,0 +1,21 @@ +package com.griddynamics.web; + +/** + * @author lzakharova + */ +public class PetClinicStoreHost { + + private String petClinicUrl; + + public PetClinicStoreHost() { + } + + public String getPetClinicUrl() { + return petClinicUrl; + } + + public void setPetClinicUrl(String petClinicUrl) { + this.petClinicUrl = petClinicUrl; + } + +} diff --git a/spring-petclinic-it/src/main/java/com/griddynamics/web/blocks/HeaderBlock.java b/spring-petclinic-it/src/main/java/com/griddynamics/web/blocks/HeaderBlock.java new file mode 100644 index 000000000..dffe5df35 --- /dev/null +++ b/spring-petclinic-it/src/main/java/com/griddynamics/web/blocks/HeaderBlock.java @@ -0,0 +1,23 @@ +package com.griddynamics.web.blocks; + + +import com.griddynamics.qa.ui.ElementBlock; +import org.jbehave.web.selenium.WebDriverProvider; + +import static com.griddynamics.web.blocks.HeaderBlockData.*; + +/** + * @author lzakharova + */ +public class HeaderBlock extends ElementBlock { + + public HeaderBlock(WebDriverProvider provider) { + super(provider, HEADER_BLOCK_NAME, headerBlockLoc); + + addElement(HOME_MENU, homeMenuLoc); + addElement(FIND_OWNERS_MENU, findOwnersMenuLoc); + addElement(VETERINARIANS_MENU, veterinariansMenuLoc); + addElement(ERROR_MENU, errorMenuLoc); + addElement(HELP_MENU, helpMenuLoc); + } +} diff --git a/spring-petclinic-it/src/main/java/com/griddynamics/web/blocks/HeaderBlockData.java b/spring-petclinic-it/src/main/java/com/griddynamics/web/blocks/HeaderBlockData.java new file mode 100644 index 000000000..f23c2c184 --- /dev/null +++ b/spring-petclinic-it/src/main/java/com/griddynamics/web/blocks/HeaderBlockData.java @@ -0,0 +1,31 @@ +package com.griddynamics.web.blocks; + + +import org.openqa.selenium.By; + +/** + * @author lzakharova + */ +public class HeaderBlockData { + + public final static String HEADER_BLOCK_NAME = "Header"; + public final static String HEADER_BLOCK_COMMON_LOC = "//div[@class='navbar']"; + public final static By headerBlockLoc = By.xpath(HEADER_BLOCK_COMMON_LOC); + + + public final static String HOME_MENU = "Home menu"; + public final static By homeMenuLoc = By.xpath(HEADER_BLOCK_COMMON_LOC + "//a[contains(text(), 'Home')]"); + + public final static String FIND_OWNERS_MENU = "Find owners menu"; + public final static By findOwnersMenuLoc = By.xpath(HEADER_BLOCK_COMMON_LOC + "//a[contains(text(), 'Find owners')]"); + + public final static String VETERINARIANS_MENU = "Veterinarians menu"; + public final static By veterinariansMenuLoc = By.xpath(HEADER_BLOCK_COMMON_LOC + "//a[contains(text(), 'Veterinarians')]"); + + public final static String ERROR_MENU = "Error menu"; + public final static By errorMenuLoc = By.xpath(HEADER_BLOCK_COMMON_LOC + "//a[contains(text(), 'Error')]"); + + public final static String HELP_MENU = "Help menu"; + public final static By helpMenuLoc = By.xpath(HEADER_BLOCK_COMMON_LOC + "//a[contains(text(), 'Help')]"); + +} diff --git a/spring-petclinic-it/src/main/java/com/griddynamics/web/pages/CustomPages.java b/spring-petclinic-it/src/main/java/com/griddynamics/web/pages/CustomPages.java new file mode 100644 index 000000000..158f9f62f --- /dev/null +++ b/spring-petclinic-it/src/main/java/com/griddynamics/web/pages/CustomPages.java @@ -0,0 +1,26 @@ +package com.griddynamics.web.pages; + +import com.griddynamics.qa.ui.AbstractPage; +import com.griddynamics.qa.ui.Pages; +import org.jbehave.web.selenium.WebDriverProvider; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Map; + +/** + * @author lzakharova + */ + +public class CustomPages extends Pages { + + @Autowired + private WebDriverProvider driverProvider; + + public CustomPages() { + } + + public CustomPages(WebDriverProvider driverProvider, Map pageMappings) { + this.driverProvider = driverProvider; + pagesMap.putAll(pageMappings); + } +} diff --git a/spring-petclinic-it/src/main/java/com/griddynamics/web/pages/PetClinicCommonPage.java b/spring-petclinic-it/src/main/java/com/griddynamics/web/pages/PetClinicCommonPage.java new file mode 100644 index 000000000..a443331ee --- /dev/null +++ b/spring-petclinic-it/src/main/java/com/griddynamics/web/pages/PetClinicCommonPage.java @@ -0,0 +1,116 @@ +package com.griddynamics.web.pages; + +import com.griddynamics.qa.ui.AbstractPage; +import com.griddynamics.web.PetClinicStoreHost; +import com.griddynamics.web.blocks.HeaderBlock; +import org.jbehave.web.selenium.WebDriverProvider; +import org.openqa.selenium.By; +import org.openqa.selenium.TimeoutException; +import org.springframework.beans.factory.annotation.Autowired; + +import static com.griddynamics.qa.logger.LoggerFactory.getLogger; +import static org.junit.Assert.assertTrue; + +/** + * @author lzakharova + */ + +public abstract class PetClinicCommonPage extends AbstractPage { + + public static final String PAGE_TITLE = "Page title"; + public static final By pageTitleLoc = By.xpath("//h2"); + + @Autowired + public PetClinicStoreHost petClinicStoreHost; + + + private String currentPageTitle; + private String currentPageUri; + + private HeaderBlock headerBlock; + + + protected PetClinicCommonPage(WebDriverProvider driverProvider) { + super(driverProvider); + initElements(); + } + + protected PetClinicCommonPage(WebDriverProvider driverProvider, String currentPageUri, String currentPageTitle) { + this(driverProvider); + setCurrentPageUri(currentPageUri); + setCurrentPageTitle(currentPageTitle); + initElements(); + } + + private void initElements() { + addElement(PAGE_TITLE, pageTitleLoc); + + headerBlock = new HeaderBlock(getDriverProvider()); + + addBlock(headerBlock); + } + + public String getBaseURL() { + return petClinicStoreHost.getPetClinicUrl(); + } + + + public String getCurrentPageTitle() { + return currentPageTitle; + } + + public void setCurrentPageTitle(String currentPageTitle) { + this.currentPageTitle = currentPageTitle; + } + + public String getCurrentPageUri() { + return currentPageUri; + } + + public void setCurrentPageUri(String currentPageUri) { + this.currentPageUri = currentPageUri; + } + + protected String getPageRelativeURL() { + return currentPageUri; + } + + @Override + public String getPageURL() { + return getBaseURL() + ("/" + getPageRelativeURL()).replaceAll("//", "/"); + } + + @Override + public boolean checkCurrentPage() { + return checkURL() ; + } + + @Override + public void assertCurrentPage() { + assertTrue("AssertPage Failed due to wrong URL OR mandatory element absence. " + + "Expected URL: " + getPageURL() + "; Got: " + getCurrentUrl(), + checkCurrentPage()); + } + + @Override + public void openPage() { + int timeoutExc = 0; + int attempt = 0; + while (timeoutExc < PAGE_OPEN_ATTEMPTS_NUMBER) { + int i = 1; + try { + while (!checkCurrentPage() && i <= PAGE_OPEN_ATTEMPTS_NUMBER) { + attempt++; + open(attempt); + i++; + } + } catch (TimeoutException e) { + timeoutExc++; + getLogger().info("Caught TimeoutException. " + e.getMessage()); + continue; + } + timeoutExc = PAGE_OPEN_ATTEMPTS_NUMBER; + } + assertCurrentPage(); + } +} diff --git a/spring-petclinic-it/src/main/java/com/griddynamics/web/pages/PetClinicFindOwnersPage.java b/spring-petclinic-it/src/main/java/com/griddynamics/web/pages/PetClinicFindOwnersPage.java new file mode 100644 index 000000000..4cf1c7746 --- /dev/null +++ b/spring-petclinic-it/src/main/java/com/griddynamics/web/pages/PetClinicFindOwnersPage.java @@ -0,0 +1,37 @@ +package com.griddynamics.web.pages; + +import org.jbehave.web.selenium.WebDriverProvider; +import org.openqa.selenium.By; + +import static org.junit.Assert.assertTrue; + +/** + * @author lzakharova + */ +public class PetClinicFindOwnersPage extends PetClinicCommonPage { + + public static final String FIND_OWNER_FIELD = "Find Owner field"; + public static final By findOwnerFieldLoc = By.xpath("//input[@id='lastName']"); + + public static final String FIND_OWNER_BUTTON = "Find Owner button"; + public static final By findOwnerButtonLoc = By.xpath("//button[@type='submit']"); + + public static final String OWNERS_TABLE = "Owners table"; + public static final By ownersTableLoc = By.xpath("//table[@id='owners']"); + + + public PetClinicFindOwnersPage(WebDriverProvider driverProvider, String currentPageUri, String currentPageTitle) { + super(driverProvider, currentPageUri, currentPageTitle); + + addElement(FIND_OWNER_FIELD, findOwnerFieldLoc); + addElement(FIND_OWNER_BUTTON, findOwnerButtonLoc); + addElement(OWNERS_TABLE, ownersTableLoc); + } + + @Override + public void assertCurrentPage() { + super.assertCurrentPage(); + assertTrue(PAGE_TITLE + " is not displayed", isElementDisplayedOnPage(PAGE_TITLE)); + } +} + diff --git a/spring-petclinic-it/src/main/java/com/griddynamics/web/pages/PetClinicHomePage.java b/spring-petclinic-it/src/main/java/com/griddynamics/web/pages/PetClinicHomePage.java new file mode 100644 index 000000000..7fa337743 --- /dev/null +++ b/spring-petclinic-it/src/main/java/com/griddynamics/web/pages/PetClinicHomePage.java @@ -0,0 +1,22 @@ +package com.griddynamics.web.pages; + +import org.jbehave.web.selenium.WebDriverProvider; + +import static org.junit.Assert.assertTrue; + +/** + * @author lzakharova + */ +public class PetClinicHomePage extends PetClinicCommonPage { + + public PetClinicHomePage(WebDriverProvider driverProvider, String currentPageUri, String currentPageTitle) { + super(driverProvider, currentPageUri, currentPageTitle); + } + + @Override + public void assertCurrentPage() { + super.assertCurrentPage(); + assertTrue(PAGE_TITLE + " is not displayed", isElementDisplayedOnPage(PAGE_TITLE)); + } +} + diff --git a/spring-petclinic-it/src/main/java/com/griddynamics/web/suits/UITestsExampleSuite.java b/spring-petclinic-it/src/main/java/com/griddynamics/web/suits/UITestsExampleSuite.java new file mode 100755 index 000000000..4277e2dee --- /dev/null +++ b/spring-petclinic-it/src/main/java/com/griddynamics/web/suits/UITestsExampleSuite.java @@ -0,0 +1,41 @@ +package com.griddynamics.web.suits; + + +import com.griddynamics.qa.framework.WebStoriesRunner; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author lzakharova + */ + +public class UITestsExampleSuite extends WebStoriesRunner { + protected static String contextPath = "/com/griddynamics/context/webApplicationContext.xml"; + + public UITestsExampleSuite() { + super(contextPath); + } + + @Override + protected List excludeStories() { + return new ArrayList() { + { + add("**/web/**/*Given*.story"); + } + }; + } + + @Override + protected List includeStories() { + return new ArrayList() { + { + add("**/stories/uitests/**/**.story"); + } + }; + } + + @Override + public void beforeRun() { + } +} diff --git a/spring-petclinic-it/src/main/resources/browser.properties b/spring-petclinic-it/src/main/resources/browser.properties new file mode 100644 index 000000000..15deafb09 --- /dev/null +++ b/spring-petclinic-it/src/main/resources/browser.properties @@ -0,0 +1,10 @@ +#Merged +#Fri Oct 04 02:59:15 CDT 2013 +browser.proxy.ip= +browser.proxy.port=8080 +browser.proxy.user=test +browser.proxy.password=test +page.timeout.ms=70000 + + + diff --git a/spring-petclinic-it/src/main/resources/com/griddynamics/context/pagesBeans.xml b/spring-petclinic-it/src/main/resources/com/griddynamics/context/pagesBeans.xml new file mode 100755 index 000000000..945637dea --- /dev/null +++ b/spring-petclinic-it/src/main/resources/com/griddynamics/context/pagesBeans.xml @@ -0,0 +1,45 @@ + + + + + + + ${petClinicHomePageTitle} + + + ${petClinicHomePageUrl} + + + + + + + ${petClinicFindOwnersPageTitle} + + + ${petClinicFindOwnersPageUrl} + + + + + + + + + + + + + + + + + + + diff --git a/spring-petclinic-it/src/main/resources/com/griddynamics/context/uiPropertiesContext.xml b/spring-petclinic-it/src/main/resources/com/griddynamics/context/uiPropertiesContext.xml new file mode 100644 index 000000000..2783d984d --- /dev/null +++ b/spring-petclinic-it/src/main/resources/com/griddynamics/context/uiPropertiesContext.xml @@ -0,0 +1,20 @@ + + + + + + + classpath:pages.properties + classpath:store.properties + classpath:browser.properties + classpath:jbehave.properties + + + + + diff --git a/spring-petclinic-it/src/main/resources/com/griddynamics/context/webApplicationContext.xml b/spring-petclinic-it/src/main/resources/com/griddynamics/context/webApplicationContext.xml new file mode 100755 index 000000000..af5259ebe --- /dev/null +++ b/spring-petclinic-it/src/main/resources/com/griddynamics/context/webApplicationContext.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${petclinic.url} + + + + + + + + + + + + + diff --git a/spring-petclinic-it/src/main/resources/com/griddynamics/stories/uitests/CheckHomePage.story b/spring-petclinic-it/src/main/resources/com/griddynamics/stories/uitests/CheckHomePage.story new file mode 100644 index 000000000..ad3b2ec19 --- /dev/null +++ b/spring-petclinic-it/src/main/resources/com/griddynamics/stories/uitests/CheckHomePage.story @@ -0,0 +1,8 @@ +Meta: +@smoke + + +Scenario: Check Home Page + +Given customer is on Pet Clinic Home Page +Then element Page title has text Welcome \ No newline at end of file diff --git a/spring-petclinic-it/src/main/resources/com/griddynamics/stories/uitests/FindOwner.story b/spring-petclinic-it/src/main/resources/com/griddynamics/stories/uitests/FindOwner.story new file mode 100644 index 000000000..b14395f0f --- /dev/null +++ b/spring-petclinic-it/src/main/resources/com/griddynamics/stories/uitests/FindOwner.story @@ -0,0 +1,12 @@ +Meta: +@smoke + + +Scenario: Check Find Owner Page + +Given customer is on Pet Clinic Home Page +When customer clicks Find owners menu +Then Pet Clinic Find Owners Page is opened + +When customer clicks Find Owner button +Then Owners table is displayed on page diff --git a/spring-petclinic-it/src/main/resources/jbehave.properties b/spring-petclinic-it/src/main/resources/jbehave.properties new file mode 100644 index 000000000..5a6e00de5 --- /dev/null +++ b/spring-petclinic-it/src/main/resources/jbehave.properties @@ -0,0 +1,8 @@ +#Merged +#Fri Oct 04 02:59:19 CDT 2013 +browser=firefox +jbehave.ignoreFailureInView=true +spring.profiles.active=local +jbehave.ignoreFailureInStories=true +jbehave.storyTimeoutInSecs=5500 +threads=1 diff --git a/spring-petclinic-it/src/main/resources/log4j.properties b/spring-petclinic-it/src/main/resources/log4j.properties new file mode 100644 index 000000000..a5f2f7e93 --- /dev/null +++ b/spring-petclinic-it/src/main/resources/log4j.properties @@ -0,0 +1,7 @@ +# ***** Set root logger level to INFO and its three appenders +log4j.rootLogger=INFO, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %p (%t) (%F:%L) - %m%n + diff --git a/spring-petclinic-it/src/main/resources/pages.properties b/spring-petclinic-it/src/main/resources/pages.properties new file mode 100644 index 000000000..5670a5663 --- /dev/null +++ b/spring-petclinic-it/src/main/resources/pages.properties @@ -0,0 +1,5 @@ +petClinicHomePageUrl=/ +petClinicHomePageTitle=PetClinic :: a Spring Framework demonstration + +petClinicFindOwnersPageUrl=/owners/find.html +petClinicFindOwnersPageTitle=PetClinic :: a Spring Framework demonstration diff --git a/spring-petclinic-it/src/main/resources/store.properties b/spring-petclinic-it/src/main/resources/store.properties new file mode 100644 index 000000000..c2eb8972d --- /dev/null +++ b/spring-petclinic-it/src/main/resources/store.properties @@ -0,0 +1,2 @@ +#petclinic.url=http://localhost:9966/petclinic +