ui自动化执行接口
This commit is contained in:
@@ -855,4 +855,16 @@ public class SeleniumUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在新标签页打开URL
|
||||||
|
* @param url 要打开的网址
|
||||||
|
*/
|
||||||
|
public void openUrlInNewTab(String url) {
|
||||||
|
// 打开新标签页
|
||||||
|
driver.switchTo().newWindow(WindowType.TAB);
|
||||||
|
|
||||||
|
// 导航到目标URL
|
||||||
|
driver.get(url);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ public class UiAutomationController extends BaseController
|
|||||||
*/
|
*/
|
||||||
// @PreAuthorize("@ss.hasPermi('system:automation:remove')")
|
// @PreAuthorize("@ss.hasPermi('system:automation:remove')")
|
||||||
@GetMapping("/executeStep")
|
@GetMapping("/executeStep")
|
||||||
public AjaxResult remove(@RequestParam Long id)
|
public AjaxResult executeStep(@RequestParam Long id)
|
||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
log.info("执行完成!");
|
log.info("执行完成!");
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ public class UiAutomationServiceImpl implements IUiAutomationService {
|
|||||||
uiAutomation.setUpdateTime(DateUtils.getNowDate());
|
uiAutomation.setUpdateTime(DateUtils.getNowDate());
|
||||||
uiAutomation.setCreateBy(SecurityUtils.getUsername());
|
uiAutomation.setCreateBy(SecurityUtils.getUsername());
|
||||||
uiAutomation.setUpdateBy(SecurityUtils.getUsername());
|
uiAutomation.setUpdateBy(SecurityUtils.getUsername());
|
||||||
uiAutomation.setStatus("1"); //未开始
|
// uiAutomation.setStatus("1"); //未开始
|
||||||
uiAutomation.setDutyBy(SecurityUtils.getUsername());
|
uiAutomation.setDutyBy(SecurityUtils.getUsername());
|
||||||
uiAutomation.setDelFlag(0);
|
uiAutomation.setDelFlag(0);
|
||||||
uiAutomation.setCrontabStatus(0); //未开启
|
uiAutomation.setCrontabStatus(0); //未开启
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.openqa.selenium.WebElement;
|
|||||||
import org.openqa.selenium.chrome.ChromeDriver;
|
import org.openqa.selenium.chrome.ChromeDriver;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
@@ -45,7 +46,8 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
@Resource
|
@Resource
|
||||||
private UiAutomationMapper uiAutomationMapper;
|
private UiAutomationMapper uiAutomationMapper;
|
||||||
|
|
||||||
|
@Value("${test.selenium.chrome-driver-path}")
|
||||||
|
private String chromeDriverPath;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,9 +65,9 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
|
|
||||||
//修改ui_automation 状态为进行中 执行结果为running
|
//修改ui_automation 状态为进行中 执行结果为running
|
||||||
UiAutomation uiAutomation = new UiAutomation();
|
UiAutomation uiAutomation = new UiAutomation();
|
||||||
uiAutomation.setStatus("2");
|
uiAutomation.setId(automationId);
|
||||||
uiAutomation.setExecutionResult("1");
|
uiAutomation.setExecutionResult("1");
|
||||||
uiAutomation.setUpdateBy(DateUtils.getTime());
|
uiAutomation.setUpdateTime(DateUtils.getNowDate());
|
||||||
uiAutomationMapper.updateUiAutomation(uiAutomation);
|
uiAutomationMapper.updateUiAutomation(uiAutomation);
|
||||||
|
|
||||||
|
|
||||||
@@ -138,15 +140,16 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
uiReportService.updateUiReport(uiReport);
|
uiReportService.updateUiReport(uiReport);
|
||||||
|
|
||||||
//修改ui_automation
|
//修改ui_automation
|
||||||
uiAutomation = new UiAutomation();
|
UiAutomation uiAutomation1 = new UiAutomation();
|
||||||
|
uiAutomation1.setId(automationId);
|
||||||
|
uiAutomation1.setExecutionResult("2");
|
||||||
if (!uiAutomation.getExecutionResult().equals("2")) {
|
if (!uiAutomation.getExecutionResult().equals("2")) {
|
||||||
uiAutomation.setExecutionResult("3");
|
uiAutomation1.setExecutionResult("3");
|
||||||
uiAutomation.setStatus("3");
|
|
||||||
}
|
}
|
||||||
uiAutomation.setUpdateBy(DateUtils.getTime());
|
uiAutomation1.setUpdateTime(DateUtils.getNowDate());
|
||||||
uiAutomation.setPassRate(stepsSucceedNumber == 0 ? "0%" :
|
uiAutomation1.setPassRate(stepsSucceedNumber == 0 ? "0%" :
|
||||||
String.format("%.2f%%", (double) stepsSucceedNumber / steps.size() * 100));
|
String.format("%.2f%%", (double) stepsSucceedNumber / steps.size() * 100));
|
||||||
uiAutomationMapper.updateUiAutomation(uiAutomation);
|
uiAutomationMapper.updateUiAutomation(uiAutomation1);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -194,7 +197,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
* @param steps
|
* @param steps
|
||||||
*/
|
*/
|
||||||
private void executeAllSteps(List<UiSceneSteps> steps, Long reportId) {
|
private void executeAllSteps(List<UiSceneSteps> steps, Long reportId) {
|
||||||
System.setProperty("webdriver.chrome.driver", "D:/chromedriver-win64/chromedriver.exe");
|
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
|
||||||
WebDriver driver = new ChromeDriver();
|
WebDriver driver = new ChromeDriver();
|
||||||
SeleniumUtils seleniumUtils = new SeleniumUtils(driver);
|
SeleniumUtils seleniumUtils = new SeleniumUtils(driver);
|
||||||
Integer orderNumber = 0;
|
Integer orderNumber = 0;
|
||||||
@@ -265,7 +268,6 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行步骤并记录日志
|
* 执行步骤并记录日志
|
||||||
*
|
*
|
||||||
@@ -286,6 +288,13 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
Integer screenshotConfiguration = otherSettingsQO.getScreenshotConfiguration(); //是否截图 1当前步骤截图 2异常截图 3 不截图
|
Integer screenshotConfiguration = otherSettingsQO.getScreenshotConfiguration(); //是否截图 1当前步骤截图 2异常截图 3 不截图
|
||||||
//等待元素超时时间
|
//等待元素超时时间
|
||||||
Integer waitElementTime = otherSettingsQO.getWaitElementTime() == null ? 0 : otherSettingsQO.getWaitElementTime();
|
Integer waitElementTime = otherSettingsQO.getWaitElementTime() == null ? 0 : otherSettingsQO.getWaitElementTime();
|
||||||
|
if (waitElementTime > 0) {
|
||||||
|
// 转换为秒(至少1秒)
|
||||||
|
long timeoutInSeconds = Math.max(1, waitElementTime / 1000);
|
||||||
|
log.info("元素等待时间{}秒", timeoutInSeconds);
|
||||||
|
seleniumUtils.setWaitTimeout(timeoutInSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
//前置操作设置
|
//前置操作设置
|
||||||
List<UiHighSettingVO> beforeSettingList = extractbeforeSetting(uiHighSettingVOList);
|
List<UiHighSettingVO> beforeSettingList = extractbeforeSetting(uiHighSettingVOList);
|
||||||
//后置操作设置
|
//后置操作设置
|
||||||
@@ -350,6 +359,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 提取前置操作
|
* 提取前置操作
|
||||||
|
*
|
||||||
* @param settings
|
* @param settings
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -361,6 +371,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取(前置//后置)等待时间
|
* 获取(前置//后置)等待时间
|
||||||
|
*
|
||||||
* @param settingList
|
* @param settingList
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -384,6 +395,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 提取后置操作
|
* 提取后置操作
|
||||||
|
*
|
||||||
* @param settings
|
* @param settings
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -395,6 +407,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 提取错误处理设置
|
* 提取错误处理设置
|
||||||
|
*
|
||||||
* @param settings
|
* @param settings
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -406,10 +419,9 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提取错误处理设置
|
* 提取错误处理设置
|
||||||
|
*
|
||||||
* @param settings
|
* @param settings
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -421,11 +433,6 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------浏览器操作---------------------------
|
//---------------------浏览器操作---------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -435,8 +442,17 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
* @param seleniumUtils Selenium工具类
|
* @param seleniumUtils Selenium工具类
|
||||||
*/
|
*/
|
||||||
private void openWebPage(UiSceneSteps step, SeleniumUtils seleniumUtils) {
|
private void openWebPage(UiSceneSteps step, SeleniumUtils seleniumUtils) {
|
||||||
log.info("打开网页:{}",step.getUrl());
|
//追加页面,在新的页面打开url,不勾选覆盖当前url 0不追加 1追加
|
||||||
seleniumUtils.openUrl(step.getUrl());
|
Integer isAppendPage = step.getIsAppendPage(); // 0=当前页,1=新标签页
|
||||||
|
String url = step.getUrl();
|
||||||
|
log.info("打开网页:{}, 模式:{}", url, isAppendPage == 1 ? "新标签页" : "当前页");
|
||||||
|
if (isAppendPage != null && isAppendPage == 1) {
|
||||||
|
// 新标签页打开
|
||||||
|
seleniumUtils.openUrlInNewTab(url);
|
||||||
|
} else {
|
||||||
|
// 默认当前页打开
|
||||||
|
seleniumUtils.openUrl(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -447,7 +463,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
*/
|
*/
|
||||||
private void closeBrowser(UiSceneSteps step, SeleniumUtils seleniumUtils) {
|
private void closeBrowser(UiSceneSteps step, SeleniumUtils seleniumUtils) {
|
||||||
log.info("关闭网页");
|
log.info("关闭网页");
|
||||||
seleniumUtils.quit();
|
seleniumUtils.closeCurrentWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -746,6 +762,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 鼠标点击操作
|
* 鼠标点击操作
|
||||||
|
*
|
||||||
* @param step 步骤对象
|
* @param step 步骤对象
|
||||||
* @param seleniumUtils Selenium工具类
|
* @param seleniumUtils Selenium工具类
|
||||||
*/
|
*/
|
||||||
@@ -781,12 +798,13 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
throw new RuntimeException("鼠标操作类型必须是数字(1-5)", e);
|
throw new RuntimeException("鼠标操作类型必须是数字(1-5)", e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("鼠标操作执行失败", e);
|
log.error("鼠标操作执行失败", e);
|
||||||
throw new RuntimeException("鼠标操作失败: " + e.getMessage(), e);
|
throw new RuntimeException("鼠标操作失败: " + e, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 鼠标移动操作
|
* 鼠标移动操作
|
||||||
|
*
|
||||||
* @param step 步骤对象
|
* @param step 步骤对象
|
||||||
* @param seleniumUtils Selenium工具类
|
* @param seleniumUtils Selenium工具类
|
||||||
*/
|
*/
|
||||||
@@ -824,12 +842,13 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
throw new RuntimeException("鼠标移动类型必须是数字(1-2)", e);
|
throw new RuntimeException("鼠标移动类型必须是数字(1-2)", e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("鼠标移动操作执行失败", e);
|
log.error("鼠标移动操作执行失败", e);
|
||||||
throw new RuntimeException("鼠标移动操作失败: " + e.getMessage(), e);
|
throw new RuntimeException("鼠标移动操作失败: " + e, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入操作
|
* 输入操作
|
||||||
|
*
|
||||||
* @param step 步骤对象
|
* @param step 步骤对象
|
||||||
* @param seleniumUtils Selenium工具类
|
* @param seleniumUtils Selenium工具类
|
||||||
*/
|
*/
|
||||||
@@ -883,12 +902,13 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
|
|||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("输入操作执行失败", e);
|
log.error("输入操作执行失败", e);
|
||||||
throw new RuntimeException("输入操作失败: " + e.getMessage(), e);
|
throw new RuntimeException("输入操作失败: " + e, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传
|
* 文件上传
|
||||||
|
*
|
||||||
* @param step
|
* @param step
|
||||||
* @param seleniumUtils
|
* @param seleniumUtils
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
<if test="stepsErrorNumber != null "> and steps_error_number = #{stepsErrorNumber}</if>
|
<if test="stepsErrorNumber != null "> and steps_error_number = #{stepsErrorNumber}</if>
|
||||||
<if test="stepsNotNumber != null "> and steps_not_number = #{stepsNotNumber}</if>
|
<if test="stepsNotNumber != null "> and steps_not_number = #{stepsNotNumber}</if>
|
||||||
</where>
|
</where>
|
||||||
order by create_time asc
|
order by create_time desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectUiReportById" parameterType="Long" resultMap="UiReportResult">
|
<select id="selectUiReportById" parameterType="Long" resultMap="UiReportResult">
|
||||||
|
|||||||
@@ -49,5 +49,6 @@ export function executeAutomationData(query) {
|
|||||||
url: '/test/automation/executeStep',
|
url: '/test/automation/executeStep',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
params: query,
|
params: query,
|
||||||
|
timeout: 600000,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user