Index: ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/ALL.java =================================================================== diff -u -r26696 -r26708 --- ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/ALL.java (.../ALL.java) (revision 26696) +++ ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/ALL.java (.../ALL.java) (revision 26708) @@ -170,7 +170,7 @@ /** * 开启配置项 */ - CssdUtils.setAndWriteConfigByNameAndValue("enbaleCheckToConfirm", Boolean.toString(true));//开启清点确认 + Utils.setAndWriteConfigByNameAndValueForAutoTest("enbaleCheckToConfirm", true);//开启清点确认 /** * 一次性物品入库以及修改消毒物品包定义 @@ -187,8 +187,8 @@ /********************************* * 回收清点 *********************************/ -// logger.info("回收开始:"); -// Utils.DateTime(); + logger.info("回收开始:"); + Utils.DateTime(); final String SERVER_URL = Utils.settings.get("服务器地址").toString(); Utils.driver.get(SERVER_URL + "/?logonType=1080p"); login.login_secondSupplyRoom(false); Index: ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/tools/Utils.java =================================================================== diff -u -r26582 -r26708 --- ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/tools/Utils.java (.../Utils.java) (revision 26582) +++ ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/tools/Utils.java (.../Utils.java) (revision 26708) @@ -2,8 +2,13 @@ import java.awt.GraphicsConfiguration; import java.awt.GraphicsEnvironment; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URL; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -48,6 +53,8 @@ import com.fasterxml.jackson.core.JsonParser.Feature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.forgon.tools.Path; +import com.forgon.tools.util.ConfigUtils; import static org.monte.media.FormatKeys.EncodingKey; import static org.monte.media.FormatKeys.FrameRateKey; @@ -342,6 +349,92 @@ } + /** + * 根据key与value对config.js的进行设值 + * @param key + * @return + */ + public static String setAndWriteConfigByNameAndValueForAutoTest(String key , Object value){ + String configFilePath = ConfigUtils.getProjectName() + "/config.js"; + writeWebConfigInfoForAutoTest(configFilePath , key , value); + return null; + } + + /** + * 将配置项写进config.js文件 + * @param configFilePath + * @param key + * @param value + * @return + */ + private static JSONObject writeWebConfigInfoForAutoTest(String configFilePath , String key , Object value){ + JSONObject jsonObj = null; + + ObjectMapper mapper = new ObjectMapper().configure( + Feature.ALLOW_COMMENTS, true); + + mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); + mapper.configure(Feature.ALLOW_SINGLE_QUOTES, true); + Scanner scan = null; + try { + String rootPath = Path.getWebAppRoot() + "/disinfectsystem/config/"; + String content = readFullFile(rootPath + configFilePath); + int startIndex = content.indexOf("{"); + //json变量定义的头(即左花括号之前的部分) + String jsonHeadContent = content.substring(0,startIndex); + int endIndex = (content.lastIndexOf("}") + 1); + if (startIndex != -1 && endIndex != -1 && startIndex < endIndex) { + content = content.substring(startIndex, endIndex); + } + + jsonObj = mapper.readValue(content,JSONObject.class); + + jsonObj.put(key, value); + String writeContent = jsonHeadContent; + writeContent += jsonObj; + + FileWriter writer = new FileWriter(new File(rootPath + configFilePath)); + writer.write(writeContent); + writer.flush(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + }finally{ + if(scan != null){ + scan.close(); + } + } + return jsonObj; + } + + // 读取完整的文件 + private static String readFullFile(String Path) { + BufferedReader reader = null; + String laststr = ""; + try { + FileInputStream fileInputStream = new FileInputStream(Path); + InputStreamReader inputStreamReader = new InputStreamReader( + fileInputStream, "UTF-8"); + reader = new BufferedReader(inputStreamReader); + String tempString = null; + while ((tempString = reader.readLine()) != null) { + laststr += tempString + "\r\n"; + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return laststr; + } + /** 定位到弹出对话框的按钮 */ public static void LocaAndWait() { // Wait wait = new FluentWait(Utils.driver)