Commit 974120dc authored by ShangLiPeng's avatar ShangLiPeng

modify rpa

parent 025a4e15
......@@ -158,6 +158,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.2.RELEASE</version>
<configuration>
<excludes>
<exclude>
......@@ -170,6 +171,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>17</source>
<target>17</target>
......@@ -197,6 +199,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-dependencies</id>
......@@ -218,7 +221,9 @@
<!--三、把依赖也打进jar包:mainClass是jar包的main方法入口-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<archive>
<manifest>
......
package com.greatchn;
import cn.hutool.core.io.resource.ClassPathResource;
import com.greatchn.kits.ChromeKits;
import com.greatchn.yzh.TaskExecutor;
import io.netty.util.internal.ResourcesUtil;
import java.awt.*;
/**
* RPA With Selenium for Java 入口
......@@ -11,8 +15,8 @@ import com.greatchn.yzh.TaskExecutor;
*/
public class Main {
public static void main(String[] args) throws Exception {
System.out.println("准备结束chrome进程");
ChromeKits.killBrowser();
ChromeKits.utilBrowserStart("./files/chrome_no_proxy.bat");
new TaskExecutor();
}
}
\ No newline at end of file
......@@ -206,7 +206,7 @@ public class LoginFunction extends BaseFunction {
})();
""", Object.class);
rpa().listen("apps/view/login.html");
} catch (NoSuchElementException ignored) {
} catch (Exception ignored) {
// 尝试性操作异常不需要处理
}
}
......
package com.greatchn.kits;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.resource.ClassPathResource;
import org.apache.commons.lang3.StringUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Date;
......@@ -14,13 +17,18 @@ public class ChromeKits {
ProcessKits.killProcess(Arrays.asList( "firefox","geckodriver","crashreporter","chromedriver","chrome"));
}
//创建浏览器
public static String utilBrowserStart(String batPath) throws Exception
public static String utilBrowserStart(String cmd)
{
Runtime rt = Runtime.getRuntime();
try
{
Process process = rt.exec(new File(batPath).getAbsolutePath());
//cmd /c dir 是执行完dir命令后关闭命令窗口。
//cmd /k dir 是执行完dir命令后不关闭命令窗口。
//cmd /c start dir 会打开一个新窗口后执行dir指令,原窗口会关闭。
//cmd /k start dir 会打开一个新窗口后执行dir指令,原窗口不会关闭。
// String cmd="cmd /k "+new File(batPath).getAbsolutePath();
System.out.println(cmd);
Process process = rt.exec(cmd);
// 获取启动返回信息
InputStreamReader isr = new InputStreamReader(process.getErrorStream());
......@@ -55,7 +63,7 @@ public class ChromeKits {
}
catch (Exception e)
{
throw e;
throw new RuntimeException(e.getMessage());
}
}
}
......@@ -3,6 +3,7 @@ package com.greatchn.rpa;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.greatchn.kits.ChromeKits;
import com.greatchn.kits.JacksonKits;
import com.greatchn.kits.RandomKits;
import com.greatchn.rpa.beans.Point;
......@@ -101,7 +102,7 @@ public class RpaCore {
*
* @param config 配置参数
*/
public RpaCore(RpaConfig config) {
public RpaCore(RpaConfig config) {
this.config = config;
this.scale = config.getScale();
......@@ -204,6 +205,7 @@ public class RpaCore {
}
//手动启动浏览器
if (this.config.isRemoteDebugging() == true) {
ChromeKits.utilBrowserStart(this.config.getRemoteDebuggingCmd());
options.setExperimentalOption("debuggerAddress", this.config.getRemoteDebuggingIP() + ":" + this.config.getRemoteDebuggingPort());
}
//Mobo
......
......@@ -28,7 +28,7 @@ public class RpaConfig {
private boolean remoteDebugging;
private int remoteDebuggingPort;
private String remoteDebuggingIP;
private String remoteDebuggingCmd;
/**
* 使用默认配置文件加载配置
*
......
......@@ -21,9 +21,14 @@ useSeleniumDrag: true
networkProxy: true
#是否使用selenium来自动启动浏览器
remoteDebugging: true
remoteDebugging: false
remoteDebuggingPort: 9222
remoteDebuggingIP: "127.0.0.1"
# cmd /b /Google/Chrome/Application/chrome.exe --remote-debugging-port=9222 --user-data-dir=/selenium/ChromeProfile --allow-pre-commit-input --disable-background-networking --disable-backgrounding-occluded-windows --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-blink-features=ShadowDOMV0 --enable-logging --ignore-certificate-errors --log-level=3 --no-service-autorun --password-store=basic --start-maximized --test-type --use-mock-keychain --flag-switches-begin --flag-switches-end
#remoteDebuggingCmd: "/Google/Chrome/Application/chrome.exe --remote-debugging-port=9222 --user-data-dir=/selenium/ChromeProfile --allow-pre-commit-input --disable-background-networking --disable-backgrounding-occluded-windows --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-blink-features=ShadowDOMV0 --enable-logging --ignore-certificate-errors --log-level=3 --no-service-autorun --password-store=basic --start-maximized --test-type --use-mock-keychain --flag-switches-begin --flag-switches-end"
#remoteDebuggingCmd: "cmd.exe /c start /b C:\\Google\\Chrome\\Application\\chrome.bat"
remoteDebuggingCmd: "cmd.exe /c start /b C:\\Google\\Chrome\\Application\\chrome.bat"
scale: 1.00
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment