From b26de9239fd45f58e59bad43857f00347afbb08f Mon Sep 17 00:00:00 2001 From: Harish Ved Date: Thu, 5 May 2016 12:01:02 +0530 Subject: [PATCH 1/2] Restructure --- .gitignore | 1 + build.xml | 7 ++ lib/browserstack-local-java-0.1.0.jar | Bin 0 -> 7890 bytes src/com/browserstack/TestNGLocal.java | 110 +++++++++++++++++++++++ src/com/browserstack/TestNGParallel.java | 6 +- src/com/browserstack/TestNGSample.java | 6 +- 6 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 lib/browserstack-local-java-0.1.0.jar create mode 100644 src/com/browserstack/TestNGLocal.java diff --git a/.gitignore b/.gitignore index 1b79009..696ba4b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ test-output/ dist/ bin/ *.png +local.log diff --git a/build.xml b/build.xml index 71f4e73..fd89c5f 100644 --- a/build.xml +++ b/build.xml @@ -42,6 +42,13 @@ + + + + + + + diff --git a/lib/browserstack-local-java-0.1.0.jar b/lib/browserstack-local-java-0.1.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..ce43afb0bfea0cfdb166ee006342ffaa3ec43d79 GIT binary patch literal 7890 zcmbtZ1z1#D*G9UeLl6)UP+Gc%8l)MzL6Gi78ib)_7?AER>FyGcAta?+LZl@HB!9SG z_5Rm;|L=dEZ_RVg*)y}&yVu@x&RT2Mt0;?rhz@rvf|$8de+>RSq1{|T;;N#|(()3l zihru1!U1m7bW4+6ZEn8yzc~p0ss<93mzEG$QDp&19D@4$gJPBWqes>l{Uk0 zq>x^c0`%4plLB}2E)NNhJREZRMm_pzN?E2O%;m7V?hS4Ya6jCGgX8?$DiCknGqSV! zxq#m_aR1aWbhLAIGI4ZrHZZdKKh%l;N!{Ac$iVui5$Ydalwlgs^WJQ&BR(7)^}id* z-I}r(SsOSxrD~vgk*Sefza988Xv_hM?)_jpR1KOn9<`CNV5U(tH=?Jvpa;oHi8@Eg zMcME)^=(@xF+)`OTJ}V8mz4mIEyWp~M{zRTlN$sjJ_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b(-Wms!#k;FL3qcKaIgpQ!vi$ zQH~cH@M>ZQ7;$oUCJ~2`CT3Ik&xdW6diQ-hyc{;@5+9c68!9#?m};u& zYFCw+Q?t^BKjRn#xP$=~@3%@oX}(qW*AaeM$V`j#j<+j5O^TNjWZoyn&)xNVlsnQ& zkwD$S*|_GAkyrS9=FaSz27!S&fsPX_jdZD~7xlrM`ytqe;DtjHhV>A8Q>cVTGxohT z9n4bY#lTnmAp7QLo~IuE%n63|r)Lx^Mhc_rK*MwSL&2^YUnTa}qa!^x4^B_=5%+Vf zwJQ#W<7=C}<=M7|!_9cV99sI|Wd7+yDr#D5t$>>cgwO&pyqOq^6)6b59OWtgNvN>YWYdmtv+ffZ$}-p5Gn zjD(nSgqWBm(6AD@0Rn)(7y%R$bD;jcawvr3@X-415$0FS`jOBBSqy-Rb@ZXr*C@zA zU#MRtZAkC5ZiqN-qD4qAtq7m7!+grcr%tl@;?ByaEH|vr9e4tSe`l|57Iq^za66*6 z*Pqe-m)SqFS+~l!lH>R2=KRy_FWlBIgx~3;Tf*tP+)mteGyG0J{c`p16xA&O^<8c) z)^CQl7JtnEH(~$Z&2I^*?{aHSd{YVhX8wbo`T_FK1l13i96z~#2l)$K^~%{n1r~bhEYa8P4sDCeUexa7%WW9e`>K~|oD|mhZ|DMoqv;TL&fxEu`a>Hr<{Mmoh z0zdZdcVo&Qwl}xh_4R$i-;8gZ{CjQi?`XHx!FRbu)B1m){q;`y-?hSzS^l|N_%Tn8 zU)g^#%b&HwuigFU2=i;Qb&~(QLI1X-+sS^#8%0?p bsLocalArgs = new HashMap(); + bsLocalArgs.put("key", accessKey); + bsLocalArgs.put("forcelocal", ""); + bsLocal.start(bsLocalArgs); + } + + @BeforeMethod(alwaysRun=true) + public void setUp() throws Exception { + String username = System.getenv("BROWSERSTACK_USERNAME"); + String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY"); + + DesiredCapabilities capability = new DesiredCapabilities(); + capability.setCapability("platform",platform); + capability.setCapability("browser", browserName); + capability.setCapability("browserVersion", browserVersion); + capability.setCapability("name", "Sample TestNG Local Test"); + capability.setCapability("build", "Sample TestNG Tests"); + capability.setCapability("browserstack.local", "true"); + + driver = new RemoteWebDriver(new URL("http://"+username+":"+accessKey+"@hub.browserstack.com/wd/hub"), capability); + } + + @Test(groups = { "local_test" }) + public void testSimple() throws Exception { + this.driver.get("http://www.google.com"); + System.out.println("Page title is: " + driver.getTitle()); + Assert.assertEquals("Google", driver.getTitle()); + WebElement element = driver.findElement(By.name("q")); + element.sendKeys("BrowserStack"); + element.submit(); + driver = new Augmenter().augment(driver); + File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); + try { + FileUtils.copyFile(srcFile, new File("Screenshot.png")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + if(driver != null) { + driver.quit(); + } + } + + @AfterSuite(alwaysRun=true) + public void afterSuite() throws Exception { + if(bsLocal != null) { + bsLocal.stop(); + } + } + + @DataProvider(name = "getBrowsers") + public static Object[][] createData1() { + return new Object[][] { + { Platform.WINDOWS.toString(), "chrome", "48" }, + { Platform.XP.toString(), "firefox", "44"}, + }; + } +} diff --git a/src/com/browserstack/TestNGParallel.java b/src/com/browserstack/TestNGParallel.java index 9b92be8..ef112df 100644 --- a/src/com/browserstack/TestNGParallel.java +++ b/src/com/browserstack/TestNGParallel.java @@ -1,8 +1,8 @@ package com.browserstack; -import org.testng.annotations.Test; -import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.Test; import org.testng.Assert; import java.io.File; @@ -29,7 +29,7 @@ public void setUp(String browser, String version, String platform) throws Except capability.setCapability("platform",platform); capability.setCapability("browserName", browser); capability.setCapability("browserVersion", version); - capability.setCapability("project", "Parallel Tests"); + capability.setCapability("name", "Sample TestNG Parallel Tests"); capability.setCapability("build", "Sample TestNG Tests"); String username = System.getenv("BROWSERSTACK_USERNAME"); String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY"); diff --git a/src/com/browserstack/TestNGSample.java b/src/com/browserstack/TestNGSample.java index 97b6948..a00c76d 100644 --- a/src/com/browserstack/TestNGSample.java +++ b/src/com/browserstack/TestNGSample.java @@ -1,10 +1,10 @@ package com.browserstack; import org.testng.annotations.DataProvider; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.AfterMethod; import org.testng.annotations.Factory; import org.testng.annotations.Test; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; import org.testng.Assert; import java.io.File; @@ -42,8 +42,8 @@ public void setUp() throws Exception { capability.setCapability("platform",platform); capability.setCapability("browser", browserName); capability.setCapability("browserVersion", browserVersion); + capability.setCapability("name", "Sample TestNG Series Tests"); capability.setCapability("build", "Sample TestNG Tests"); - capability.setCapability("project", "Series Tests"); String username = System.getenv("BROWSERSTACK_USERNAME"); String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY"); driver = new RemoteWebDriver(new URL("http://"+username+":"+accessKey+"@hub.browserstack.com/wd/hub"), capability); From 2f54c1a91a16dde6987566d7187979951fe66300 Mon Sep 17 00:00:00 2001 From: Harish Ved Date: Thu, 5 May 2016 12:04:17 +0530 Subject: [PATCH 2/2] Update README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 165a2d4..387c3d1 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Sample for running [TestNG] tests with BrowserStack Automate. - Optionally, you can add your BrowserStack credentials to the environment variables `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY`. ### Running the tests +- To start local tests run: `ant test-local` - To start tests in series, run: `ant test-series` - To start parallel tests run: `ant test-parallel`