Skip to content
Permalink
Browse files

replace JSON library from org.json to com.google.code.gson.

  • Loading branch information...
vmi committed Jan 31, 2016
1 parent 7837a97 commit 641ab94e7d014cdf4fd6a83554dcff57130143d3
@@ -1,6 +1,10 @@
Selenese Runner Java Relase Note
================================

### 2.4.0

* Replace JSON library from org.json to com.google.code.gson.

### 2.3.1

* Fix problem with path relativize double URI escaping items like spaces. (PR #183 by stevenebutler)
@@ -524,11 +524,10 @@ It supports test-case and test-suite which are Selenium IDE's native format.</de
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20080701</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency><dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
@@ -8,8 +8,8 @@
import javax.script.ScriptException;

import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;

import com.google.gson.Gson;
import com.thoughtworks.selenium.SeleniumException;

import jp.vmi.script.JSList;
@@ -49,7 +49,7 @@ public CommandList getExpandedCommands(Context context, Map<String, String> roll
bindings.put("rule", ((JSMap<?, ?>) rule).unwrap());
else
bindings.put("rule", rule);
String args = new JSONObject(rollupArgs).toString();
String args = new Gson().toJson(rollupArgs);
try {
commands = JSList.toList(engine, engine.eval("rule.getExpandedCommands(" + args + ")", bindings));
} catch (ScriptException e) {
@@ -3,12 +3,10 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.io.output.StringBuilderWriter;
import org.json.JSONException;
import org.json.JSONObject;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;

import com.google.gson.Gson;
import com.thoughtworks.selenium.SeleniumException;

/**
@@ -51,21 +49,17 @@ public Object eval(WebDriver driver, String script) {
public Object eval(WebDriver driver, String script, String cast) {
VarsMap varsMap = context.getVarsMap();
boolean hasStoredVars = script.matches(".*\\bstoredVars\\b.*");
StringBuilderWriter writer = new StringBuilderWriter();
StringBuilder writer = new StringBuilder();
if (hasStoredVars) {
writer.append("return (function(){var storedVars = ");
try {
new JSONObject(varsMap).write(writer);
} catch (JSONException e) {
throw new RuntimeException(e);
}
new Gson().toJson(varsMap, writer);
writer.append(";\n");
}
writer.append("return [");
if (cast != null)
writer.append(cast);
writer.append("((function(){");
mutator.mutate(script, writer.getBuilder());
mutator.mutate(script, writer);
writer.append("})())");
if (hasStoredVars)
writer.append(", storedVars];})();");
@@ -3,17 +3,17 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.json.JSONException;
import org.json.JSONObject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.google.common.io.Files;
import com.google.gson.Gson;

import jp.vmi.selenium.selenese.utils.PathUtils;

@@ -48,22 +48,10 @@ public static void setDriverSpecificCapabilities(DesiredCapabilities caps, Drive
} catch (IOException e) {
throw new RuntimeException(e);
}
JSONObject jsonObject;
try {
jsonObject = new JSONObject(json);
} catch (JSONException e) {
throw new RuntimeException(e);
}
@SuppressWarnings("unchecked")
Iterator<String> keys = (Iterator<String>) jsonObject.keys();
while (keys.hasNext()) {
String key = keys.next();
try {
options.setExperimentalOption(key, jsonObject.get(key));
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
Map<String, Object> jsonObject = new Gson().fromJson(json, Map.class);
for (Entry<String, Object> entry : jsonObject.entrySet())
options.setExperimentalOption(entry.getKey(), entry.getValue());
}
caps.setCapability(ChromeOptions.CAPABILITY, options);
caps.merge(driverOptions.getCapabilities());

0 comments on commit 641ab94

Please sign in to comment.
You can’t perform that action at this time.