Skip to content

Commit e7ac5b7

Browse files
committed
Fixing formatting issues
1 parent 7cd0ec0 commit e7ac5b7

File tree

3 files changed

+116
-119
lines changed

3 files changed

+116
-119
lines changed

java/testng/src/main/java/com/saucelabs/saucebindings/testng/SauceBaseTest.java

+54-54
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,75 @@
33
import com.saucelabs.saucebindings.DataCenter;
44
import com.saucelabs.saucebindings.SauceSession;
55
import com.saucelabs.saucebindings.options.SauceOptions;
6+
import java.lang.reflect.Method;
7+
import java.util.Arrays;
68
import org.openqa.selenium.remote.RemoteWebDriver;
79
import org.testng.ITestResult;
810
import org.testng.annotations.AfterMethod;
911
import org.testng.annotations.BeforeMethod;
1012

11-
import java.lang.reflect.Method;
12-
import java.util.Arrays;
13-
1413
public class SauceBaseTest {
15-
private static ThreadLocal<SauceSession> session = new ThreadLocal<>();
16-
private static ThreadLocal<DataCenter> dataCenterThreadLocal = new ThreadLocal<>();
14+
private static ThreadLocal<SauceSession> session = new ThreadLocal<>();
15+
private static ThreadLocal<DataCenter> dataCenterThreadLocal = new ThreadLocal<>();
1716

18-
public RemoteWebDriver getDriver() {
19-
return getSession().getDriver();
20-
}
17+
public RemoteWebDriver getDriver() {
18+
return getSession().getDriver();
19+
}
2120

22-
public SauceSession getSession() {
23-
return session.get();
24-
}
21+
public SauceSession getSession() {
22+
return session.get();
23+
}
2524

26-
public DataCenter getDataCenter() {
27-
return dataCenterThreadLocal.get();
28-
}
25+
public DataCenter getDataCenter() {
26+
return dataCenterThreadLocal.get();
27+
}
2928

30-
/**
31-
* This is designed to be able to be overridden in a subclass
32-
*
33-
* @return default instance of SauceOptions
34-
*/
35-
protected SauceOptions createSauceOptions() {
36-
return new SauceOptions();
37-
}
29+
/**
30+
* This is designed to be able to be overridden in a subclass
31+
*
32+
* @return default instance of SauceOptions
33+
*/
34+
protected SauceOptions createSauceOptions() {
35+
return new SauceOptions();
36+
}
3837

39-
/**
40-
* This method ensures a test name is set by default, and then starts the session
41-
* It creates a session and a driver
42-
*
43-
* @param method the default parameter for BeforeMethod
44-
*/
45-
@BeforeMethod
46-
protected void setup(Method method) {
47-
SauceOptions sauceOptions = createSauceOptions();
48-
if (sauceOptions.sauce().getName() == null) {
49-
sauceOptions.sauce().setName(method.getName());
50-
}
51-
session.set(new SauceSession(sauceOptions));
52-
DataCenter dataCenter = getDataCenter();
53-
if (dataCenter != null) {
54-
getSession().setDataCenter(getDataCenter());
55-
}
56-
getSession().start();
38+
/**
39+
* This method ensures a test name is set by default, and then starts the session It creates a
40+
* session and a driver
41+
*
42+
* @param method the default parameter for BeforeMethod
43+
*/
44+
@BeforeMethod
45+
protected void setup(Method method) {
46+
SauceOptions sauceOptions = createSauceOptions();
47+
if (sauceOptions.sauce().getName() == null) {
48+
sauceOptions.sauce().setName(method.getName());
5749
}
50+
session.set(new SauceSession(sauceOptions));
5851

59-
@AfterMethod
60-
protected void teardown(ITestResult result) {
61-
if (result.isSuccess()) {
62-
getSession().stop(true);
63-
} else {
64-
Throwable e = result.getThrowable();
65-
getDriver().executeScript("sauce:context=Failure Reason: " + e.getMessage());
52+
DataCenter dataCenter = getDataCenter();
53+
if (dataCenter != null) {
54+
getSession().setDataCenter(getDataCenter());
55+
}
56+
getSession().start();
57+
}
6658

67-
for (Object trace : Arrays.stream(e.getStackTrace()).toArray()) {
68-
if (trace.toString().contains("sun")) {
69-
break;
70-
}
71-
getDriver().executeScript("sauce:context=Backtrace: " + trace);
72-
}
59+
@AfterMethod
60+
protected void teardown(ITestResult result) {
61+
if (result.isSuccess()) {
62+
getSession().stop(true);
63+
} else {
64+
Throwable e = result.getThrowable();
65+
getDriver().executeScript("sauce:context=Failure Reason: " + e.getMessage());
7366

74-
getSession().stop(false);
67+
for (Object trace : Arrays.stream(e.getStackTrace()).toArray()) {
68+
if (trace.toString().contains("sun")) {
69+
break;
7570
}
71+
getDriver().executeScript("sauce:context=Backtrace: " + trace);
72+
}
73+
74+
getSession().stop(false);
7675
}
76+
}
7777
}

java/testng/src/main/java/com/saucelabs/saucebindings/testng/SauceParameterizedBaseTest.java

+47-49
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,61 @@
22

33
import com.saucelabs.saucebindings.SauceSession;
44
import com.saucelabs.saucebindings.options.SauceOptions;
5+
import java.lang.reflect.Method;
6+
import java.util.Arrays;
57
import org.openqa.selenium.remote.RemoteWebDriver;
68
import org.testng.ITestResult;
79
import org.testng.annotations.AfterMethod;
810
import org.testng.annotations.BeforeMethod;
911

10-
import java.lang.reflect.Method;
11-
import java.util.Arrays;
12-
1312
public abstract class SauceParameterizedBaseTest {
14-
private static ThreadLocal<SauceSession> session = new ThreadLocal<>();
15-
16-
public RemoteWebDriver getDriver() {
17-
return getSession().getDriver();
18-
}
19-
20-
public SauceSession getSession() {
21-
return session.get();
13+
private static ThreadLocal<SauceSession> session = new ThreadLocal<>();
14+
15+
public RemoteWebDriver getDriver() {
16+
return getSession().getDriver();
17+
}
18+
19+
public SauceSession getSession() {
20+
return session.get();
21+
}
22+
23+
/**
24+
* This is designed to be able to be overridden in a subclass if using parameterization
25+
*
26+
* @param method the Method instance required for starting Parameterized tests in subclass
27+
* @param parameters the DataProvider parameters object defined in the subclass
28+
* @return default instance of SauceOptions
29+
*/
30+
protected SauceOptions createSauceOptions(Method method, Object[] parameters) {
31+
return new SauceOptions();
32+
}
33+
34+
@BeforeMethod
35+
protected void setup(Method method, Object[] parameters) {
36+
SauceOptions sauceOptions = createSauceOptions(method, parameters);
37+
if (sauceOptions.sauce().getName() == null) {
38+
sauceOptions.sauce().setName(method.getName());
2239
}
23-
24-
/**
25-
* This is designed to be able to be overridden in a subclass if using parameterization
26-
*
27-
* @param method the Method instance required for starting Parameterized tests in subclass
28-
* @param parameters the DataProvider parameters object defined in the subclass
29-
* @return default instance of SauceOptions
30-
*/
31-
protected SauceOptions createSauceOptions(Method method, Object[] parameters) {
32-
return new SauceOptions();
33-
}
34-
35-
@BeforeMethod
36-
protected void setup(Method method, Object[] parameters) {
37-
SauceOptions sauceOptions = createSauceOptions(method, parameters);
38-
if (sauceOptions.sauce().getName() == null) {
39-
sauceOptions.sauce().setName(method.getName());
40+
session.set(new SauceSession(sauceOptions));
41+
getSession().start();
42+
}
43+
44+
@AfterMethod
45+
protected void teardown(ITestResult result) {
46+
if (result.isSuccess()) {
47+
getSession().stop(true);
48+
} else {
49+
Throwable e = result.getThrowable();
50+
getDriver().executeScript("sauce:context=Failure Reason: " + e.getMessage());
51+
52+
for (Object trace : Arrays.stream(e.getStackTrace()).toArray()) {
53+
if (trace.toString().contains("sun")) {
54+
break;
4055
}
41-
session.set(new SauceSession(sauceOptions));
42-
getSession().start();
43-
}
56+
getDriver().executeScript("sauce:context=Backtrace: " + trace);
57+
}
4458

45-
46-
@AfterMethod
47-
protected void teardown(ITestResult result) {
48-
if (result.isSuccess()) {
49-
getSession().stop(true);
50-
} else {
51-
Throwable e = result.getThrowable();
52-
getDriver().executeScript("sauce:context=Failure Reason: " + e.getMessage());
53-
54-
for (Object trace : Arrays.stream(e.getStackTrace()).toArray()) {
55-
if (trace.toString().contains("sun")) {
56-
break;
57-
}
58-
getDriver().executeScript("sauce:context=Backtrace: " + trace);
59-
}
60-
61-
getSession().stop(false);
62-
}
59+
getSession().stop(false);
6360
}
61+
}
6462
}
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
package com.saucelabs.saucebindings.testng;
22

3+
import java.lang.reflect.Method;
34
import org.testng.Assert;
45
import org.testng.annotations.AfterMethod;
56
import org.testng.annotations.BeforeMethod;
67
import org.testng.annotations.Test;
78

8-
import java.lang.reflect.Method;
9-
109
public class AddHooksTest extends SauceBaseTest {
11-
Boolean working = null;
10+
Boolean working = null;
1211

13-
@BeforeMethod
14-
protected void setup(Method method) {
15-
working = true;
16-
super.setup(method);
17-
}
12+
@BeforeMethod
13+
protected void setup(Method method) {
14+
working = true;
15+
super.setup(method);
16+
}
1817

19-
@AfterMethod
20-
protected void teardown() {
21-
System.out.println("Can do something in teardown before test watcher methods");
22-
}
18+
@AfterMethod
19+
protected void teardown() {
20+
System.out.println("Can do something in teardown before test watcher methods");
21+
}
2322

24-
@Test
25-
public void useCustomOptions() {
26-
Assert.assertTrue(working);
27-
}
23+
@Test
24+
public void useCustomOptions() {
25+
Assert.assertTrue(working);
26+
}
2827
}

0 commit comments

Comments
 (0)