当前位置:网站首页>利用图片实现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;
}
}
边栏推荐
- Redis+Caffeine两级缓存的实现
- How to compare the size of two dates in unity and C #
- Verification code is the natural enemy of automation? See how the great God solved it
- Understand the quality assurance of open source software (OSS)
- 软件项目验收测试范围和流程,这些你都知道吗?
- JasperReport报表生成工具的基本使用和常见问题
- 如何实现接口异常场景测试?测试方法探索与测试工具实现
- Neuron+ekuiper realizes data collection, cleaning and anti control of industrial Internet of things
- Instanceinforeplicator class of Eureka (service registration auxiliary class)
- 芯片硅片与流片技术
猜你喜欢

C# Winform 相册功能,图片缩放,拖拽,预览图分页

5G时代,如何打造一场令人惊叹的VR直播活动?

Oceanbase database helps the ideal automobile intelligent production line to realize automatic recovery within 30 seconds
![[untitled]](/img/ff/f23e5275683d4d7b13fcb94cc77702.png)
[untitled]

BSN发展联盟理事长单志广:DDC可为中国元宇宙产业发展提供底层支撑
![[introduction to postgraduate entrance examination] analysis of postgraduate entrance examination data of Cyberspace Security Major of Beijing Jiaotong University from 2018 to 2022](/img/84/b572b3b80cc0dd1489076116cf0638.png)
[introduction to postgraduate entrance examination] analysis of postgraduate entrance examination data of Cyberspace Security Major of Beijing Jiaotong University from 2018 to 2022

看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-5

一文彻底弄懂工厂模式(Factory)

【无标题】

Kukai TV ADB
随机推荐
C generic method
Quickly understand the commonly used symmetric encryption algorithm, and no longer have to worry about the interviewer's thorough inquiry
Cve - 2022 - 22965 Resume
A simple scientific research secret
《Kubernetes监控篇:Grafana通过自动化方式添加datasource和dashboard》
作为过来人,写给初入职场的程序员的一些忠告
BSN发展联盟理事长单志广:DDC可为中国元宇宙产业发展提供底层支撑
Instanceinforeplicator class of Eureka (service registration auxiliary class)
基于SSH框架甜品商城管理系统【源码+数据库】
JS高级程序设计第 4 版:迭代器的学习
Redis+Caffeine两级缓存的实现
Chengdu test equipment development_ Array introduction of C language for single chip microcomputer
请问,中衍期货是不是靠谱的?资金安全吗?
JasperReport报表生成工具的基本使用和常见问题
Maui uses Masa blazor component library
Flink status management
Technology practice | scene oriented audio and video call experience Optimization
如何保护WordPress网站免受网络攻击?采取安全措施至关重要
Z-Score和deltf/f有什么区别?
什么是Bout?