Skip to content

Commit 7e0fd09

Browse files
committed
fix local spawning
1 parent d08025d commit 7e0fd09

3 files changed

Lines changed: 22 additions & 17 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* Update `env/default/default.properties` with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings)
1818

1919
## Running the tests
20-
* To run the sample specs, run `mvn test -P sample-specs`
21-
* To run the sample local specs, run `mvn test -P sample-local-specs`
20+
* To run the sample specs, run `mvn test -P sample-test`
21+
* To run the sample local specs, run `mvn test -P sample-local-test`
2222

2323
## Notes
2424
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)

pom.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@
5151
</dependencies>
5252
<profiles>
5353
<profile>
54-
<id>sample-specs</id>
54+
<id>sample-test</id>
55+
<activation>
56+
<activeByDefault>true</activeByDefault>
57+
</activation>
5558
<build>
5659
<pluginManagement>
5760
<plugins>
@@ -91,7 +94,7 @@
9194
</build>
9295
</profile>
9396
<profile>
94-
<id>sample-local-specs</id>
97+
<id>sample-local-test</id>
9598
<build>
9699
<pluginManagement>
97100
<plugins>

src/test/java/com/browserstack/gauge/pages/SearchSpec.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@ public class SearchSpec {
2020
private static final String AUTOMATE_KEY = System.getenv("BROWSERSTACK_ACCESS_KEY");
2121
private static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub.browserstack.com/wd/hub";
2222
private WebDriver driver;
23-
private Local local;
23+
private static Local local;
24+
2425
@BeforeSuite
2526
public void beforeSuite() throws Exception {
26-
if (!(System.getenv("LOCAL").isEmpty()) && System.getenv("LOCAL").equalsIgnoreCase("true")) {
27-
local = new Local();
28-
Map<String, String> options = new HashMap<String, String>();
29-
options.put("key", AUTOMATE_KEY);
30-
local.start(options);
27+
try {
28+
if (!(System.getenv("LOCAL").isEmpty()) && System.getenv("LOCAL").equalsIgnoreCase("true")) {
29+
local = new Local();
30+
Map<String, String> options = new HashMap<String, String>();
31+
options.put("key", AUTOMATE_KEY);
32+
local.start(options);
33+
}
34+
} catch (Exception e) {
35+
System.out.println("Error while start local - " + e);
3136
}
3237
}
3338
@BeforeSpec
@@ -37,19 +42,15 @@ public void setUp() throws Exception {
3742
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
3843

3944
if (!(System.getenv("LOCAL").isEmpty()) && System.getenv("LOCAL").equalsIgnoreCase("true")) {
40-
if(local == null || !local.isRunning()){
41-
local = new Local();
42-
Map<String, String> options = new HashMap<String, String>();
43-
options.put("key", AUTOMATE_KEY);
44-
local.start(options);
45+
if (local != null && local.isRunning()) {
46+
browserstackOptions.put("local", "true");
4547
}
46-
browserstackOptions.put("local", "true");
4748
}
4849

4950
// Capabilities from environment
5051
if(System.getenv("DEVICE") != null){
5152
caps.setCapability("browserName", System.getenv("BROWSERNAME"));
52-
caps.setCapability("platform", System.getenv("PLATFORM"));
53+
caps.setCapability("os", System.getenv("PLATFORM"));
5354
caps.setCapability("deviceName", System.getenv("DEVICE"));
5455
}
5556
else {
@@ -61,6 +62,7 @@ public void setUp() throws Exception {
6162
}
6263
browserstackOptions.put("buildName", "browserstack-build-1");
6364
browserstackOptions.put("sessionName", "BStack Sample Gauge");
65+
browserstackOptions.put("source", "gauge:sample-master:v1.0");
6466
caps.setCapability("bstack:options", browserstackOptions);
6567

6668
java.net.URL remoteURL = new URL(URL);

0 commit comments

Comments
 (0)