Permalink
Browse files

updated selenium and updated json.

  • Loading branch information...
1 parent bbdcd3d commit 23e6cf0ece106629b06233cff0ae7df052a8337a @alvinrdeleon alvinrdeleon committed Feb 27, 2013
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2012. JSpringBot. All Rights Reserved.
+ *
+ * See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The JSpringBot licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jspringbot.keyword.expression;
+
+import org.jspringbot.KeywordInfo;
+import org.jspringbot.syntax.HighlightRobotLogger;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+import java.util.List;
+
+@Component
+@KeywordInfo(
+ name = "EL Run Keyword If",
+ parameters = {"condition", "keyword", "*keywordArgs"},
+ description = "classpath:desc/ELRunKeywordIf.txt"
+)
+public class ELRunKeywordIf extends AbstractExpressionKeyword {
+ public static final HighlightRobotLogger LOG = HighlightRobotLogger.getLogger(ExpressionHelper.class);
+
+ @Override
+ public Object execute(final Object[] params) throws Exception {
+ if(Boolean.class.isInstance(params[0])) {
+ throw new IllegalArgumentException("Expecting condition with boolean result on first argument.");
+ }
+
+ if((Boolean) params[0]) {
+ List<Object> items = Arrays.asList(params);
+
+ if(items.size() <= 2) {
+ return ELRunKeyword.runKeyword(String.valueOf(params[1]));
+ } else {
+ return ELRunKeyword.runKeyword(String.valueOf(params[1]), items.subList(2, items.size()));
+ }
+ }
+
+ return null;
+ }
+}
@@ -118,9 +118,17 @@ public String getJsonString() {
return items;
}
+ public JSONObject getRoot() {
+ return JsonPath.read(jsonString, "$");
+ }
+
public Object getJsonValue(String jsonExpression) {
validate();
+ if(jsonExpression.equals("*")) {
+ return getRoot();
+ }
+
Object jsonValue = JsonPath.read(jsonString, "$." + jsonExpression);
if(jsonValue instanceof List) {
@@ -6,6 +6,7 @@
import org.jspringbot.syntax.HighlightRobotLogger;
import javax.xml.transform.TransformerException;
+import java.util.ArrayList;
import java.util.List;
public class JSONUtils {
@@ -26,6 +27,24 @@ public static Object object(Object... args) throws TransformerException {
return null;
}
+ public static List<String> propertyNames(String... args) throws TransformerException {
+ String path = "*";
+ JSONObject object;
+
+ if(args.length == 1 && String.class.isInstance(args[0])) {
+ path = args[0];
+ }
+
+
+ object = (JSONObject) getHelper().getJsonValue(path);
+
+ if(object == null) {
+ throw new IllegalStateException(String.format("Unable to find object keys given '%s'", path));
+ }
+
+ return new ArrayList<String>(object.keySet());
+ }
+
public static List objects(Object... args) throws TransformerException {
if(args.length == 2 && JSONObject.class.isInstance(args[0]) && String.class.isInstance(args[1])) {
JSONObject jsonObject = (JSONObject) args[0];
@@ -14,6 +14,12 @@
<function-signature>net.minidev.json.JSONObject object(java.lang.Object[])</function-signature>
</function>
<function>
+ <name>propertyNames</name>
+ <prefix>json</prefix>
+ <function-class>org.jspringbot.keyword.json.JSONUtils</function-class>
+ <function-signature>java.util.List propertyNames(java.lang.String[])</function-signature>
+ </function>
+ <function>
<name>property</name>
<prefix>json</prefix>
<function-class>org.jspringbot.keyword.json.JSONUtils</function-class>
@@ -46,6 +46,13 @@
private StartJSONObject startJSONObject;
@Test
+ public void testRoot() throws Exception {
+ helper.setJsonString("{ \"pc1\" : \"S1\", \"bc1\" : \"H4\", \"pc2\" : \"H0\", \"bc2\" : \"HQ\", \"pcd\" : \"H5\", \"bcd\" : \"S4\" }");
+
+ System.out.println(helper.getRoot());
+ }
+
+ @Test
public void testGetJsonValues() throws JSONException, TokenStreamException, RecognitionException {
creator.startJSONObject();
creator.startJSONObject("store");
@@ -87,7 +87,7 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
- <version>2.28.0</version>
+ <version>2.30.0</version>
</dependency>
<dependency>
<groupId>junit-addons</groupId>

0 comments on commit 23e6cf0

Please sign in to comment.