From 01fdbd1940ec456e4d4f5c792106f7530af4fcad Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Thu, 28 Feb 2013 17:11:35 +0400 Subject: [PATCH 01/31] Updating dependencies to the latest versions --- src/main/resources/archetype-resources/pom.xml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index c167ee5..9b3a919 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -10,17 +10,22 @@ org.testng testng - 6.3 + 6.8 + + + junit + junit + 4.11 org.seleniumhq.selenium selenium-java - 2.12.0 + 2.31.0 com.opera operadriver - 0.7.3 + 1.2 From 2094157042fa28dad736347957333f1e91cdcde8 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Fri, 1 Mar 2013 16:36:44 +0400 Subject: [PATCH 02/31] Updating operadriver version --- src/main/resources/archetype-resources/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index 9b3a919..07a5a89 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -25,7 +25,7 @@ com.opera operadriver - 1.2 + 1.1 From a2f20fb48f99f19675bff802f3aff3c0c53ebe8f Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Thu, 7 Mar 2013 18:13:03 +0400 Subject: [PATCH 03/31] Using more typical names for driver and baseUrl --- .../src/test/java/pages/HomePageTest.java | 2 +- .../src/test/java/pages/TestBase.java | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java b/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java index 2567afc..0ede6bb 100644 --- a/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java +++ b/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java @@ -18,7 +18,7 @@ public class HomePageTest extends TestBase { public void testInit(String path) { // Load the page in the browser - webDriver.get(websiteUrl + path); + webDriver.get(baseUrl + path); homepage = PageFactory.initElements(webDriver, HomePage.class); } diff --git a/src/main/resources/archetype-resources/src/test/java/pages/TestBase.java b/src/main/resources/archetype-resources/src/test/java/pages/TestBase.java index 167a43a..84a130e 100644 --- a/src/main/resources/archetype-resources/src/test/java/pages/TestBase.java +++ b/src/main/resources/archetype-resources/src/test/java/pages/TestBase.java @@ -32,17 +32,17 @@ public class TestBase { private static final String SCREENSHOT_FOLDER = "target/screenshots/"; private static final String SCREENSHOT_FORMAT = ".png"; - protected WebDriver webDriver; + protected WebDriver driver; protected String gridHubUrl; - protected String websiteUrl; + protected String baseUrl; protected Browser browser; @BeforeClass public void init() { - websiteUrl = PropertyLoader.loadProperty("site.url"); + baseUrl = PropertyLoader.loadProperty("site.url"); gridHubUrl = PropertyLoader.loadProperty("grid2.hub"); browser = new Browser(); @@ -53,15 +53,15 @@ public void init() { String username = PropertyLoader.loadProperty("user.username"); String password = PropertyLoader.loadProperty("user.password"); - webDriver = WebDriverFactory.getInstance(gridHubUrl, browser, username, + driver = WebDriverFactory.getInstance(gridHubUrl, browser, username, password); - webDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); + driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } @AfterSuite(alwaysRun = true) public void tearDown() { - if (webDriver != null) { - webDriver.quit(); + if (driver != null) { + driver.quit(); } } @@ -69,7 +69,7 @@ public void tearDown() { // public void setScreenshot(ITestResult result) { // if (!result.isSuccess()) { // try { -// WebDriver returned = new Augmenter().augment(webDriver); +// WebDriver returned = new Augmenter().augment(driver); // if (returned != null) { // File f = ((TakesScreenshot) returned) // .getScreenshotAs(OutputType.FILE); From c95b2df86eae70bf858fa89e555802f8301f1eeb Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Thu, 7 Mar 2013 18:23:38 +0400 Subject: [PATCH 04/31] Fixing another use of webDriver field --- .../archetype-resources/src/test/java/pages/HomePageTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java b/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java index 0ede6bb..04d2045 100644 --- a/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java +++ b/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java @@ -18,7 +18,7 @@ public class HomePageTest extends TestBase { public void testInit(String path) { // Load the page in the browser - webDriver.get(baseUrl + path); + driver.get(baseUrl + path); homepage = PageFactory.initElements(webDriver, HomePage.class); } From 076c0cbb608eacf7265d32c8dd3234ada55403e5 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Thu, 7 Mar 2013 18:23:38 +0400 Subject: [PATCH 05/31] Fixing another use of webDriver field --- .../archetype-resources/src/test/java/pages/HomePageTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java b/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java index 0ede6bb..402e981 100644 --- a/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java +++ b/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java @@ -18,8 +18,8 @@ public class HomePageTest extends TestBase { public void testInit(String path) { // Load the page in the browser - webDriver.get(baseUrl + path); - homepage = PageFactory.initElements(webDriver, HomePage.class); + driver.get(baseUrl + path); + homepage = PageFactory.initElements(driver, HomePage.class); } @Test From 96fee9faee878306881672504461e188cbe05ffb Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Thu, 7 Mar 2013 18:38:45 +0400 Subject: [PATCH 06/31] Making WebDriver factory to use the singleton driver object for local drivers --- .../src/main/java/webdriver/WebDriverFactory.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java index 17f4935..f393ff8 100644 --- a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java +++ b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java @@ -48,6 +48,8 @@ public class WebDriverFactory { public static final String MAC = "mac"; public static final String LINUX = "linux"; + private static WebDriver webDriver = null; + /* * Factory method to return a RemoteWebDriver instance given the url of the * Grid hub and a Browser instance. @@ -145,7 +147,9 @@ public static WebDriver getInstance(String gridHubUrl, Browser browser, public static WebDriver getInstance(String browser, String username, String password) { - WebDriver webDriver = null; + if (webDriver != null) { + return webDriver; + } if (CHROME.equals(browser)) { setChromeDriver(); From 0c434e21f30b4a96ceee250b5c58ee8ffba92ced Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Sat, 9 Mar 2013 14:55:03 +0400 Subject: [PATCH 07/31] Updating OperaDriver version to 1.2 --- README.md | 2 +- src/main/resources/archetype-resources/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1409bd3..eb3fcf2 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Now, you can use the archetype in a new project typing: where *mygroupId* : group id of the project you are creating; *myartifactId* : artifact id of the project you are creating -It uses Java bindings for Selenium version 2.12.0, OperaDriver version 0.7.3 and TestNG version 6.3. +It uses Java bindings for Selenium version 2.31.0, OperaDriver version 1.2 and TestNG version 6.8. Project Structure diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index 07a5a89..9b3a919 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -25,7 +25,7 @@ com.opera operadriver - 1.1 + 1.2 From 71769ebdb73125890f9769e0a1bacf7a9c33209f Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Sat, 9 Mar 2013 14:57:35 +0400 Subject: [PATCH 08/31] Normalizing line endings --- .gitattributes | 22 +++ .../src/main/java/pages/Page.java | 68 +++---- .../src/main/java/util/Browser.java | 80 ++++---- .../src/test/java/pages/HomePageTest.java | 68 +++---- .../src/test/java/pages/TestBase.java | 176 +++++++++--------- .../src/test/resources/testng.xml | 24 +-- 6 files changed, 230 insertions(+), 208 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/src/main/resources/archetype-resources/src/main/java/pages/Page.java b/src/main/resources/archetype-resources/src/main/java/pages/Page.java index 0821b25..bb43ab7 100644 --- a/src/main/resources/archetype-resources/src/main/java/pages/Page.java +++ b/src/main/resources/archetype-resources/src/main/java/pages/Page.java @@ -1,34 +1,34 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${groupId}.pages; - -import org.openqa.selenium.WebDriver; - -/* - * Abstract class representation of a Page in the UI. Page object pattern - * - * @author Sebastiano Armeli-Battana - */ -public abstract class Page { - - protected WebDriver webDriver; - - /* - * Constructor injecting the WebDriver interface - * - * @param webDriver - */ - public Page(WebDriver webDriver) { - this.webDriver = webDriver; - } - - public WebDriver getWebDriver() { - return webDriver; - } - - public String getTitle() { - return webDriver.getTitle(); - } - -} +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${groupId}.pages; + +import org.openqa.selenium.WebDriver; + +/* + * Abstract class representation of a Page in the UI. Page object pattern + * + * @author Sebastiano Armeli-Battana + */ +public abstract class Page { + + protected WebDriver webDriver; + + /* + * Constructor injecting the WebDriver interface + * + * @param webDriver + */ + public Page(WebDriver webDriver) { + this.webDriver = webDriver; + } + + public WebDriver getWebDriver() { + return webDriver; + } + + public String getTitle() { + return webDriver.getTitle(); + } + +} diff --git a/src/main/resources/archetype-resources/src/main/java/util/Browser.java b/src/main/resources/archetype-resources/src/main/java/util/Browser.java index 8771941..ae96cec 100644 --- a/src/main/resources/archetype-resources/src/main/java/util/Browser.java +++ b/src/main/resources/archetype-resources/src/main/java/util/Browser.java @@ -1,41 +1,41 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${groupId}.util; - -/* - * Bean representing a browser. It contains name, version and platform fields. - * - * @author Sebastiano Armeli-Battana - */ -public class Browser { - - private String name; - private String version; - private String platform; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getPlatform() { - return platform; - } - - public void setPlatform(String platform) { - this.platform = platform; - } - +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${groupId}.util; + +/* + * Bean representing a browser. It contains name, version and platform fields. + * + * @author Sebastiano Armeli-Battana + */ +public class Browser { + + private String name; + private String version; + private String platform; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + } \ No newline at end of file diff --git a/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java b/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java index 402e981..80e5e68 100644 --- a/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java +++ b/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java @@ -1,34 +1,34 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${groupId}.pages; - -import org.openqa.selenium.support.PageFactory; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - -public class HomePageTest extends TestBase { - - HomePage homepage; - - @Parameters({ "path" }) - @BeforeClass - public void testInit(String path) { - - // Load the page in the browser - driver.get(baseUrl + path); - homepage = PageFactory.initElements(driver, HomePage.class); - } - - @Test - public void testH1Existing() throws InterruptedException { - Assert.assertTrue(homepage.getH1() != null); - } - - @Test - public void test2() throws InterruptedException { - Assert.assertTrue(true); - } -} +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${groupId}.pages; + +import org.openqa.selenium.support.PageFactory; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +public class HomePageTest extends TestBase { + + HomePage homepage; + + @Parameters({ "path" }) + @BeforeClass + public void testInit(String path) { + + // Load the page in the browser + driver.get(baseUrl + path); + homepage = PageFactory.initElements(driver, HomePage.class); + } + + @Test + public void testH1Existing() throws InterruptedException { + Assert.assertTrue(homepage.getH1() != null); + } + + @Test + public void test2() throws InterruptedException { + Assert.assertTrue(true); + } +} diff --git a/src/main/resources/archetype-resources/src/test/java/pages/TestBase.java b/src/main/resources/archetype-resources/src/test/java/pages/TestBase.java index 84a130e..7e6d1d3 100644 --- a/src/main/resources/archetype-resources/src/test/java/pages/TestBase.java +++ b/src/main/resources/archetype-resources/src/test/java/pages/TestBase.java @@ -1,88 +1,88 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${groupId}.pages; - -import java.io.File; -import java.io.IOException; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.io.FileUtils; -import org.openqa.selenium.OutputType; -import org.openqa.selenium.TakesScreenshot; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.Augmenter; -import org.openqa.selenium.remote.ScreenshotException; -import org.testng.ITestResult; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.AfterSuite; -import org.testng.annotations.BeforeClass; - -import ${groupId}.util.PropertyLoader; -import ${groupId}.util.Browser; -import ${groupId}.webdriver.WebDriverFactory; - -/* - * Base class for all the test classes - * - * @author Sebastiano Armeli-Battana - */ - -public class TestBase { - private static final String SCREENSHOT_FOLDER = "target/screenshots/"; - private static final String SCREENSHOT_FORMAT = ".png"; - - protected WebDriver driver; - - protected String gridHubUrl; - - protected String baseUrl; - - protected Browser browser; - - @BeforeClass - public void init() { - baseUrl = PropertyLoader.loadProperty("site.url"); - gridHubUrl = PropertyLoader.loadProperty("grid2.hub"); - - browser = new Browser(); - browser.setName(PropertyLoader.loadProperty("browser.name")); - browser.setVersion(PropertyLoader.loadProperty("browser.version")); - browser.setPlatform(PropertyLoader.loadProperty("browser.platform")); - - String username = PropertyLoader.loadProperty("user.username"); - String password = PropertyLoader.loadProperty("user.password"); - - driver = WebDriverFactory.getInstance(gridHubUrl, browser, username, - password); - driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); - } - - @AfterSuite(alwaysRun = true) - public void tearDown() { - if (driver != null) { - driver.quit(); - } - } - -// @AfterMethod -// public void setScreenshot(ITestResult result) { -// if (!result.isSuccess()) { -// try { -// WebDriver returned = new Augmenter().augment(driver); -// if (returned != null) { -// File f = ((TakesScreenshot) returned) -// .getScreenshotAs(OutputType.FILE); -// try { -// FileUtils.copyFile(f, new File(SCREENSHOT_FOLDER -// + result.getName() + SCREENSHOT_FORMAT)); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// } -// } catch (ScreenshotException se) { -// se.printStackTrace(); -// } -// } -// } -} +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${groupId}.pages; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.io.FileUtils; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.remote.Augmenter; +import org.openqa.selenium.remote.ScreenshotException; +import org.testng.ITestResult; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.AfterSuite; +import org.testng.annotations.BeforeClass; + +import ${groupId}.util.PropertyLoader; +import ${groupId}.util.Browser; +import ${groupId}.webdriver.WebDriverFactory; + +/* + * Base class for all the test classes + * + * @author Sebastiano Armeli-Battana + */ + +public class TestBase { + private static final String SCREENSHOT_FOLDER = "target/screenshots/"; + private static final String SCREENSHOT_FORMAT = ".png"; + + protected WebDriver driver; + + protected String gridHubUrl; + + protected String baseUrl; + + protected Browser browser; + + @BeforeClass + public void init() { + baseUrl = PropertyLoader.loadProperty("site.url"); + gridHubUrl = PropertyLoader.loadProperty("grid2.hub"); + + browser = new Browser(); + browser.setName(PropertyLoader.loadProperty("browser.name")); + browser.setVersion(PropertyLoader.loadProperty("browser.version")); + browser.setPlatform(PropertyLoader.loadProperty("browser.platform")); + + String username = PropertyLoader.loadProperty("user.username"); + String password = PropertyLoader.loadProperty("user.password"); + + driver = WebDriverFactory.getInstance(gridHubUrl, browser, username, + password); + driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); + } + + @AfterSuite(alwaysRun = true) + public void tearDown() { + if (driver != null) { + driver.quit(); + } + } + +// @AfterMethod +// public void setScreenshot(ITestResult result) { +// if (!result.isSuccess()) { +// try { +// WebDriver returned = new Augmenter().augment(driver); +// if (returned != null) { +// File f = ((TakesScreenshot) returned) +// .getScreenshotAs(OutputType.FILE); +// try { +// FileUtils.copyFile(f, new File(SCREENSHOT_FOLDER +// + result.getName() + SCREENSHOT_FORMAT)); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// } catch (ScreenshotException se) { +// se.printStackTrace(); +// } +// } +// } +} diff --git a/src/main/resources/archetype-resources/src/test/resources/testng.xml b/src/main/resources/archetype-resources/src/test/resources/testng.xml index a0e5b10..af7a292 100644 --- a/src/main/resources/archetype-resources/src/test/resources/testng.xml +++ b/src/main/resources/archetype-resources/src/test/resources/testng.xml @@ -1,13 +1,13 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) - - - - - - - - - +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + \ No newline at end of file From 800a0c31a1b59e7334438bd6085d47efcdd35027 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Sun, 10 Mar 2013 22:47:13 +0400 Subject: [PATCH 09/31] Fixing link to the repository in the instruction --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb3fcf2..8a56e6e 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This project provides just a starting point to get up to speed with Selenium 2 i To install the archetype in your local repo: - git clone git://github.com/sebarmeli/Selenium2-Java-QuickStart-Archetype.git + git clone git://github.com/barancev/Selenium2-Java-QuickStart-Archetype.git cd Selenium2-Java-Quickstart-Archetype mvn install From 5e71172891c14342175c38c2559bb5c42cd6f877 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Wed, 13 Mar 2013 01:18:08 +0400 Subject: [PATCH 10/31] Adding Safari support --- .../src/main/java/webdriver/WebDriverFactory.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java index f393ff8..9c0bbfc 100644 --- a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java +++ b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java @@ -15,6 +15,7 @@ import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.iphone.IPhoneDriver; +import org.openqa.selenium.safari.SafariDriver; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; @@ -38,6 +39,7 @@ public class WebDriverFactory { public static final String OPERA = "opera"; public static final String INTERNET_EXPLORER = "ie"; public static final String HTML_UNIT = "htmlunit"; + public static final String SAFARI = "safari"; public static final String IPHONE = "iphone"; /* Platform constants */ @@ -102,6 +104,8 @@ public static WebDriver getInstance(String gridHubUrl, Browser browser, true); } else if (OPERA.equals(browserName)) { capability = DesiredCapabilities.opera(); + } else if (SAFARI.equals(browserName)) { + capability = DesiredCapabilities.safari(); } else if (ANDROID.equals(browserName)) { capability = DesiredCapabilities.android(); } else if (IPHONE.equals(browserName)) { @@ -173,6 +177,9 @@ public static WebDriver getInstance(String browser, String username, } else if (OPERA.equals(browser)) { webDriver = new OperaDriver(); + } else if (SAFARI.equals(browser)) { + webDriver = new Safaririver(); + } else if (IPHONE.equals(browser)) { try { webDriver = new IPhoneDriver(); From 44f8b04900e0e727cdc55b210755cdf78d4a8c48 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Wed, 13 Mar 2013 01:21:52 +0400 Subject: [PATCH 11/31] Changing mind to use an external chromedriver --- README.md | 7 ------- .../resources/META-INF/maven/archetype-metadata.xml | 3 --- .../src/main/java/webdriver/WebDriverFactory.java | 13 +------------ .../src/main/resources/drivers/chrome/README.txt | 4 ---- 4 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 src/main/resources/archetype-resources/src/main/resources/drivers/chrome/README.txt diff --git a/README.md b/README.md index 8a56e6e..381ba3d 100644 --- a/README.md +++ b/README.md @@ -48,13 +48,6 @@ In the TestBase class, I commented out the method launched after the suite runs funcitonality. (at the moment it's not supported on mobile devices) -Adding Chrome Driver to the project ------------------------------------ - -If you need to use chromedriver, you should put the proper driver file downloaded from http://code.google.com/p/chromium/downloads/list into *src/main/resources/drivers/chrome*. If you are on Windows, the file should be named *chromedriver.exe*, -if on Unix-based system, the file should be named *chromedriver*. - - TestNG ------ For more info around TestNG framework, go to http://testng.org/doc/index.html. If you prefer, you could substitute this framework with JUnit. diff --git a/src/main/resources/META-INF/maven/archetype-metadata.xml b/src/main/resources/META-INF/maven/archetype-metadata.xml index 47faca4..aef48b1 100644 --- a/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -22,9 +22,6 @@ src/main/resources - - src/main/resources/drivers/chrome/ - src/main/resources/grid2 diff --git a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java index 9c0bbfc..15b2477 100644 --- a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java +++ b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java @@ -156,9 +156,8 @@ public static WebDriver getInstance(String browser, String username, } if (CHROME.equals(browser)) { - setChromeDriver(); - webDriver = new ChromeDriver(); + } else if (FIREFOX.equals(browser)) { FirefoxProfile ffProfile = new FirefoxProfile(); @@ -240,14 +239,4 @@ private static DesiredCapabilities setVersionAndPlatform( return capability; } - /* - * Helper method to set ChromeDriver location into the right ststem property - */ - private static void setChromeDriver() { - String os = System.getProperty("os.name").toLowerCase().substring(0, 3); - String chromeBinary = "src/main/resources/drivers/chrome/chromedriver" - + (os.equals("win") ? ".exe" : ""); - System.setProperty("webdriver.chrome.driver", chromeBinary); - } - } \ No newline at end of file diff --git a/src/main/resources/archetype-resources/src/main/resources/drivers/chrome/README.txt b/src/main/resources/archetype-resources/src/main/resources/drivers/chrome/README.txt deleted file mode 100644 index 1e240e9..0000000 --- a/src/main/resources/archetype-resources/src/main/resources/drivers/chrome/README.txt +++ /dev/null @@ -1,4 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -Place in this folder the chrome driver for your OS (chromedriver.exe for Win or chromedriver for Mac or Linux) if you need it. \ No newline at end of file From 4ad5a57ed2fcabc0945c7874d1753d8fedde5a0d Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Tue, 19 Mar 2013 22:50:08 +0400 Subject: [PATCH 12/31] Fixing SafariDriver class name --- .../src/main/java/webdriver/WebDriverFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java index 15b2477..8120248 100644 --- a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java +++ b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java @@ -177,7 +177,7 @@ public static WebDriver getInstance(String browser, String username, webDriver = new OperaDriver(); } else if (SAFARI.equals(browser)) { - webDriver = new Safaririver(); + webDriver = new SafariDriver(); } else if (IPHONE.equals(browser)) { try { From a7c28bee9bba0cfd016c32cb1034046aeea7b3ef Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Wed, 17 Apr 2013 18:21:02 +0400 Subject: [PATCH 13/31] Updating versions of selenium and other dependencies --- pom.xml | 2 +- src/main/resources/archetype-resources/pom.xml | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 2b189e5..c7b2d71 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ 4.0.0 com.sebarmeli selenium2-java-quickstart-archetype - 0.2 + 0.3 Selenium2 Java QuickStart Archetype maven-archetype Generates a QuickStart project with Selenium 2 and TestNG diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index 9b3a919..46f5733 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -10,7 +10,7 @@ org.testng testng - 6.8 + 6.8.1 junit @@ -20,7 +20,7 @@ org.seleniumhq.selenium selenium-java - 2.31.0 + 2.32.0 com.opera @@ -39,13 +39,14 @@ org.apache.maven.plugins maven-resources-plugin - 2.3 + 2.6 UTF-8 maven-surefire-plugin + 2.14.1 src/test/resources/testng.xml @@ -54,7 +55,7 @@ maven-compiler-plugin - 2.3.2 + 3.1 1.6 1.6 From 0bc082c549d20a434d641b6916fdda0aca85901b Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Sun, 21 Apr 2013 20:32:07 +0400 Subject: [PATCH 14/31] Fixed version number in the documentation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 381ba3d..5dd3b12 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,11 @@ To install the archetype in your local repo: Now, you can use the archetype in a new project typing: - mvn archetype:generate -DarchetypeGroupId=com.sebarmeli -DarchetypeArtifactId=selenium2-java-quickstart-archetype -DarchetypeVersion=0.2 -DgroupId= -DartifactId= + mvn archetype:generate -DarchetypeGroupId=com.sebarmeli -DarchetypeArtifactId=selenium2-java-quickstart-archetype -DarchetypeVersion=0.3 -DgroupId= -DartifactId= where *mygroupId* : group id of the project you are creating; *myartifactId* : artifact id of the project you are creating -It uses Java bindings for Selenium version 2.31.0, OperaDriver version 1.2 and TestNG version 6.8. +It uses Java bindings for Selenium version 2.32.0, OperaDriver version 1.3 and TestNG version 6.8. Project Structure From f316ebbf3d0c83a5ebae86ad7e36d73b227204c0 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Mon, 27 May 2013 11:52:36 +0400 Subject: [PATCH 15/31] Updating versions of selenium (2.33) and operadriver (1.3) --- README.md | 4 ++-- pom.xml | 2 +- src/main/resources/archetype-resources/pom.xml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5dd3b12..fa397eb 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,11 @@ To install the archetype in your local repo: Now, you can use the archetype in a new project typing: - mvn archetype:generate -DarchetypeGroupId=com.sebarmeli -DarchetypeArtifactId=selenium2-java-quickstart-archetype -DarchetypeVersion=0.3 -DgroupId= -DartifactId= + mvn archetype:generate -DarchetypeGroupId=com.sebarmeli -DarchetypeArtifactId=selenium2-java-quickstart-archetype -DarchetypeVersion=0.4 -DgroupId= -DartifactId= where *mygroupId* : group id of the project you are creating; *myartifactId* : artifact id of the project you are creating -It uses Java bindings for Selenium version 2.32.0, OperaDriver version 1.3 and TestNG version 6.8. +It uses Java bindings for Selenium version 2.33.0, OperaDriver version 1.3 and TestNG version 6.8. Project Structure diff --git a/pom.xml b/pom.xml index c7b2d71..479a269 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ 4.0.0 com.sebarmeli selenium2-java-quickstart-archetype - 0.3 + 0.4 Selenium2 Java QuickStart Archetype maven-archetype Generates a QuickStart project with Selenium 2 and TestNG diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index 46f5733..e79d13d 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -20,12 +20,12 @@ org.seleniumhq.selenium selenium-java - 2.32.0 + 2.33.0 com.opera operadriver - 1.2 + 1.3 From 5424775c5dc395264b7ba8d8567d07422cab3d5f Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Thu, 15 Aug 2013 19:02:01 +0400 Subject: [PATCH 16/31] Updated for 2.35 --- src/main/resources/archetype-resources/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index e79d13d..6fc7daf 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -10,7 +10,7 @@ org.testng testng - 6.8.1 + 6.8.5 junit @@ -20,12 +20,12 @@ org.seleniumhq.selenium selenium-java - 2.33.0 + 2.35.0 com.opera operadriver - 1.3 + 1.4 From 727dbb9ce0e53d86ad3b4fefe354176f9a75d534 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Fri, 23 Aug 2013 17:10:44 +0400 Subject: [PATCH 17/31] 1) Added support for PhantomJS, 2) Updated OperaDriver to 1.5 --- README.md | 4 +- pom.xml | 4 +- .../resources/archetype-resources/pom.xml | 257 +++++++++--------- .../main/java/webdriver/WebDriverFactory.java | 8 + 4 files changed, 148 insertions(+), 125 deletions(-) diff --git a/README.md b/README.md index fa397eb..52f7a38 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,11 @@ To install the archetype in your local repo: Now, you can use the archetype in a new project typing: - mvn archetype:generate -DarchetypeGroupId=com.sebarmeli -DarchetypeArtifactId=selenium2-java-quickstart-archetype -DarchetypeVersion=0.4 -DgroupId= -DartifactId= + mvn archetype:generate -DarchetypeGroupId=ru.st.selenium -DarchetypeArtifactId=selenium2-java-quickstart-archetype -DarchetypeVersion=0.5 -DgroupId= -DartifactId= where *mygroupId* : group id of the project you are creating; *myartifactId* : artifact id of the project you are creating -It uses Java bindings for Selenium version 2.33.0, OperaDriver version 1.3 and TestNG version 6.8. +It uses Java bindings for Selenium version 2.35.0, OperaDriver version 1.5, PhantomJSDriver 1.0.4 and TestNG version 6.8.5. Project Structure diff --git a/pom.xml b/pom.xml index 479a269..7b31c55 100644 --- a/pom.xml +++ b/pom.xml @@ -8,9 +8,9 @@ 4.0.0 - com.sebarmeli + ru.st.selenium selenium2-java-quickstart-archetype - 0.4 + 0.5 Selenium2 Java QuickStart Archetype maven-archetype Generates a QuickStart project with Selenium 2 and TestNG diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index 6fc7daf..5928b53 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -6,125 +6,140 @@ ${version} jar - - - org.testng - testng - 6.8.5 - - - junit - junit - 4.11 - - - org.seleniumhq.selenium - selenium-java - 2.35.0 - - - com.opera - operadriver - 1.4 - - - - - - src/main/resources - true - - - - - org.apache.maven.plugins - maven-resources-plugin - 2.6 - - UTF-8 - - - - maven-surefire-plugin - 2.14.1 - - - src/test/resources/testng.xml - - - - - maven-compiler-plugin - 3.1 - - 1.6 - 1.6 - - - - - - - - local - - local - - - - - - - - - - true - - - - dev - - dev - - - - - - - - - - - test - - test - - - - - - - - - - - prod - - prod - - - - - - - - - - - force-local-driver - - - - - + + + org.testng + testng + 6.8.5 + + + junit + junit + 4.11 + + + org.seleniumhq.selenium + selenium-java + 2.35.0 + + + com.opera + operadriver + 1.5 + + + com.github.detro.ghostdriver + phantomjsdriver + 1.0.4 + + + org.seleniumhq.selenium + selenium-remote-driver + + + org.seleniumhq.selenium + selenium-server + + + + + + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + UTF-8 + + + + maven-surefire-plugin + 2.14.1 + + + src/test/resources/testng.xml + + + + + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + + + + + + + + local + + local + + + + + + + + + + true + + + + dev + + dev + + + + + + + + + + + test + + test + + + + + + + + + + + prod + + prod + + + + + + + + + + + force-local-driver + + + + + diff --git a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java index 8120248..371dd2f 100644 --- a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java +++ b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java @@ -16,11 +16,13 @@ import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.iphone.IPhoneDriver; import org.openqa.selenium.safari.SafariDriver; +import org.openqa.selenium.phantomjs.PhantomJSDriver; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import com.opera.core.systems.OperaDriver; + import ${groupId}.util.Browser; import ${groupId}.webdriver.AuthenticatedHtmlUnitDriver; @@ -38,6 +40,7 @@ public class WebDriverFactory { public static final String FIREFOX = "firefox"; public static final String OPERA = "opera"; public static final String INTERNET_EXPLORER = "ie"; + public static final String PHANTOMJS = "phantomjs"; public static final String HTML_UNIT = "htmlunit"; public static final String SAFARI = "safari"; public static final String IPHONE = "iphone"; @@ -102,6 +105,8 @@ public static WebDriver getInstance(String gridHubUrl, Browser browser, .setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); + } else if (PHANTOMJS.equals(browserName)) { + capability = DesiredCapabilities.phantomjs(); } else if (OPERA.equals(browserName)) { capability = DesiredCapabilities.opera(); } else if (SAFARI.equals(browserName)) { @@ -179,6 +184,9 @@ public static WebDriver getInstance(String browser, String username, } else if (SAFARI.equals(browser)) { webDriver = new SafariDriver(); + } else if (PHANTOMJS.equals(browser)) { + webDriver = new PhantomJSDriver(); + } else if (IPHONE.equals(browser)) { try { webDriver = new IPhoneDriver(); From b147208dad02cafe0f84d9a71b19b9490d39769e Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Thu, 31 Oct 2013 14:48:21 +0400 Subject: [PATCH 18/31] Updated for 2.37 --- README.md | 4 ++-- src/main/resources/archetype-resources/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 52f7a38..5e48aa7 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,10 @@ To install the archetype in your local repo: Now, you can use the archetype in a new project typing: mvn archetype:generate -DarchetypeGroupId=ru.st.selenium -DarchetypeArtifactId=selenium2-java-quickstart-archetype -DarchetypeVersion=0.5 -DgroupId= -DartifactId= - + where *mygroupId* : group id of the project you are creating; *myartifactId* : artifact id of the project you are creating -It uses Java bindings for Selenium version 2.35.0, OperaDriver version 1.5, PhantomJSDriver 1.0.4 and TestNG version 6.8.5. +It uses Java bindings for Selenium version 2.37.0, OperaDriver version 1.5, PhantomJSDriver 1.0.4 and TestNG version 6.8.5. Project Structure diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index 5928b53..f744888 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -20,7 +20,7 @@ org.seleniumhq.selenium selenium-java - 2.35.0 + 2.37.0 com.opera From db8df308eb6d59c09d2434cd91e80038980d4ac6 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Thu, 27 Feb 2014 00:27:10 +0400 Subject: [PATCH 19/31] Updated to 2.40 --- README.md | 4 ++-- changelog.txt | 8 -------- pom.xml | 2 +- src/main/resources/archetype-resources/pom.xml | 8 ++++---- 4 files changed, 7 insertions(+), 15 deletions(-) delete mode 100644 changelog.txt diff --git a/README.md b/README.md index 5e48aa7..b4bd39f 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,11 @@ To install the archetype in your local repo: Now, you can use the archetype in a new project typing: - mvn archetype:generate -DarchetypeGroupId=ru.st.selenium -DarchetypeArtifactId=selenium2-java-quickstart-archetype -DarchetypeVersion=0.5 -DgroupId= -DartifactId= + mvn archetype:generate -DarchetypeGroupId=ru.st.selenium -DarchetypeArtifactId=selenium2-java-quickstart-archetype -DarchetypeVersion=0.6 -DgroupId= -DartifactId= where *mygroupId* : group id of the project you are creating; *myartifactId* : artifact id of the project you are creating -It uses Java bindings for Selenium version 2.37.0, OperaDriver version 1.5, PhantomJSDriver 1.0.4 and TestNG version 6.8.5. +It uses Java bindings for Selenium version 2.40.0, OperaDriver version 1.5, PhantomJSDriver 1.1.0 and TestNG version 6.8.8. Project Structure diff --git a/changelog.txt b/changelog.txt deleted file mode 100644 index 9caea3c..0000000 --- a/changelog.txt +++ /dev/null @@ -1,8 +0,0 @@ -Version 0.2 -------------- - * Upgrade to Archetype Plugin version 2 - * Mobile testing supported - -Version 0.1 -------------- - * Initial release \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7b31c55..a255cab 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ 4.0.0 ru.st.selenium selenium2-java-quickstart-archetype - 0.5 + 0.6 Selenium2 Java QuickStart Archetype maven-archetype Generates a QuickStart project with Selenium 2 and TestNG diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index f744888..10b984e 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -10,7 +10,7 @@ org.testng testng - 6.8.5 + 6.8.8 junit @@ -20,7 +20,7 @@ org.seleniumhq.selenium selenium-java - 2.37.0 + 2.40.0 com.opera @@ -30,7 +30,7 @@ com.github.detro.ghostdriver phantomjsdriver - 1.0.4 + 1.1.0 org.seleniumhq.selenium @@ -61,7 +61,7 @@ maven-surefire-plugin - 2.14.1 + 2.16 src/test/resources/testng.xml From f201e8307413fc8e2e6c862409ff75a3ceb6ec70 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Fri, 28 Feb 2014 18:12:59 +0400 Subject: [PATCH 20/31] Ignoring IDEA project files --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 63323bd..b7c249c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ /target /.project /.settings -/.classpath \ No newline at end of file +/.classpath +/.idea +/*.iml From 146faf905f41780e2db6a9c75a4e8ba06921c3a7 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Fri, 28 Feb 2014 18:39:54 +0400 Subject: [PATCH 21/31] Enriching POM --- pom.xml | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index a255cab..5f80b18 100644 --- a/pom.xml +++ b/pom.xml @@ -8,22 +8,45 @@ 4.0.0 - ru.st.selenium - selenium2-java-quickstart-archetype + + ru.stqa.selenium + webdriver-java-quickstart-archetype 0.6 - Selenium2 Java QuickStart Archetype maven-archetype - Generates a QuickStart project with Selenium 2 and TestNG + + WebDriver Java QuickStart Archetype + Generates a QuickStart project with WebDriver and TestNG + https://github.com/barancev/webdriver-java-quickstart-archetype + - 2.1 + UTF-8 + 2.2 + The Apache Software License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt - + + + scm:git:https://github.com/barancev/webdriver-java-quickstart-archetype + scm:git:https://github.com/barancev/webdriver-java-quickstart-archetype + https://github.com/barancev/webdriver-java-quickstart-archetype + + + + + barancev + Alexei Barantsev + + Owner + + + + + org.apache.maven.archetype @@ -41,4 +64,15 @@ + + + + sonatype-nexus-snapshots + http://oss.sonatype.org/content/repositories/snapshots + + + sonatype-nexus-staging + http://oss.sonatype.org/service/local/staging/deploy/maven2 + + From d8cb0b3cc8b677f89c7515ba1357c443c1d7442a Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Sat, 1 Mar 2014 18:57:33 +0400 Subject: [PATCH 22/31] Removing use of IPhoneDriver and AndroidDriver --- .../src/main/java/webdriver/WebDriverFactory.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java index 371dd2f..2f5d167 100644 --- a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java +++ b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java @@ -111,10 +111,6 @@ public static WebDriver getInstance(String gridHubUrl, Browser browser, capability = DesiredCapabilities.opera(); } else if (SAFARI.equals(browserName)) { capability = DesiredCapabilities.safari(); - } else if (ANDROID.equals(browserName)) { - capability = DesiredCapabilities.android(); - } else if (IPHONE.equals(browserName)) { - capability = DesiredCapabilities.iphone(); } else { capability = DesiredCapabilities.htmlUnit(); @@ -187,16 +183,6 @@ public static WebDriver getInstance(String browser, String username, } else if (PHANTOMJS.equals(browser)) { webDriver = new PhantomJSDriver(); - } else if (IPHONE.equals(browser)) { - try { - webDriver = new IPhoneDriver(); - } catch (Exception e) { - e.printStackTrace(); - } - - } else if (ANDROID.equals(browser)) { - webDriver = new AndroidDriver(); - } else { // HTMLunit Check From 5822fedd20bc691bd6b9e2ef8e1824f197c7cafa Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Sat, 1 Mar 2014 19:04:19 +0400 Subject: [PATCH 23/31] Updating version number --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5f80b18..e1ff0c2 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ ru.stqa.selenium webdriver-java-quickstart-archetype - 0.6 + 0.7 maven-archetype WebDriver Java QuickStart Archetype From 81af1c43bc9d73afd9293b9fb46dfee07dc573b3 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Sat, 1 Mar 2014 19:11:04 +0400 Subject: [PATCH 24/31] Updating docs --- README.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b4bd39f..2c534e6 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,17 @@ Introduction ============ -This archetype generates a small Maven project with Selenium 2 and TestNG embedded to make it easy to get started testing with Selenium Web Driver. - -This project provides just a starting point to get up to speed with Selenium 2 infrastructure. +This archetype generates a small Maven project with Selenium WebDriver and TestNG embedded to make it easy to get started developing tests with Selenium WebDriver. To install the archetype in your local repo: - git clone git://github.com/barancev/Selenium2-Java-QuickStart-Archetype.git - cd Selenium2-Java-Quickstart-Archetype + git clone git://github.com/barancev/webdriver-java-quickstart-archetype.git + cd webdriver-java-quickstart-archetype mvn install Now, you can use the archetype in a new project typing: - mvn archetype:generate -DarchetypeGroupId=ru.st.selenium -DarchetypeArtifactId=selenium2-java-quickstart-archetype -DarchetypeVersion=0.6 -DgroupId= -DartifactId= + mvn archetype:generate -DarchetypeGroupId=ru.stqa.selenium -DarchetypeArtifactId=webdriver-java-quickstart-archetype -DarchetypeVersion=0.7 -DgroupId= -DartifactId= where *mygroupId* : group id of the project you are creating; *myartifactId* : artifact id of the project you are creating @@ -69,4 +67,4 @@ The project is just a starting point, feel free to modify it according to your n Credits ------- -The selenium2-java-quickstart-archetype project is an open source project licensed under the Apache License 2.0. \ No newline at end of file +The webdriver-java-quickstart-archetype project is an open source project licensed under the Apache License 2.0. \ No newline at end of file From 35ddd3fb2d607057a39e6ccc15b1c6a39b67d604 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Sat, 1 Mar 2014 19:16:27 +0400 Subject: [PATCH 25/31] Removing imports for IPhoneDriver and AndroidDriver --- .../src/main/java/webdriver/WebDriverFactory.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java index 2f5d167..75511a2 100644 --- a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java +++ b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java @@ -8,13 +8,11 @@ import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.android.AndroidDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.openqa.selenium.ie.InternetExplorerDriver; -import org.openqa.selenium.iphone.IPhoneDriver; import org.openqa.selenium.safari.SafariDriver; import org.openqa.selenium.phantomjs.PhantomJSDriver; import org.openqa.selenium.remote.CapabilityType; From 887a9e0eb7bc9fb1d6c7edde2304b7ea9fdf36a3 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Fri, 21 Mar 2014 17:01:34 +0400 Subject: [PATCH 26/31] Updating formatting --- pom.xml | 128 +++++++++++++++++++++++++++----------------------------- 1 file changed, 61 insertions(+), 67 deletions(-) diff --git a/pom.xml b/pom.xml index e1ff0c2..338d971 100644 --- a/pom.xml +++ b/pom.xml @@ -1,78 +1,72 @@ - - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - ru.stqa.selenium - webdriver-java-quickstart-archetype - 0.7 - maven-archetype + ru.stqa.selenium + webdriver-java-testng-archetype + 0.8-SNAPSHOT + maven-archetype - WebDriver Java QuickStart Archetype - Generates a QuickStart project with WebDriver and TestNG + WebDriver Java QuickStart Archetype + Generates a QuickStart project with WebDriver and TestNG https://github.com/barancev/webdriver-java-quickstart-archetype - - UTF-8 - 2.2 - + + UTF-8 + 2.2 + - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - - + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + - - scm:git:https://github.com/barancev/webdriver-java-quickstart-archetype - scm:git:https://github.com/barancev/webdriver-java-quickstart-archetype - https://github.com/barancev/webdriver-java-quickstart-archetype - + + scm:git:https://github.com/barancev/webdriver-java-quickstart-archetype + scm:git:https://github.com/barancev/webdriver-java-quickstart-archetype + https://github.com/barancev/webdriver-java-quickstart-archetype + + + + + barancev + Alexei Barantsev + + Owner + + + - - - barancev - Alexei Barantsev - - Owner - - - + + + + org.apache.maven.archetype + archetype-packaging + ${archetype.version} + + + + + + maven-archetype-plugin + ${archetype.version} + true + + + + - - - - org.apache.maven.archetype - archetype-packaging - ${archetype.version} - - - - - - maven-archetype-plugin - ${archetype.version} - true - - - - + + + sonatype-nexus-snapshots + http://oss.sonatype.org/content/repositories/snapshots + + + sonatype-nexus-staging + http://oss.sonatype.org/service/local/staging/deploy/maven2 + + - - - sonatype-nexus-snapshots - http://oss.sonatype.org/content/repositories/snapshots - - - sonatype-nexus-staging - http://oss.sonatype.org/service/local/staging/deploy/maven2 - - From ea210a54a8e954dfcefb440ce1f1a1972f3ff11c Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Fri, 21 Mar 2014 23:42:39 +0400 Subject: [PATCH 27/31] Updating to use ru.stqa:webdriver-factory --- pom.xml | 2 +- .../resources/archetype-resources/pom.xml | 5 + .../src/main/java/pages/HomePage.java | 4 +- .../src/main/java/pages/Page.java | 4 +- .../src/main/java/util/Browser.java | 41 --- .../src/main/java/util/PropertyLoader.java | 6 +- .../AuthenticatedHtmlUnitDriver.java | 39 --- .../main/java/webdriver/WebDriverFactory.java | 234 ------------------ .../src/test/java/pages/TestBase.java | 65 +---- 9 files changed, 23 insertions(+), 377 deletions(-) delete mode 100644 src/main/resources/archetype-resources/src/main/java/util/Browser.java delete mode 100644 src/main/resources/archetype-resources/src/main/java/webdriver/AuthenticatedHtmlUnitDriver.java delete mode 100644 src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java diff --git a/pom.xml b/pom.xml index 338d971..97df1bd 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 ru.stqa.selenium - webdriver-java-testng-archetype + webdriver-java-quickstart-archetype 0.8-SNAPSHOT maven-archetype diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index 10b984e..a515f9e 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -42,6 +42,11 @@ + + ru.stqa.selenium + webdriver-factory + 1.0 + diff --git a/src/main/resources/archetype-resources/src/main/java/pages/HomePage.java b/src/main/resources/archetype-resources/src/main/java/pages/HomePage.java index 2866f9a..88957d7 100644 --- a/src/main/resources/archetype-resources/src/main/java/pages/HomePage.java +++ b/src/main/resources/archetype-resources/src/main/java/pages/HomePage.java @@ -9,10 +9,8 @@ import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.How; -/* +/** * Sample page - * - * @author Sebastiano Armeli-Battana */ public class HomePage extends Page { diff --git a/src/main/resources/archetype-resources/src/main/java/pages/Page.java b/src/main/resources/archetype-resources/src/main/java/pages/Page.java index bb43ab7..28d7529 100644 --- a/src/main/resources/archetype-resources/src/main/java/pages/Page.java +++ b/src/main/resources/archetype-resources/src/main/java/pages/Page.java @@ -5,10 +5,8 @@ import org.openqa.selenium.WebDriver; -/* +/** * Abstract class representation of a Page in the UI. Page object pattern - * - * @author Sebastiano Armeli-Battana */ public abstract class Page { diff --git a/src/main/resources/archetype-resources/src/main/java/util/Browser.java b/src/main/resources/archetype-resources/src/main/java/util/Browser.java deleted file mode 100644 index ae96cec..0000000 --- a/src/main/resources/archetype-resources/src/main/java/util/Browser.java +++ /dev/null @@ -1,41 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${groupId}.util; - -/* - * Bean representing a browser. It contains name, version and platform fields. - * - * @author Sebastiano Armeli-Battana - */ -public class Browser { - - private String name; - private String version; - private String platform; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getPlatform() { - return platform; - } - - public void setPlatform(String platform) { - this.platform = platform; - } - -} \ No newline at end of file diff --git a/src/main/resources/archetype-resources/src/main/java/util/PropertyLoader.java b/src/main/resources/archetype-resources/src/main/java/util/PropertyLoader.java index 52256f7..a06b6bb 100644 --- a/src/main/resources/archetype-resources/src/main/java/util/PropertyLoader.java +++ b/src/main/resources/archetype-resources/src/main/java/util/PropertyLoader.java @@ -6,10 +6,8 @@ import java.io.IOException; import java.util.Properties; -/* +/** * Class that extracts properties from the prop file. - * - * @author Sebastiano Armeli-Battana */ public class PropertyLoader { @@ -23,7 +21,7 @@ public static String loadProperty(String name) { e.printStackTrace(); } - String value = ""; + String value = null; if (name != null) { value = props.getProperty(name); diff --git a/src/main/resources/archetype-resources/src/main/java/webdriver/AuthenticatedHtmlUnitDriver.java b/src/main/resources/archetype-resources/src/main/java/webdriver/AuthenticatedHtmlUnitDriver.java deleted file mode 100644 index 4958005..0000000 --- a/src/main/resources/archetype-resources/src/main/java/webdriver/AuthenticatedHtmlUnitDriver.java +++ /dev/null @@ -1,39 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${groupId}.webdriver; - -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.htmlunit.HtmlUnitDriver; - -import com.gargoylesoftware.htmlunit.BrowserVersion; -import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider; -import com.gargoylesoftware.htmlunit.WebClient; - -/* - * Class extending HtmlUnitDriver to support BASIC authentication - * - * @author Sebastiano Armeli-Battana - */ -public class AuthenticatedHtmlUnitDriver extends HtmlUnitDriver { - private static String USERNAME; - private static String PASSWORD; - - public AuthenticatedHtmlUnitDriver() { - } - - public static WebDriver create(String username, String password) { - USERNAME = username; - PASSWORD = password; - return new AuthenticatedHtmlUnitDriver(); - } - - @Override - protected WebClient newWebClient(BrowserVersion browserVersion) { - WebClient client = super.newWebClient(browserVersion); - DefaultCredentialsProvider provider = new DefaultCredentialsProvider(); - provider.addCredentials(USERNAME, PASSWORD); - client.setCredentialsProvider(provider); - return client; - } -} diff --git a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java b/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java deleted file mode 100644 index 75511a2..0000000 --- a/src/main/resources/archetype-resources/src/main/java/webdriver/WebDriverFactory.java +++ /dev/null @@ -1,234 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${groupId}.webdriver; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.openqa.selenium.Platform; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.firefox.FirefoxProfile; -import org.openqa.selenium.htmlunit.HtmlUnitDriver; -import org.openqa.selenium.ie.InternetExplorerDriver; -import org.openqa.selenium.safari.SafariDriver; -import org.openqa.selenium.phantomjs.PhantomJSDriver; -import org.openqa.selenium.remote.CapabilityType; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; - -import com.opera.core.systems.OperaDriver; - -import ${groupId}.util.Browser; -import ${groupId}.webdriver.AuthenticatedHtmlUnitDriver; - -import ${groupId}.util.Browser; - -/* - * Factory to instantiate a WebDriver object. It returns an instance of the driver (local invocation) or an instance of RemoteWebDriver - * - * @author Sebastiano Armeli-Battana - */ -public class WebDriverFactory { - - /* Browsers constants */ - public static final String CHROME = "chrome"; - public static final String FIREFOX = "firefox"; - public static final String OPERA = "opera"; - public static final String INTERNET_EXPLORER = "ie"; - public static final String PHANTOMJS = "phantomjs"; - public static final String HTML_UNIT = "htmlunit"; - public static final String SAFARI = "safari"; - public static final String IPHONE = "iphone"; - - /* Platform constants */ - public static final String WINDOWS = "windows"; - public static final String ANDROID = "android"; - public static final String XP = "xp"; - public static final String VISTA = "vista"; - public static final String MAC = "mac"; - public static final String LINUX = "linux"; - - private static WebDriver webDriver = null; - - /* - * Factory method to return a RemoteWebDriver instance given the url of the - * Grid hub and a Browser instance. - * - * @param gridHubUrl : grid hub URI - * - * @param browser : Browser object containing info around the browser to hit - * - * @param username : username for BASIC authentication on the page to test - * - * @param password : password for BASIC authentication on the page to test - * - * @return RemoteWebDriver - */ - public static WebDriver getInstance(String gridHubUrl, Browser browser, - String username, String password) { - - WebDriver webDriver = null; - - DesiredCapabilities capability = new DesiredCapabilities(); - String browserName = browser.getName(); - capability.setJavascriptEnabled(true); - - // In case there is no Hub - if (gridHubUrl == null || gridHubUrl.length() == 0) { - return getInstance(browserName, username, password); - } - - if (CHROME.equals(browserName)) { - capability = DesiredCapabilities.chrome(); - } else if (FIREFOX.equals(browserName)) { - capability = DesiredCapabilities.firefox(); - - FirefoxProfile ffProfile = new FirefoxProfile(); - - // Authenication Hack for Firefox - if (username != null && password != null) { - ffProfile.setPreference("network.http.phishy-userpass-length", - 255); - capability.setCapability(FirefoxDriver.PROFILE, ffProfile); - } - - capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true); - } else if (INTERNET_EXPLORER.equals(browserName)) { - - capability = DesiredCapabilities.internetExplorer(); - capability - .setCapability( - InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, - true); - } else if (PHANTOMJS.equals(browserName)) { - capability = DesiredCapabilities.phantomjs(); - } else if (OPERA.equals(browserName)) { - capability = DesiredCapabilities.opera(); - } else if (SAFARI.equals(browserName)) { - capability = DesiredCapabilities.safari(); - } else { - - capability = DesiredCapabilities.htmlUnit(); - // HTMLunit Check - if (username != null && password != null) { - webDriver = (HtmlUnitDriver) AuthenticatedHtmlUnitDriver - .create(username, password); - } else { - webDriver = new HtmlUnitDriver(true); - } - - return webDriver; - } - - capability = setVersionAndPlatform(capability, browser.getVersion(), - browser.getPlatform()); - - // Create Remote WebDriver - try { - webDriver = new RemoteWebDriver(new URL(gridHubUrl), capability); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return webDriver; - } - - /* - * Factory method to return a WebDriver instance given the browser to hit - * - * @param browser : String representing the local browser to hit - * - * @param username : username for BASIC authentication on the page to test - * - * @param password : password for BASIC authentication on the page to test - * - * @return WebDriver instance - */ - public static WebDriver getInstance(String browser, String username, - String password) { - - if (webDriver != null) { - return webDriver; - } - - if (CHROME.equals(browser)) { - webDriver = new ChromeDriver(); - - } else if (FIREFOX.equals(browser)) { - - FirefoxProfile ffProfile = new FirefoxProfile(); - - // Authenication Hack for Firefox - if (username != null && password != null) { - ffProfile.setPreference("network.http.phishy-userpass-length", - 255); - } - - webDriver = new FirefoxDriver(ffProfile); - - } else if (INTERNET_EXPLORER.equals(browser)) { - webDriver = new InternetExplorerDriver(); - - } else if (OPERA.equals(browser)) { - webDriver = new OperaDriver(); - - } else if (SAFARI.equals(browser)) { - webDriver = new SafariDriver(); - - } else if (PHANTOMJS.equals(browser)) { - webDriver = new PhantomJSDriver(); - - } else { - - // HTMLunit Check - if (username != null && password != null) { - webDriver = (HtmlUnitDriver) AuthenticatedHtmlUnitDriver - .create(username, password); - } else { - webDriver = new HtmlUnitDriver(true); - } - } - - return webDriver; - } - - /* - * Helper method to set version and platform for a specific browser - * - * @param capability : DesiredCapabilities object coming from the selected - * browser - * - * @param version : browser version - * - * @param platform : browser platform - * - * @return DesiredCapabilities - */ - private static DesiredCapabilities setVersionAndPlatform( - DesiredCapabilities capability, String version, String platform) { - if (MAC.equalsIgnoreCase(platform)) { - capability.setPlatform(Platform.MAC); - } else if (LINUX.equalsIgnoreCase(platform)) { - capability.setPlatform(Platform.LINUX); - } else if (XP.equalsIgnoreCase(platform)) { - capability.setPlatform(Platform.XP); - } else if (VISTA.equalsIgnoreCase(platform)) { - capability.setPlatform(Platform.VISTA); - } else if (WINDOWS.equalsIgnoreCase(platform)) { - capability.setPlatform(Platform.WINDOWS); - } else if (ANDROID.equalsIgnoreCase(platform)) { - capability.setPlatform(Platform.ANDROID); - } else { - capability.setPlatform(Platform.ANY); - } - - if (version != null) { - capability.setVersion(version); - } - return capability; - } - -} \ No newline at end of file diff --git a/src/main/resources/archetype-resources/src/test/java/pages/TestBase.java b/src/main/resources/archetype-resources/src/test/java/pages/TestBase.java index 7e6d1d3..e4e33b5 100644 --- a/src/main/resources/archetype-resources/src/test/java/pages/TestBase.java +++ b/src/main/resources/archetype-resources/src/test/java/pages/TestBase.java @@ -3,86 +3,47 @@ #set( $symbol_escape = '\' ) package ${groupId}.pages; -import java.io.File; -import java.io.IOException; import java.util.concurrent.TimeUnit; -import org.apache.commons.io.FileUtils; -import org.openqa.selenium.OutputType; -import org.openqa.selenium.TakesScreenshot; +import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.Augmenter; -import org.openqa.selenium.remote.ScreenshotException; -import org.testng.ITestResult; -import org.testng.annotations.AfterMethod; +import org.openqa.selenium.remote.DesiredCapabilities; + import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeClass; +import ru.stqa.selenium.factory.WebDriverFactory; + import ${groupId}.util.PropertyLoader; -import ${groupId}.util.Browser; -import ${groupId}.webdriver.WebDriverFactory; -/* - * Base class for all the test classes - * - * @author Sebastiano Armeli-Battana +/** + * Base class for all the TestNG-based test classes */ - public class TestBase { - private static final String SCREENSHOT_FOLDER = "target/screenshots/"; - private static final String SCREENSHOT_FORMAT = ".png"; - protected WebDriver driver; protected String gridHubUrl; protected String baseUrl; - protected Browser browser; - @BeforeClass public void init() { baseUrl = PropertyLoader.loadProperty("site.url"); gridHubUrl = PropertyLoader.loadProperty("grid2.hub"); - browser = new Browser(); - browser.setName(PropertyLoader.loadProperty("browser.name")); - browser.setVersion(PropertyLoader.loadProperty("browser.version")); - browser.setPlatform(PropertyLoader.loadProperty("browser.platform")); + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setBrowserName(PropertyLoader.loadProperty("browser.name")); + capabilities.setVersion(PropertyLoader.loadProperty("browser.version")); + capabilities.setPlatform(Platform.valueOf(PropertyLoader.loadProperty("browser.platform"))); - String username = PropertyLoader.loadProperty("user.username"); - String password = PropertyLoader.loadProperty("user.password"); - - driver = WebDriverFactory.getInstance(gridHubUrl, browser, username, - password); + driver = WebDriverFactory.getDriver(gridHubUrl, capabilities); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } @AfterSuite(alwaysRun = true) public void tearDown() { if (driver != null) { - driver.quit(); + WebDriverFactory.dismissDriver(driver); } } - -// @AfterMethod -// public void setScreenshot(ITestResult result) { -// if (!result.isSuccess()) { -// try { -// WebDriver returned = new Augmenter().augment(driver); -// if (returned != null) { -// File f = ((TakesScreenshot) returned) -// .getScreenshotAs(OutputType.FILE); -// try { -// FileUtils.copyFile(f, new File(SCREENSHOT_FOLDER -// + result.getName() + SCREENSHOT_FORMAT)); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// } -// } catch (ScreenshotException se) { -// se.printStackTrace(); -// } -// } -// } } From 37d67c50a075756b3b0e8788632dbc6a3f5ffc15 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Sun, 15 Feb 2015 20:05:16 +0300 Subject: [PATCH 28/31] Upgraded to 2.43.1 --- src/main/resources/archetype-resources/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index 10b984e..f4777cb 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -20,7 +20,7 @@ org.seleniumhq.selenium selenium-java - 2.40.0 + 2.43.1 com.opera From 4c9fed6cfa968a8d5d9041a26d7e15903b1a412f Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Sun, 15 Feb 2015 20:05:53 +0300 Subject: [PATCH 29/31] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2c534e6..89cb079 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Now, you can use the archetype in a new project typing: where *mygroupId* : group id of the project you are creating; *myartifactId* : artifact id of the project you are creating -It uses Java bindings for Selenium version 2.40.0, OperaDriver version 1.5, PhantomJSDriver 1.1.0 and TestNG version 6.8.8. +It uses Java bindings for Selenium version 2.43.1, OperaDriver version 1.5, PhantomJSDriver 1.1.0 and TestNG version 6.8.8. Project Structure @@ -67,4 +67,4 @@ The project is just a starting point, feel free to modify it according to your n Credits ------- -The webdriver-java-quickstart-archetype project is an open source project licensed under the Apache License 2.0. \ No newline at end of file +The webdriver-java-quickstart-archetype project is an open source project licensed under the Apache License 2.0. From 8ea10ed29c99ac0de17a34372e042d1d7af43e52 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Mon, 29 Jun 2015 11:58:59 +0300 Subject: [PATCH 30/31] Upgrading to Selenium 2.46 --- NOTICE | 4 +- README.md | 8 ++-- pom.xml | 2 +- .../resources/archetype-resources/pom.xml | 47 +++++-------------- .../test/java/{pages => }/HomePageTest.java | 4 +- .../src/test/java/{pages => }/TestBase.java | 13 +++-- .../src/test/resources/testng.xml | 2 +- 7 files changed, 32 insertions(+), 48 deletions(-) rename src/main/resources/archetype-resources/src/test/java/{pages => }/HomePageTest.java (93%) rename src/main/resources/archetype-resources/src/test/java/{pages => }/TestBase.java (73%) diff --git a/NOTICE b/NOTICE index 2aa9092..d26506d 100644 --- a/NOTICE +++ b/NOTICE @@ -1,5 +1,5 @@ -Selenium2 Java QuickStart Archetype -Copyright 2011 sebarmeli +WebDriver Java QuickStart Archetype +Copyright 2013-2014 Alexei Barantsev barancev@gmail.com This product includes software developed by Sebastiano Armeli-Battana diff --git a/README.md b/README.md index 89cb079..cb3c2db 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,11 @@ To install the archetype in your local repo: Now, you can use the archetype in a new project typing: - mvn archetype:generate -DarchetypeGroupId=ru.stqa.selenium -DarchetypeArtifactId=webdriver-java-quickstart-archetype -DarchetypeVersion=0.7 -DgroupId= -DartifactId= + mvn archetype:generate -DarchetypeGroupId=ru.stqa.selenium -DarchetypeArtifactId=webdriver-java-quickstart-archetype -DarchetypeVersion=0.8 -DgroupId= -DartifactId= where *mygroupId* : group id of the project you are creating; *myartifactId* : artifact id of the project you are creating -It uses Java bindings for Selenium version 2.43.1, OperaDriver version 1.5, PhantomJSDriver 1.1.0 and TestNG version 6.8.8. +It uses Java bindings for Selenium version 2.46.0, PhantomJSDriver 1.2.1 and TestNG version 6.9.4. Project Structure @@ -35,7 +35,7 @@ Hudson/Jenkins). **TestBase** class provides 30 seconds as interval for polling element from the DOM (implicity wait), and also it takes care of closing the driver when all the tests are executed in the suite. (Feel free to update all this values according to your needs) -**HomePageTest** class (in *src/test/java/pages*) is just an example of a test class for testing the homepage of a web application. This test class accepts the *path* parameter +**HomePageTest** class (in *src/test/java*) is just an example of a test class for testing the homepage of a web application. This test class accepts the *path* parameter (set in *src/test/resources/testng.xml)* defining the path appended to the base URL (in case of the home page, usually just "/"). In the setup method of this class, the **PageFactory** class is used to help supporting the **PageObject** pattern (see below for more information). Briefly according to this pattern, each page is an object. *src/main/java/pages/HomePage* class is an example of a class representing the home page. Notice how the constructor accepts the "WebDriver" interface as parameter and all the "services" available for that page should be exposed here. It also allows to @@ -53,7 +53,7 @@ For more info around TestNG framework, go to http://testng.org/doc/index.html. I Page Object pattern ------------------- -For more info around this pattern, read this wiki page: http://code.google.com/p/selenium/wiki/PageObjects +For more info around this pattern, read this wiki page: https://github.com/SeleniumHQ/selenium/wiki/PageObjects Integration with SauceLabs diff --git a/pom.xml b/pom.xml index 97df1bd..5e832aa 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ ru.stqa.selenium webdriver-java-quickstart-archetype - 0.8-SNAPSHOT + 0.8 maven-archetype WebDriver Java QuickStart Archetype diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index a651ad9..790dc41 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -10,42 +10,17 @@ org.testng testng - 6.8.8 + 6.9.4 junit junit - 4.11 - - - org.seleniumhq.selenium - selenium-java - 2.43.1 - - - com.opera - operadriver - 1.5 - - - com.github.detro.ghostdriver - phantomjsdriver - 1.1.0 - - - org.seleniumhq.selenium - selenium-remote-driver - - - org.seleniumhq.selenium - selenium-server - - + 4.12 ru.stqa.selenium webdriver-factory - 1.0 + 1.1.46 @@ -92,8 +67,8 @@ - - + http://localhost/ + firefox @@ -108,8 +83,8 @@ - - + http://devhost/ + firefox @@ -121,8 +96,8 @@ - - + http://testhost/ + firefox @@ -134,8 +109,8 @@ - - + http://prodhost/ + firefox diff --git a/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java b/src/main/resources/archetype-resources/src/test/java/HomePageTest.java similarity index 93% rename from src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java rename to src/main/resources/archetype-resources/src/test/java/HomePageTest.java index 80e5e68..ce4144b 100644 --- a/src/main/resources/archetype-resources/src/test/java/pages/HomePageTest.java +++ b/src/main/resources/archetype-resources/src/test/java/HomePageTest.java @@ -1,7 +1,7 @@ #set( $symbol_pound = '#' ) #set( $symbol_dollar = '$' ) #set( $symbol_escape = '\' ) -package ${groupId}.pages; +package ${groupId}; import org.openqa.selenium.support.PageFactory; import org.testng.Assert; @@ -9,6 +9,8 @@ import org.testng.annotations.Parameters; import org.testng.annotations.Test; +import ${groupId}.pages.HomePage; + public class HomePageTest extends TestBase { HomePage homepage; diff --git a/src/main/resources/archetype-resources/src/test/java/pages/TestBase.java b/src/main/resources/archetype-resources/src/test/java/TestBase.java similarity index 73% rename from src/main/resources/archetype-resources/src/test/java/pages/TestBase.java rename to src/main/resources/archetype-resources/src/test/java/TestBase.java index e4e33b5..2e6d434 100644 --- a/src/main/resources/archetype-resources/src/test/java/pages/TestBase.java +++ b/src/main/resources/archetype-resources/src/test/java/TestBase.java @@ -1,7 +1,7 @@ #set( $symbol_pound = '#' ) #set( $symbol_dollar = '$' ) #set( $symbol_escape = '\' ) -package ${groupId}.pages; +package ${groupId}; import java.util.concurrent.TimeUnit; @@ -34,9 +34,16 @@ public void init() { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setBrowserName(PropertyLoader.loadProperty("browser.name")); capabilities.setVersion(PropertyLoader.loadProperty("browser.version")); - capabilities.setPlatform(Platform.valueOf(PropertyLoader.loadProperty("browser.platform"))); + String platform = PropertyLoader.loadProperty("browser.platform"); + if (!(null == platform || "".equals(platform))) { + capabilities.setPlatform(Platform.valueOf(PropertyLoader.loadProperty("browser.platform"))); + } - driver = WebDriverFactory.getDriver(gridHubUrl, capabilities); + if (!(null == gridHubUrl || "".equals(gridHubUrl))) { + driver = WebDriverFactory.getDriver(gridHubUrl, capabilities); + } else { + driver = WebDriverFactory.getDriver(capabilities); + } driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } diff --git a/src/main/resources/archetype-resources/src/test/resources/testng.xml b/src/main/resources/archetype-resources/src/test/resources/testng.xml index af7a292..c5a8444 100644 --- a/src/main/resources/archetype-resources/src/test/resources/testng.xml +++ b/src/main/resources/archetype-resources/src/test/resources/testng.xml @@ -7,7 +7,7 @@ - + \ No newline at end of file From 199297b19e349d1768d06e5a0b7cde9fbcf54154 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Sun, 25 Sep 2016 00:28:15 +0300 Subject: [PATCH 31/31] Update README.md --- README.md | 71 +------------------------------------------------------ 1 file changed, 1 insertion(+), 70 deletions(-) diff --git a/README.md b/README.md index cb3c2db..e81c74a 100644 --- a/README.md +++ b/README.md @@ -1,70 +1 @@ -Introduction -============ - -This archetype generates a small Maven project with Selenium WebDriver and TestNG embedded to make it easy to get started developing tests with Selenium WebDriver. - -To install the archetype in your local repo: - - git clone git://github.com/barancev/webdriver-java-quickstart-archetype.git - cd webdriver-java-quickstart-archetype - mvn install - -Now, you can use the archetype in a new project typing: - - mvn archetype:generate -DarchetypeGroupId=ru.stqa.selenium -DarchetypeArtifactId=webdriver-java-quickstart-archetype -DarchetypeVersion=0.8 -DgroupId= -DartifactId= - -where *mygroupId* : group id of the project you are creating; *myartifactId* : artifact id of the project you are creating - -It uses Java bindings for Selenium version 2.46.0, PhantomJSDriver 1.2.1 and TestNG version 6.9.4. - - -Project Structure ------------------------------------ - -The project follows the standard Maven structure, so all the tests go in the *src/test/java* folder. Tests should inherit from the **TestBase** class. In this class a factory method -from **WebDriverFactory** class is in charge of generating the instance of the WebDriver interface you need. Different parameters are passed into the factory: - -* base URL : base URL of the AUT (application under test) -* Grid 2 hub URL : URL of the hub (if using Grid 2) -* browser fatures: a) name b) version c) platform -* username / password : in case of BASIC authenticated site - -Those parameters are retrieved from the *src/main/resources/application.properties* file. You can also populate the properties file from command line (through -D:@ondemand.saucelabs.com:80/wd/hub* - -Further Notes -------- -The project is just a starting point, feel free to modify it according to your needs. - -Credits -------- -The webdriver-java-quickstart-archetype project is an open source project licensed under the Apache License 2.0. +Deprecated in favor of https://github.com/barancev/webdriver-testng-archetype and https://github.com/barancev/webdriver-junit-archetype