Commit 974120dc authored by ShangLiPeng's avatar ShangLiPeng

modify rpa

parent 025a4e15
...@@ -158,6 +158,7 @@ ...@@ -158,6 +158,7 @@
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.2.RELEASE</version>
<configuration> <configuration>
<excludes> <excludes>
<exclude> <exclude>
...@@ -170,6 +171,7 @@ ...@@ -170,6 +171,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration> <configuration>
<source>17</source> <source>17</source>
<target>17</target> <target>17</target>
...@@ -197,6 +199,7 @@ ...@@ -197,6 +199,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId> <artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions> <executions>
<execution> <execution>
<id>copy-dependencies</id> <id>copy-dependencies</id>
...@@ -218,7 +221,9 @@ ...@@ -218,7 +221,9 @@
<!--三、把依赖也打进jar包:mainClass是jar包的main方法入口--> <!--三、把依赖也打进jar包:mainClass是jar包的main方法入口-->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId> <artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration> <configuration>
<archive> <archive>
<manifest> <manifest>
......
package com.greatchn; package com.greatchn;
import cn.hutool.core.io.resource.ClassPathResource;
import com.greatchn.kits.ChromeKits; import com.greatchn.kits.ChromeKits;
import com.greatchn.yzh.TaskExecutor; import com.greatchn.yzh.TaskExecutor;
import io.netty.util.internal.ResourcesUtil;
import java.awt.*;
/** /**
* RPA With Selenium for Java 入口 * RPA With Selenium for Java 入口
...@@ -11,8 +15,8 @@ import com.greatchn.yzh.TaskExecutor; ...@@ -11,8 +15,8 @@ import com.greatchn.yzh.TaskExecutor;
*/ */
public class Main { public class Main {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
System.out.println("准备结束chrome进程");
ChromeKits.killBrowser(); ChromeKits.killBrowser();
ChromeKits.utilBrowserStart("./files/chrome_no_proxy.bat");
new TaskExecutor(); new TaskExecutor();
} }
} }
\ No newline at end of file
...@@ -206,7 +206,7 @@ public class LoginFunction extends BaseFunction { ...@@ -206,7 +206,7 @@ public class LoginFunction extends BaseFunction {
})(); })();
""", Object.class); """, Object.class);
rpa().listen("apps/view/login.html"); rpa().listen("apps/view/login.html");
} catch (NoSuchElementException ignored) { } catch (Exception ignored) {
// 尝试性操作异常不需要处理 // 尝试性操作异常不需要处理
} }
} }
......
package com.greatchn.kits; package com.greatchn.kits;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.resource.ClassPathResource;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
...@@ -14,13 +17,18 @@ public class ChromeKits { ...@@ -14,13 +17,18 @@ public class ChromeKits {
ProcessKits.killProcess(Arrays.asList( "firefox","geckodriver","crashreporter","chromedriver","chrome")); 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(); Runtime rt = Runtime.getRuntime();
try try
{ {
//cmd /c dir 是执行完dir命令后关闭命令窗口。
Process process = rt.exec(new File(batPath).getAbsolutePath()); //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()); InputStreamReader isr = new InputStreamReader(process.getErrorStream());
...@@ -55,7 +63,7 @@ public class ChromeKits { ...@@ -55,7 +63,7 @@ public class ChromeKits {
} }
catch (Exception e) catch (Exception e)
{ {
throw e; throw new RuntimeException(e.getMessage());
} }
} }
} }
...@@ -3,6 +3,7 @@ package com.greatchn.rpa; ...@@ -3,6 +3,7 @@ package com.greatchn.rpa;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.greatchn.kits.ChromeKits;
import com.greatchn.kits.JacksonKits; import com.greatchn.kits.JacksonKits;
import com.greatchn.kits.RandomKits; import com.greatchn.kits.RandomKits;
import com.greatchn.rpa.beans.Point; import com.greatchn.rpa.beans.Point;
...@@ -101,7 +102,7 @@ public class RpaCore { ...@@ -101,7 +102,7 @@ public class RpaCore {
* *
* @param config 配置参数 * @param config 配置参数
*/ */
public RpaCore(RpaConfig config) { public RpaCore(RpaConfig config) {
this.config = config; this.config = config;
this.scale = config.getScale(); this.scale = config.getScale();
...@@ -204,6 +205,7 @@ public class RpaCore { ...@@ -204,6 +205,7 @@ public class RpaCore {
} }
//手动启动浏览器 //手动启动浏览器
if (this.config.isRemoteDebugging() == true) { if (this.config.isRemoteDebugging() == true) {
ChromeKits.utilBrowserStart(this.config.getRemoteDebuggingCmd());
options.setExperimentalOption("debuggerAddress", this.config.getRemoteDebuggingIP() + ":" + this.config.getRemoteDebuggingPort()); options.setExperimentalOption("debuggerAddress", this.config.getRemoteDebuggingIP() + ":" + this.config.getRemoteDebuggingPort());
} }
//Mobo //Mobo
......
...@@ -28,7 +28,7 @@ public class RpaConfig { ...@@ -28,7 +28,7 @@ public class RpaConfig {
private boolean remoteDebugging; private boolean remoteDebugging;
private int remoteDebuggingPort; private int remoteDebuggingPort;
private String remoteDebuggingIP; private String remoteDebuggingIP;
private String remoteDebuggingCmd;
/** /**
* 使用默认配置文件加载配置 * 使用默认配置文件加载配置
* *
......
...@@ -21,9 +21,14 @@ useSeleniumDrag: true ...@@ -21,9 +21,14 @@ useSeleniumDrag: true
networkProxy: true networkProxy: true
#是否使用selenium来自动启动浏览器 #是否使用selenium来自动启动浏览器
remoteDebugging: true remoteDebugging: false
remoteDebuggingPort: 9222 remoteDebuggingPort: 9222
remoteDebuggingIP: "127.0.0.1" 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 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