Skip to content

Commit 3605509

Browse files
author
Anirudha Khanna
authored
Merge pull request #11 from browserstack/develop
Merging develop into master.
2 parents 83d91b5 + 4ba3223 commit 3605509

File tree

10 files changed

+104
-1
lines changed

10 files changed

+104
-1
lines changed

browserstack-teamcity-agent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>browserstack-teamcity</artifactId>
77
<groupId>com.browserstack</groupId>
8-
<version>1.0-SNAPSHOT</version>
8+
<version>1.0.0</version>
99
</parent>
1010

1111
<artifactId>browserstack-teamcity-agent</artifactId>

browserstack-teamcity-agent/src/main/java/com/browserstack/automate/ci/teamcity/BrowserStackLocalAgent.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
import java.util.Map;
2222
import java.util.regex.Pattern;
2323

24+
25+
/**
26+
* Component that runs on the Agent side.
27+
* Setups and tears down BrowserStackLocal, if configured.
28+
* Also responsible for copying report files into artifacts after build completion.
29+
*/
2430
public class BrowserStackLocalAgent extends AgentLifeCycleAdapter {
2531
private static final String REPORT_FILE_PATTERN = "**/browserstack-reports/REPORT-*.xml";
2632

@@ -93,6 +99,8 @@ public void runnerFinished(@NotNull BuildRunnerContext runner, @NotNull BuildFin
9399
killLocal(build);
94100
}
95101

102+
// find and collect report files that match our Ant pattern
103+
// if found, artifacts are published to the artifact directory by appending "=> <path>"
96104
List<File> reportFiles = new ArrayList<File>();
97105
FileUtil.collectMatchedFiles(build.getCheckoutDirectory(),
98106
Pattern.compile(FileUtil.convertAntToRegexp(REPORT_FILE_PATTERN)),
@@ -110,6 +118,11 @@ public void buildFinished(@NotNull AgentRunningBuild build, @NotNull BuildFinish
110118
}
111119
}
112120

121+
/**
122+
* Loads the build feature for the current build and checks if BrowserStackLocal is enabled
123+
*
124+
* @param build Current build.
125+
*/
113126
private void loadBuildFeature(final AgentRunningBuild build) {
114127
Collection<AgentBuildFeature> buildFeatures = build.getBuildFeaturesOfType(BrowserStackParameters.BUILD_FEATURE_TYPE);
115128
isEnabled = !buildFeatures.isEmpty();
@@ -121,6 +134,12 @@ private void loadBuildFeature(final AgentRunningBuild build) {
121134
}
122135
}
123136

137+
/**
138+
* Adds environment variables to the build environment.
139+
*
140+
* @param runner Represents current build runner.
141+
* @param config
142+
*/
124143
private void exportEnvVars(final BuildRunnerContext runner, final Map<String, String> config) {
125144
if (!config.containsKey(EnvVars.BROWSERSTACK_USER) || !config.containsKey(EnvVars.BROWSERSTACK_ACCESSKEY)) {
126145
return;
@@ -145,6 +164,12 @@ private void exportEnvVars(final BuildRunnerContext runner, final Map<String, St
145164
buildLogger.message(EnvVars.BROWSERSTACK_BUILD + "=" + buildId);
146165
}
147166

167+
/**
168+
* Returns a unique Build Id for the currently running build.
169+
*
170+
* @param runner Represents current build runner.
171+
* @return String Unique build Id.
172+
*/
148173
private static String getBuildId(final BuildRunnerContext runner) {
149174
return runner.getBuild().getBuildTypeName() +
150175
"-" +
@@ -153,6 +178,11 @@ private static String getBuildId(final BuildRunnerContext runner) {
153178
runner.getBuild().getBuildNumber();
154179
}
155180

181+
/**
182+
* Terminates the BrowserStackLocal binary.
183+
*
184+
* @param build Represents running build on the agent side.
185+
*/
156186
private void killLocal(final AgentRunningBuild build) {
157187
if (browserstackLocal != null) {
158188
BuildProgressLogger buildLogger = build.getBuildLogger();

browserstack-teamcity-agent/src/main/java/com/browserstack/automate/ci/teamcity/TeamCityBrowserStackLocal.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
import java.io.InputStream;
1212
import java.util.List;
1313

14+
/**
15+
* Implementation of BrowserStackLocal for TeamCity.
16+
* Overrides the default {@link ProcessBuilder} APIs to use TeamCity APIs for launching binaries on the command-line.
17+
*/
1418
public class TeamCityBrowserStackLocal extends BrowserStackLocal {
1519
private final BuildProgressLogger buildLogger;
1620

browserstack-teamcity-server/src/main/java/com/browserstack/automate/ci/teamcity/analytics/AutomateSessionController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.Map;
2020

2121
/**
22+
* Exposes a JSON API for the frontend to record the iframe load time.
23+
*
2224
* @author Shirish Kamath
2325
* @author Anirudha Khanna
2426
*/

browserstack-teamcity-server/src/main/java/com/browserstack/automate/ci/teamcity/analytics/TeamcityAnalyticsDataProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.io.File;
1010

1111
/**
12+
* Provides data for Analytics to gather and submit.
13+
*
1214
* @author Shirish Kamath
1315
* @author Anirudha Khanna
1416
*/

browserstack-teamcity-server/src/main/java/com/browserstack/automate/ci/teamcity/config/AutomateBuildFeature.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
import java.util.HashMap;
2222
import java.util.Map;
2323

24+
/**
25+
* Configuration for the "BrowserStack" build feature for each project.
26+
*
27+
* @author Shirish Kamath
28+
* @author Anirudha Khanna
29+
*/
2430
public class AutomateBuildFeature extends BuildFeature {
2531

2632
private static final String ERR_INVALID_PATH = "Invalid path";
@@ -55,6 +61,13 @@ public boolean isMultipleFeaturesPerBuildTypeAllowed() {
5561
return false;
5662
}
5763

64+
/**
65+
* Returns parameters description of the build feature, will be used in the TeamCity UI to
66+
* describe this feature settings. Can contain HTML, so please make sure it is safe in terms of XSS.
67+
*
68+
* @param params parameters to describe
69+
* @return short description of parameters.
70+
*/
5871
@NotNull
5972
@Override
6073
public String describeParameters(@NotNull Map<String, String> params) {
@@ -78,10 +91,17 @@ public Map<String, String> getDefaultParameters() {
7891
defaults = new HashMap<String, String>();
7992
}
8093

94+
// Analytics are enabled by default
8195
defaults.put(BrowserStackParameters.ENABLE_ANALYTICS, "true");
8296
return defaults;
8397
}
8498

99+
/**
100+
* Checks if the "BrowserStack" build feature has been added to the given build.
101+
*
102+
* @param build
103+
* @return
104+
*/
85105
@Nullable
86106
@Override
87107
public PropertiesProcessor getParametersProcessor() {

browserstack-teamcity-server/src/main/java/com/browserstack/automate/ci/teamcity/listener/BrowserStackBuildServerAdapter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
import java.util.Map;
1515

1616
/**
17+
* Tracks the events occurring at the build server.
18+
* Mainly used for Analytics.
19+
*
1720
* @author Shirish Kamath
1821
* @author Anirudha Khanna
1922
*/

browserstack-teamcity-server/src/main/java/com/browserstack/automate/ci/teamcity/ui/AutomateResultsTab.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
import java.util.regex.Pattern;
4040

4141
/**
42+
* Controller for the "BrowserStack" tab displayed in the UI with test results.
43+
* This handles both views: the list of test cases and the iframe for a single test.
44+
*
4245
* @author Shirish Kamath
4346
* @author Anirudha Khanna
4447
*/
@@ -157,6 +160,8 @@ public Continuation processBuildArtifact(@NotNull BuildArtifact artifact) {
157160
if (results != null) {
158161
for (Element elem : results) {
159162
String testCaseId = elem.getAttribute("id").getValue();
163+
164+
// Checks if test case in our report exists in test report XMLs parsed by TeamCity
160165
if (testCaseId != null && testResultMap.containsKey(testCaseId)) {
161166
STestRun testRun = testResultMap.get(testCaseId);
162167
elem.setAttribute("status", testRun.getStatusText());

browserstack-teamcity-server/src/main/java/com/browserstack/automate/ci/teamcity/ui/AutomateSessionLink.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import java.util.Map;
2626

2727
/**
28+
* Controller for the link to the BrowserStack tab displayed
29+
* under the stacktrace of a failed test.
30+
*
2831
* @author Shirish Kamath
2932
* @author Anirudha Khanna
3033
*/
@@ -51,6 +54,7 @@ public void fillModel(@NotNull Map<String, Object> model, @NotNull HttpServletRe
5154
List<STestRun> testRuns = (List<STestRun>) testRunsAttr;
5255
STestRun testRun = null;
5356

57+
// Get the STestRun for the current STest
5458
for (STestRun tr : testRuns) {
5559
if (tr.getTest().getTestNameId() == test.getTestNameId()) {
5660
testRun = tr;
@@ -74,6 +78,13 @@ public void fillModel(@NotNull Map<String, Object> model, @NotNull HttpServletRe
7478
}
7579
}
7680

81+
/**
82+
* Finds the index for the give test case w.r.t. to other test cases having the same name.
83+
*
84+
* @param testRuns List of test runs executed in this build.
85+
* @param testRun Current test run.
86+
* @return
87+
*/
7788
private int getTestIndex(final List<STestRun> testRuns, final STestRun testRun) {
7889
// TODO: This iterates through all test results with the same name as the test case being queries
7990
// and figure out index for the test case w.r.t other tests with the same name (but different parameters)
@@ -100,6 +111,15 @@ public boolean isAvailable(@NotNull final HttpServletRequest request) {
100111
return true;
101112
}
102113

114+
/**
115+
* Finds the sessionId for the current test case by parsing the XML artifact files
116+
* and returning the session Id for the matching test case (name{index})
117+
*
118+
* @param testRun Current test run.
119+
* @param testIndex Test index for the test case w.r.t other tests having the same name.
120+
* @return BrowserStack Automate Session Id
121+
* @throws IOException
122+
*/
103123
@SuppressWarnings("unchecked")
104124
private static String findSessionId(final STestRun testRun, final long testIndex) throws IOException {
105125
String testNameFull = ParserUtil.getTestName(testRun);

browserstack-teamcity-server/src/main/java/com/browserstack/automate/ci/teamcity/util/ParserUtil.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ public class ParserUtil {
2323

2424
private static final String PACKAGE_DEFAULT = "(root)";
2525

26+
/**
27+
* Returns the full class name (packageName.className)
28+
* @param testRun
29+
* @return
30+
*/
2631
public static String getFullClassName(final STestRun testRun) {
2732
TestName testName = testRun.getTest().getName();
2833
return String.format("%s.%s", testName.hasPackage() ? testName.getPackageName() : PACKAGE_DEFAULT, testName.getClassName());
2934
}
3035

36+
/**
37+
* Returns the full test name (packageName.className.testName)
38+
* @param testRun
39+
* @return
40+
*/
3141
public static String getTestName(final STestRun testRun) {
3242
return String.format("%s.%s", getFullClassName(testRun), testRun.getTest().getName().getTestMethodName());
3343
}
@@ -44,6 +54,13 @@ public static List<Element> parseResultFile(final InputStream inputStream) throw
4454
return null;
4555
}
4656

57+
/**
58+
* Generates a map for all test cases parsed by TeamCity from test report XMLs.
59+
* Keys in the map are unique identifiers for each test case (packageName.className.methodName{testIndex}).
60+
*
61+
* @param allTests
62+
* @return
63+
*/
4764
public static Map<String, STestRun> processTestResults(final List<STestRun> allTests) {
4865
Map<String, STestRun> testStatusMap = new HashMap<String, STestRun>();
4966
Map<String, Long> testCaseIndices = new HashMap<String, Long>();

0 commit comments

Comments
 (0)