Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for specifying browser information as a JSON String or Array #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions java/src/com/yahoo/platform/yuitest/selenium/SeleniumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import com.yahoo.platform.yuitest.config.TestPageGroup;
import com.yahoo.platform.yuitest.coverage.results.SummaryCoverageReport;
import com.yahoo.platform.yuitest.results.TestReport;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
* Controls Selenium to extract YUI Test information.
Expand Down Expand Up @@ -428,12 +431,32 @@ private SessionResult runTestPage(Selenium selenium, String browser,
//--------------------------------------------------------------------------

/**
* Splits the comma-delimited list of browsers into an array of strings.
* Attempts to parse the 'selenium.browsers' property as a JSON String. If the property is not a JSON string,
* splits the comma-delimited list of browsers into an array of strings.
* @throws Exception If there are no browsers specified.
*/
private void getBrowserList() throws Exception {

browsers = (properties.getProperty("selenium.browsers", "")).split("\\,");
String browsersText = properties.getProperty("selenium.browsers", "");
try {
//try parse as a JSON Array
JSONArray jsonArray = new JSONArray(browsersText);
browsers = new String[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
browsers[i] = jsonObject.toString();
}
} catch (JSONException e) {
try {
//try parse as a JSON Object
new JSONObject(browsersText);
browsers = new String[1];
browsers[0] = browsersText;
} catch (JSONException e1) {
//fall back to splitting input string on ,
browsers = browsersText.split("\\,");
}
}
if(browsers.length == 0){
throw new Exception("The configuration property 'selenium.browsers' is missing.");
}
Expand Down