@@ -24,6 +24,7 @@ import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.stereotype.Service ;
import org.springframework.util.CollectionUtils ;
@@ -45,7 +46,8 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
@Resource
private UiAutomationMapper uiAutomationMapper ;
@Value ( " ${test.selenium.chrome-driver-path} " )
private String chromeDriverPath ;
/**
@@ -63,9 +65,9 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
//修改ui_automation 状态为进行中 执行结果为running
UiAutomation uiAutomation = new UiAutomation ( ) ;
uiAutomation . setStatus ( " 2 " ) ;
uiAutomation . setId ( automationId ) ;
uiAutomation . setExecutionResult ( " 1 " ) ;
uiAutomation . setUpdateBy ( DateUtils . getTim e ( ) ) ;
uiAutomation . setUpdateTime ( DateUtils . getNowDat e ( ) ) ;
uiAutomationMapper . updateUiAutomation ( uiAutomation ) ;
@@ -138,15 +140,16 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
uiReportService . updateUiReport ( uiReport ) ;
//修改ui_automation
uiAutomation = new UiAutomation ( ) ;
UiAutomation uiAutomation1 = new UiAutomation ( ) ;
uiAutomation1 . setId ( automationId ) ;
uiAutomation1 . setExecutionResult ( " 2 " ) ;
if ( ! uiAutomation . getExecutionResult ( ) . equals ( " 2 " ) ) {
uiAutomation . setExecutionResult ( " 3 " ) ;
uiAutomation . setStatus ( " 3 " ) ;
uiAutomation1 . setExecutionResult ( " 3 " ) ;
}
uiAutomation . setUpdateBy ( DateUtils . getTim e ( ) ) ;
uiAutomation . setPassRate ( stepsSucceedNumber = = 0 ? " 0% " :
uiAutomation1 . setUpdateTime ( DateUtils . getNowDat e ( ) ) ;
uiAutomation1 . setPassRate ( stepsSucceedNumber = = 0 ? " 0% " :
String . format ( " %.2f%% " , ( double ) stepsSucceedNumber / steps . size ( ) * 100 ) ) ;
uiAutomationMapper . updateUiAutomation ( uiAutomation ) ;
uiAutomationMapper . updateUiAutomation ( uiAutomation1 ) ;
}
return result ;
}
@@ -194,7 +197,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
* @param steps
*/
private void executeAllSteps ( List < UiSceneSteps > steps , Long reportId ) {
System . setProperty ( " webdriver.chrome.driver " , " D:/ chromed river-win64/chromedriver.exe " ) ;
System . setProperty ( " webdriver.chrome.driver " , chromeD riverPath ) ;
WebDriver driver = new ChromeDriver ( ) ;
SeleniumUtils seleniumUtils = new SeleniumUtils ( driver ) ;
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 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 ) ;
//后置操作设置
@@ -350,6 +359,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
/**
* 提取前置操作
*
* @param settings
* @return
*/
@@ -361,6 +371,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
/**
* 获取(前置//后置)等待时间
*
* @param settingList
* @return
*/
@@ -384,6 +395,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
/**
* 提取后置操作
*
* @param settings
* @return
*/
@@ -395,6 +407,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
/**
* 提取错误处理设置
*
* @param settings
* @return
*/
@@ -406,10 +419,9 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
}
/**
* 提取错误处理设置
*
* @param settings
* @return
*/
@@ -421,11 +433,6 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
}
//---------------------浏览器操作---------------------------
/**
@@ -435,8 +442,17 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
* @param seleniumUtils Selenium工具类
*/
private void openWebPage ( UiSceneSteps step , SeleniumUtils seleniumUtils ) {
log . info ( " 打开网页:{} " , step . getUrl ( ) ) ;
seleniumUtils . openUrl ( step . getUrl ( ) ) ;
//追加页面, 在新的页面打开url, 不勾选覆盖当前url 0不追加 1追加
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 ) {
log . info ( " 关闭网页 " ) ;
seleniumUtils . quit ( ) ;
seleniumUtils . closeCurrentWindow ( ) ;
}
/**
@@ -746,6 +762,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
/**
* 鼠标点击操作
*
* @param step 步骤对象
* @param seleniumUtils Selenium工具类
*/
@@ -781,12 +798,13 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
throw new RuntimeException ( " 鼠标操作类型必须是数字(1-5) " , e ) ;
} catch ( Exception e ) {
log . error ( " 鼠标操作执行失败 " , e ) ;
throw new RuntimeException ( " 鼠标操作失败: " + e . getMessage ( ) , e ) ;
throw new RuntimeException ( " 鼠标操作失败: " + e , e ) ;
}
}
/**
* 鼠标移动操作
*
* @param step 步骤对象
* @param seleniumUtils Selenium工具类
*/
@@ -824,12 +842,13 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
throw new RuntimeException ( " 鼠标移动类型必须是数字(1-2) " , e ) ;
} catch ( Exception e ) {
log . error ( " 鼠标移动操作执行失败 " , e ) ;
throw new RuntimeException ( " 鼠标移动操作失败: " + e . getMessage ( ) , e ) ;
throw new RuntimeException ( " 鼠标移动操作失败: " + e , e ) ;
}
}
/**
* 输入操作
*
* @param step 步骤对象
* @param seleniumUtils Selenium工具类
*/
@@ -883,12 +902,13 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
} catch ( Exception e ) {
log . error ( " 输入操作执行失败 " , e ) ;
throw new RuntimeException ( " 输入操作失败: " + e . getMessage ( ) , e ) ;
throw new RuntimeException ( " 输入操作失败: " + e , e ) ;
}
}
/**
* 文件上传
*
* @param step
* @param seleniumUtils
*/