Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataease
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
zhu
dataease
Commits
12c8578d
提交
12c8578d
authored
11月 09, 2021
作者:
fit2cloud-chenyw
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 新增后台仪表板截图
上级
55acb8a5
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
93 行增加
和
0 行删除
+93
-0
pom.xml
backend/pom.xml
+5
-0
WebDriverUtils.java
...c/main/java/io/dataease/commons/utils/WebDriverUtils.java
+88
-0
没有找到文件。
backend/pom.xml
浏览文件 @
12c8578d
...
...
@@ -244,6 +244,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.seleniumhq.selenium
</groupId>
<artifactId>
selenium-java
</artifactId>
</dependency>
</dependencies>
<build>
...
...
backend/src/main/java/io/dataease/commons/utils/WebDriverUtils.java
0 → 100644
浏览文件 @
12c8578d
package
io
.
dataease
.
commons
.
utils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.openqa.selenium.OutputType
;
import
org.openqa.selenium.TakesScreenshot
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.chrome.ChromeDriver
;
import
org.openqa.selenium.chrome.ChromeDriverService
;
import
org.openqa.selenium.chrome.ChromeOptions
;
import
org.openqa.selenium.remote.Augmenter
;
import
org.springframework.core.env.Environment
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
/**
* 打印浏览器
*/
public
class
WebDriverUtils
{
private
static
String
driverPath
;
public
static
void
print
(
String
url
,
String
filePath
)
{
try
{
url
=
URLDecoder
.
decode
(
url
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
if
(
StringUtils
.
isBlank
(
driverPath
))
{
driverPath
=
CommonBeanFactory
.
getBean
(
Environment
.
class
).
getProperty
(
"dataease.chrome-driver-path"
,
String
.
class
,
"/usr/bin/chromedriver"
);
}
String
driverPath
=
"/usr/local/sbin/chromedriver"
;
ChromeOptions
options
=
new
ChromeOptions
();
options
.
addArguments
(
"headless"
);
options
.
addArguments
(
"no-sandbox"
);
options
.
addArguments
(
"disable-gpu"
);
options
.
addArguments
(
"disable-features=NetworkService"
);
options
.
addArguments
(
"ignore-certificate-errors"
);
options
.
addArguments
(
"silent-launch"
);
options
.
addArguments
(
"disable-application-cache"
);
options
.
addArguments
(
"disable-web-security"
);
options
.
addArguments
(
"no-proxy-server"
);
options
.
addArguments
(
"disable-dev-shm-usage"
);
WebDriver
driver
=
null
;
try
{
System
.
setProperty
(
ChromeDriverService
.
CHROME_DRIVER_EXE_PROPERTY
,
driverPath
);
driver
=
new
ChromeDriver
(
options
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
driver
.
get
(
url
);
WebDriver
augmentedDriver
=
new
Augmenter
().
augment
(
driver
);
File
screenshot
=
((
TakesScreenshot
)
augmentedDriver
)
.
getScreenshotAs
(
OutputType
.
FILE
);
File
file
=
new
File
(
filePath
);
copy
(
screenshot
,
file
);
driver
.
quit
();
}
private
static
void
copy
(
File
src
,
File
dest
)
{
try
{
FileInputStream
fis
=
new
FileInputStream
(
src
);
//创建输入流对象
FileOutputStream
fos
=
new
FileOutputStream
(
dest
);
//创建输出流对象
byte
datas
[]
=
new
byte
[
1024
*
8
];
//创建搬运工具
int
len
=
0
;
//创建长度
while
((
len
=
fis
.
read
(
datas
))!=-
1
)
//循环读取数据
{
fos
.
write
(
datas
,
0
,
len
);
}
fis
.
close
();
//释放资源
fis
.
close
();
//释放资源
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论