当前位置:网站首页>Using pictures to locate app elements sikulix
Using pictures to locate app elements sikulix
2022-06-22 14:38:00 【qq_ four hundred and ninety-two million four hundred and forty-】
brief introduction :Sikuli It's a novel graphic scripting language , Or an alternative automated testing technology . It is similar to our commonly used automated testing technology ( Tools ) There's a big difference .
sikulix jar Package download address
SikuliX project files : SikuliX
You can also search this in the Alibaba cloud warehouse jar package

You need to download the following 3 A package ,
sikulixapi-2.0.5.jar sikulixapi-2.0.5-win.jar be used for windows
sikulixapi-2.0.5.jar sikulixapi-2.0.5-mac.jar be used for mac The computer

It can also be in pom Add... To the file , However, this method is not recommended , This package will have many dependent packages , The download may fail
You can also refer to :java+win7+eclipse+Maven+sikuli Configuration summary --- Graphic scripting language - Let's have a look
<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);
// Need to open appium server, And start the simulator
//driver= new AndroidDriver(new URL("http://localhost:4723/wd/hub"),devices);
// Don't need to open appium The desktop version
AppiumDriverLocalService service =startAppiumService();
driver = new AndroidDriver(service.getUrl(), devices);
Screen s = new Screen();
// Set element not found , Automatic wait time 10 second
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;
}
}
appium combination sikuli The simple practice of _Xiamen_wiley The blog of -CSDN Blog
边栏推荐
- 11 方法引用和构造器应用
- How to solve the problem of amount accuracy in financial applications (take quorum and golang as examples)
- D security can call the system
- 机器学习之随机森林
- 一文彻底弄懂单例模式(Singleton)
- 加密市场进入寒冬,是“天灾”还是“人祸”?
- Cve-2022-22965 reappearance
- Transformers vit image model vector acquisition
- Unity 子线程调用主线程的UI
- Basic usage and FAQs of jasperreport report report generation tool
猜你喜欢

轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷

How to add a mask to a VR panoramic work? What is the function?

JS高级程序设计第 4 版:迭代器的学习

C语言学生管理系统(开源)

Understand the quality assurance of open source software (OSS)

Neuron+ekuiper realizes data collection, cleaning and anti control of industrial Internet of things

【考研攻略】北京交通大学网络空间安全专业2018-2022年考研数据分析

扩散模型又杀疯了!这一次被攻占的领域是...

Policy deployment of firewall Foundation

作为程序员,职业规划需要注意的四个阶段
随机推荐
Specific methods and steps of PROFINET communication between s7-200smart and Fanuc robot
Flink status management
Traffic replication in istio Service Grid
unity和C#中怎么去比较2个日期大小
Unity's rich text color sets the color to be fully transparent
Kukai TV ADB
C generic_ Generic class
transformers VIT图像模型向量获取
Unity 子线程调用主线程的UI
Summary of patent blog writing
Vcip2021: super resolution using decoded information
5G时代,如何打造一场令人惊叹的VR直播活动?
Messiari annual report-2021
In 5g era, how to create an amazing live VR activity?
Dessert mall management system based on SSH framework [source code + database]
拜登签署两项旨在加强政府网络安全的新法案
Aliyundrive fuse that allows jellyfin to directly mount alicloud disks
How to use SQL to modify in the database & delete
Support vector machine for machine learning
【无标题】