From bfb53a51a545cd0a03e03eab485ee712b88ae906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AD=E5=AE=87=E7=90=A6?= <465645774@qq.com> Date: Fri, 30 Oct 2020 19:08:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=AF=BB=E5=8F=96=E6=97=A0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=AD=98=E5=82=A8=E5=85=83=E7=B4=A0=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../selenium/location/NoFileLocation.java | 165 ++++++++++++++++++ .../selenium/location/NoFileLocationTest.java | 92 ++++++++++ 2 files changed, 257 insertions(+) create mode 100644 src/main/java/pres/auxiliary/work/selenium/location/NoFileLocation.java create mode 100644 src/test/java/pres/auxiliary/work/selenium/location/NoFileLocationTest.java diff --git a/src/main/java/pres/auxiliary/work/selenium/location/NoFileLocation.java b/src/main/java/pres/auxiliary/work/selenium/location/NoFileLocation.java new file mode 100644 index 0000000..7f633e4 --- /dev/null +++ b/src/main/java/pres/auxiliary/work/selenium/location/NoFileLocation.java @@ -0,0 +1,165 @@ +package pres.auxiliary.work.selenium.location; + +import java.util.ArrayList; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +import pres.auxiliary.work.selenium.element.ElementType; + +/** + *
文件名:NoFileLocation.java
+ *用途: + * 提供在不编写元素定位文件的情况下读取元素定位方法,通过该类,可存储一些临时添加的元素定位 + * 方式,并在编写脚本过程中进行调用 + *
+ *编码时间:2020年10月29日上午8:38:24
+ *修改时间:2020年10月29日上午8:38:24
+ * @author 彭宇琦 + * @version Ver1.0 + */ +public class NoFileLocation extends AbstractLocation implements WriteLocation, WriteTempletLocation { + /** + * 存储json的读取方式 + */ + private JsonLocation jsonLocation; + /** + * 用于存储当前通过方法添加的元素信息 + */ + private JSONObject nowLocationJson; + /** + * 用于存储通过新增方法添加的元素信息 + */ + private JSONObject newLocationJson; + + /** + * 构造类对象 + */ + public NoFileLocation() { + //初始化json参数 + nowLocationJson = new JSONObject(); + nowLocationJson.put(JsonLocation.KEY_TEMPLETE, new JSONObject()); + nowLocationJson.put(JsonLocation.KEY_ELEMENT, new JSONObject()); + //克隆当前元素json信息 + newLocationJson = (JSONObject) nowLocationJson.clone(); + + //初始化json定位类对象 + jsonLocation = new JsonLocation(nowLocationJson.toJSONString()); + } + + @Override + public void putElementLocation(String name, ByType byType, String value) { + //获取元素对象 + JSONObject elementJson = getElementJson(name); + //获取对象的location键值,若键值不存在,则添加键值 + if (!elementJson.containsKey(JsonLocation.KEY_LOCATION)) { + elementJson.put(JsonLocation.KEY_LOCATION, new JSONArray()); + } + + //封装定位方式 + JSONObject locationJson = new JSONObject(); + locationJson.put(JsonLocation.KEY_TYPE, byType.getValue()); + locationJson.put(JsonLocation.KEY_VALUE, value); + + //向定位方式组中添加定位方式 + elementJson.getJSONArray(JsonLocation.KEY_LOCATION).add(locationJson); + } + + @Override + public void putElementTempletLocation(String name, ByType byType, String templetId) { + //获取元素对象 + JSONObject elementJson = getElementJson(name); + //获取对象的location键值,若键值不存在,则添加键值 + if (!elementJson.containsKey(JsonLocation.KEY_LOCATION)) { + elementJson.put(JsonLocation.KEY_LOCATION, new JSONArray()); + } + + //封装定位方式 + JSONObject locationJson = new JSONObject(); + locationJson.put(JsonLocation.KEY_TEMP, templetId); + locationJson.put(JsonLocation.KEY_TYPE, byType.getValue()); + + //向定位方式组中添加定位方式 + elementJson.getJSONArray(JsonLocation.KEY_LOCATION).add(locationJson); + } + + @Override + public void putElementType(String name, ElementType elementType) { + //获取元素对象,并存储键值 + getElementJson(name).put(JsonLocation.KEY_TYPE, elementType.getValue()); + } + + @Override + public void putIframeNameList(String name, String iframeName) { + //获取元素对象,并存储键值 + getElementJson(name).put(JsonLocation.KEY_IFRAME, iframeName); + } + + @Override + public void putWaitTime(String name, long waitTime) { + //获取元素对象,并存储键值 + getElementJson(name).put(JsonLocation.KEY_WAIT, waitTime); + } + + @Override + public void putTemplet(String templetId, String templetValue) { + newLocationJson.getJSONObject((JsonLocation.KEY_TEMPLETE)).put(templetId, templetValue); + } + + @Override + public void putTempletReplaceKey(String name, String templetId, String key, String value) { + // TODO Auto-generated method stub + + } + + @Override + public ArrayList