利辛自动化小程序
This commit is contained in:
parent
6aa940158d
commit
3f545da5e8
|
|
@ -1,6 +1,5 @@
|
||||||
package com.bonus.autoweb.base;
|
package com.bonus.autoweb.base;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.JavascriptExecutor;
|
import org.openqa.selenium.JavascriptExecutor;
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
|
|
@ -23,31 +22,34 @@ import java.util.concurrent.TimeUnit;
|
||||||
public class AutoMain {
|
public class AutoMain {
|
||||||
|
|
||||||
Logger log = LoggerFactory.getLogger(AutoMain.class);
|
Logger log = LoggerFactory.getLogger(AutoMain.class);
|
||||||
/**
|
|
||||||
* A {@link WebDriver} instance used for browser automation and control.
|
|
||||||
* This object represents a browser window or tab, allowing interactions with web pages,
|
|
||||||
* navigation, form filling, and other browser-related tasks in a programmatic manner.
|
|
||||||
*
|
|
||||||
* @see <a href="https://www.selenium.dev/documentation/en/webdriver/">Selenium WebDriver documentation</a>
|
|
||||||
*/
|
|
||||||
//浏览器驱动对象
|
//浏览器驱动对象
|
||||||
@Getter
|
|
||||||
private WebDriver webDriver;
|
private WebDriver webDriver;
|
||||||
|
|
||||||
|
public WebDriver getWebDriver() {
|
||||||
|
return webDriver;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化驱动
|
* 初始化驱动
|
||||||
*/
|
*/
|
||||||
public void initDrive(int type) {
|
public void initDrive(int type) {
|
||||||
// chromedriver服务地址
|
// chromedriver服务地址
|
||||||
System.setProperty(DataConfig.DRIVE_NAME, DataConfig.DRIVE_PATH);
|
System.setProperty(DataConfig.DRIVE_NAME, DataConfig.drivePath);
|
||||||
ChromeOptions option = new ChromeOptions();
|
ChromeOptions option = new ChromeOptions();
|
||||||
//添加浏览器地址
|
//添加浏览器地址
|
||||||
|
// option.setBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");//个人本地
|
||||||
option.setBinary("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe");//个人本地
|
option.setBinary("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe");//个人本地
|
||||||
|
// option.setBinary("C:\\Users\\19814\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");//个人本地
|
||||||
|
// option.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
|
||||||
|
// option.setBinary("C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");//宿州
|
||||||
|
// option.addArguments("start-fullscreen");
|
||||||
option.addArguments("--start-maximized");
|
option.addArguments("--start-maximized");
|
||||||
option.addArguments("--force-device-scale-factor=0.75");
|
option.addArguments("--force-device-scale-factor=0.75");
|
||||||
option.addArguments("disable-infobars");
|
option.addArguments("disable-infobars");
|
||||||
|
|
||||||
//隐藏页面
|
//隐藏页面
|
||||||
|
// option.addArguments("--headless");
|
||||||
|
// webDriver = new FirefoxDriver(option);
|
||||||
webDriver = new ChromeDriver(option);
|
webDriver = new ChromeDriver(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,6 +138,16 @@ public class AutoMain {
|
||||||
*/
|
*/
|
||||||
private void openDuty() throws InterruptedException {
|
private void openDuty() throws InterruptedException {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// WebElement alertDiv = webDriver.findElement(By.xpath("/html/body/div[2]/div/div[1]/div/div[1]/div[1]/span"));
|
||||||
|
// if(alertDiv.getText()) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }catch (Exception e){
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
|
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -198,7 +210,16 @@ public class AutoMain {
|
||||||
log.info("管理标签的ID值为:" + attributeId);
|
log.info("管理标签的ID值为:" + attributeId);
|
||||||
Thread.sleep(300);
|
Thread.sleep(300);
|
||||||
|
|
||||||
|
|
||||||
|
// //执行鼠标悬停动作-常态值班
|
||||||
|
// String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div[2]/div[3]";
|
||||||
|
// WebElement wectzb = webDriver.findElement(By.xpath(ctzbXpath));
|
||||||
|
// action.moveToElement(wectzb).build().perform();
|
||||||
|
// Thread.sleep(300);
|
||||||
|
|
||||||
|
|
||||||
//打开预警响应管理页面
|
//打开预警响应管理页面
|
||||||
|
//*[@id=\"" + attributeId + "\"]/div/div[2]/div[2]/div[1]/div[2]
|
||||||
String zbglXpath = "//*[@id=\"" + attributeId + "\"]/div/div/div[2]/div[3]";
|
String zbglXpath = "//*[@id=\"" + attributeId + "\"]/div/div/div[2]/div[3]";
|
||||||
webDriver.findElement(By.xpath(zbglXpath)).click();
|
webDriver.findElement(By.xpath(zbglXpath)).click();
|
||||||
log.info("打开预警页面------------");
|
log.info("打开预警页面------------");
|
||||||
|
|
@ -228,7 +249,16 @@ public class AutoMain {
|
||||||
log.info("管理标签的ID值为:" + attributeId);
|
log.info("管理标签的ID值为:" + attributeId);
|
||||||
Thread.sleep(300);
|
Thread.sleep(300);
|
||||||
|
|
||||||
|
|
||||||
|
// //执行鼠标悬停动作-预警行动
|
||||||
|
// String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div[2]/div[4]";
|
||||||
|
// WebElement wectzb = webDriver.findElement(By.xpath(ctzbXpath));
|
||||||
|
// action.moveToElement(wectzb).build().perform();
|
||||||
|
// Thread.sleep(300);
|
||||||
|
|
||||||
|
|
||||||
//打开预警响应管理页面
|
//打开预警响应管理页面
|
||||||
|
//*[@id=\"" + attributeId + "\"]/div/div[2]/div[2]/div[1]/div[2]
|
||||||
String zbglXpath = "//*[@id=\"" + attributeId + "\"]/div/div/div[2]/div[4]";
|
String zbglXpath = "//*[@id=\"" + attributeId + "\"]/div/div/div[2]/div[4]";
|
||||||
webDriver.findElement(By.xpath(zbglXpath)).click();
|
webDriver.findElement(By.xpath(zbglXpath)).click();
|
||||||
log.info("打开预警页面------------");
|
log.info("打开预警页面------------");
|
||||||
|
|
@ -265,15 +295,28 @@ public class AutoMain {
|
||||||
//执行鼠标悬停动作-检查操练管理
|
//执行鼠标悬停动作-检查操练管理
|
||||||
String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div[2]/div[5]";
|
String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div[2]/div[5]";
|
||||||
webDriver.findElement(By.xpath(ctzbXpath)).click();
|
webDriver.findElement(By.xpath(ctzbXpath)).click();
|
||||||
|
// WebElement wectzb =
|
||||||
|
// action.moveToElement(wectzb).build().perform();
|
||||||
Thread.sleep(1500);
|
Thread.sleep(1500);
|
||||||
|
|
||||||
//打开日常操练页面
|
//打开日常操练页面
|
||||||
|
//*[@id=\"" + attributeId + "\"]/div/div[2]/div[2]/div[1]/div[2]
|
||||||
|
// String zbglXpath = "//*[@id=\"" + attributeId + "\"]/div/div[2]/div[2]/div/div[1]";
|
||||||
|
// webDriver.findElement(By.xpath(zbglXpath)).click();
|
||||||
|
// log.info("打开日常操练页面------------");
|
||||||
// /* TODO 800 --> 1500 */
|
// /* TODO 800 --> 1500 */
|
||||||
|
// Thread.sleep(1500);
|
||||||
|
|
||||||
//定位日常操练iframe的标签
|
//定位日常操练iframe的标签
|
||||||
WebElement dutyIframe = webDriver.findElement(By.id("rccl"));
|
WebElement dutyIframe = webDriver.findElement(By.id("rccl"));
|
||||||
webDriver.switchTo().frame(dutyIframe);
|
webDriver.switchTo().frame(dutyIframe);
|
||||||
log.info("定位到日常操练iframe-----------");
|
log.info("定位到日常操练iframe-----------");
|
||||||
Thread.sleep(8000);
|
Thread.sleep(8000);
|
||||||
|
//定位日常操练iframe的标签
|
||||||
|
// WebElement insideIframe = webDriver.findElement(By.xpath("/html/body/div/section/div[1]/div[2]/div/iframe"));
|
||||||
|
// webDriver.switchTo().frame(insideIframe);
|
||||||
|
// log.info("定位到日常操练内部iframe-----------");
|
||||||
|
// Thread.sleep(3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -311,10 +354,17 @@ public class AutoMain {
|
||||||
//执行鼠标悬停动作-检查操练管理
|
//执行鼠标悬停动作-检查操练管理
|
||||||
String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div[2]/div[5]";
|
String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div[2]/div[5]";
|
||||||
webDriver.findElement(By.xpath(ctzbXpath)).click();
|
webDriver.findElement(By.xpath(ctzbXpath)).click();
|
||||||
|
// WebElement wectzb =
|
||||||
|
// action.moveToElement(wectzb).build().perform();
|
||||||
Thread.sleep(1500);
|
Thread.sleep(1500);
|
||||||
|
|
||||||
//打开检查计划页面
|
//打开检查计划页面
|
||||||
|
//*[@id=\"" + attributeId + "\"]/div/div[2]/div[2]/div[1]/div[2]
|
||||||
|
// String zbglXpath = "//*[@id=\"" + attributeId + "\"]/div/div[2]/div[2]/div/div[1]";
|
||||||
|
// webDriver.findElement(By.xpath(zbglXpath)).click();
|
||||||
|
// log.info("打开日常操练页面------------");
|
||||||
// /* TODO 800 --> 1500 */
|
// /* TODO 800 --> 1500 */
|
||||||
|
// Thread.sleep(1500);
|
||||||
|
|
||||||
//定位检查计划iframe的标签
|
//定位检查计划iframe的标签
|
||||||
WebElement dutyIframe = webDriver.findElement(By.id("rccl"));
|
WebElement dutyIframe = webDriver.findElement(By.id("rccl"));
|
||||||
|
|
@ -324,5 +374,10 @@ public class AutoMain {
|
||||||
//点击抽查按钮
|
//点击抽查按钮
|
||||||
webDriver.findElement(By.xpath("/html/body/div/section/div[1]/div[1]/div/div/div/div[3]")).click();
|
webDriver.findElement(By.xpath("/html/body/div/section/div[1]/div[1]/div/div/div/div[3]")).click();
|
||||||
|
|
||||||
|
// //定位日常操练iframe的标签
|
||||||
|
// WebElement insideIframe = webDriver.findElement(By.xpath("/html/body/div/section/div[1]/div[2]/div/iframe"));
|
||||||
|
// webDriver.switchTo().frame(insideIframe);
|
||||||
|
// log.info("定位到日常操练内部iframe-----------");
|
||||||
|
// Thread.sleep(3000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,6 @@ import java.io.*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Lenovo
|
|
||||||
*/
|
|
||||||
public class AutoUtils {
|
public class AutoUtils {
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue