当前位置:网站首页>利用图片实现APP元素定位sikulix
利用图片实现APP元素定位sikulix
2022-06-22 13:17:00 【qq_492448446】
简介:Sikuli 是一种新颖的图形脚本语言,或者说是一种另类的自动化测试技术。它与我们常用的自动化测试技术(工具)有很大的区别。
sikulix jar包下载地址
SikuliX project files : SikuliX
在阿里云仓库也可以搜索这个jar包

需要下载以下3个包,
sikulixapi-2.0.5.jar sikulixapi-2.0.5-win.jar 用于windows
sikulixapi-2.0.5.jar sikulixapi-2.0.5-mac.jar 用于mac电脑

也可以在pom文件中添加,但是不建议采用此方法,这个包会有很多的依赖包,可能会下载失败
也可以参考:java+win7+eclipse+Maven+sikuli 配置总结---图形脚本语言 - 走看看
<dependency>
<groupId>com.sikulix</groupId>
<artifactId>sikulixapi</artifactId>
<version>1.1.0</version>
</dependency>
package com.welab.automation.projects.demo;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import lombok.SneakyThrows;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.sikuli.script.Screen;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.Base64;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import static io.appium.java_client.service.local.flags.GeneralServerFlag.LOG_LEVEL;
import static io.appium.java_client.service.local.flags.GeneralServerFlag.SESSION_OVERRIDE;
public class TestSikulix {
public static void main(String[] args) throws URISyntaxException, IOException {
TestSikulix testOpenCV = new TestSikulix();
testOpenCV.startMain();
}
AndroidDriver driver;
@SneakyThrows
public void startMain() throws URISyntaxException, IOException {
DesiredCapabilities devices = new DesiredCapabilities();
devices.setCapability("platformName", "Android");
devices.setCapability("deviceName","emulator-5554");
devices.setCapability("platformVersion", "10");
devices.setCapability("appPackage","com.android.settings");
devices.setCapability("appActivity","com.android.settings.Settings");
devices.setCapability("automation","uiautomator2");
devices.setCapability("unicodeKeyboard", true);
devices.setCapability("resetKeyboard",true);
//需要打开appium server,并启动模拟器
//driver= new AndroidDriver(new URL("http://localhost:4723/wd/hub"),devices);
//不需要打开appium桌面版
AppiumDriverLocalService service =startAppiumService();
driver = new AndroidDriver(service.getUrl(), devices);
Screen s = new Screen();
// 设置未找到元素,自动等待时间10秒
s.setAutoWaitTimeout(10);
String project_path=System.getProperty("user.dir");
System.out.println(System.getProperty("user.dir"));
String path = project_path+ "\\src\\main\\java\\com\\welab\\automation\\projects\\demo\\Notifications.png";
s.click("D:\\images\\test\\test01.png");
Thread.sleep(5000);
s.click("D:\\images\\test\\test02.png");
System.out.println("pass");
}
public void clickMobileElementByPicture(String picPath) throws URISyntaxException, IOException {
File file = new File(picPath);
String base64String = Base64.getEncoder().encodeToString(Files.readAllBytes(file.toPath()));
By by= MobileBy.image(base64String);
findMobileElement(by).click();
}
public MobileElement findMobileElement(By by) {
return (MobileElement) driver.findElement(by);
}
private static AppiumDriverLocalService startAppiumService() {
AtomicInteger port = new AtomicInteger();
AppiumDriverLocalService service = null;
service = new AppiumServiceBuilder()
.usingAnyFreePort()
.withIPAddress("0.0.0.0")
.withArgument(SESSION_OVERRIDE)
.withArgument(LOG_LEVEL, "error")
.usingDriverExecutable(new File("D:\\Program Files\\nodejs\\node.exe"))
.withAppiumJS(new File("C:\\Users\\jeff.xie\\AppData\\Roaming\\npm\\node_modules\\appium\\build\\lib\\main.js"))
.build();
Optional.ofNullable(service).ifPresent(s -> {
s.start();
port.set(s.getUrl().getPort());
});
AppiumDriverLocalService appiumDriverLocalService = service;
return service;
}
}
边栏推荐
- Aliyundrive fuse that allows jellyfin to directly mount alicloud disks
- C# Winform 相册功能,图片缩放,拖拽,预览图分页
- 数据库 就业咨询系统求各位帮下忙
- History of hash index design
- VR panoramic shooting breaks the deadlock of traditional propaganda that wild geese pass without leaving traces
- Stephencovey's tips for efficient work for young people
- JS高级程序设计第 4 版:迭代器的学习
- 一文彻底弄懂单例模式(Singleton)
- 如何实现接口异常场景测试?测试方法探索与测试工具实现
- 软件项目验收测试范围和流程,这些你都知道吗?
猜你喜欢

Lisez ceci pour vous apprendre à jouer avec la cible de test de pénétration vulnhub - driftingblues - 5

Chip silicon and streaming technology

Madcap flare 2022, documentation in language or format

"N'osez pas douter du Code, vous devez douter du Code" notez une analyse de délai de demande réseau

Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!

基于SSH框架甜品商城管理系统【源码+数据库】

Chengdu test equipment development_ Array introduction of C language for single chip microcomputer

In 5g era, how to create an amazing live VR activity?

如何实现接口异常场景测试?测试方法探索与测试工具实现

能让Jellyfin直接挂载阿里云盘的aliyundrive-fuse
随机推荐
请问,中衍期货是不是靠谱的?资金安全吗?
Nine good programming habits for 10 years
CVE-2022-22965複現
VR全景拍摄,打破传统宣传雁过不留痕的僵局
VCIP2021:利用解码信息进行超分辨率
"Dare not doubt the code, but have to doubt the code" a network request timeout analysis
作为程序员,职业规划需要注意的四个阶段
Kubernetes monitoring: grafana adds datasource and dashboard through automation
Quickly understand the commonly used symmetric encryption algorithm, and no longer have to worry about the interviewer's thorough inquiry
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
Policy deployment of firewall Foundation
金融应用如何解决金额精度问题(以Quorum、golang为例)
位置编码(PE)是如何在Transformers中发挥作用的
安装和使用protobuf-c
How to protect WordPress websites from cyber attacks? It is important to take safety measures
定金预售的规则思路详解
成都测试设备开发_单片机C语言之数组介绍
一文彻底弄懂单例模式(Singleton)
Analysis on data skew of redis slice cluster
client-go gin的简单整合九-Create