当前位置:网站首页>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
边栏推荐
猜你喜欢

JasperReport报表生成工具的基本使用和常见问题

验证码是自动化的天敌?看看大神是怎么解决的
How MySQL enables multiple auto incrementing columns in a table

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

Traffic replication in istio Service Grid

transformers VIT图像模型向量获取

成都测试设备开发_单片机C语言之数组介绍

Stephencovey's tips for efficient work for young people

拜登签署两项旨在加强政府网络安全的新法案

client-go gin的简单整合九-Create
随机推荐
七牛云上传图片
Shan Zhiguang, chairman of BSN Development Alliance: DDC can provide the underlying support for the development of China's meta universe industry
C#泛型方法
天润云上市在即:VC大佬田溯宁大幅减持,预计将套现2.6亿港元
Deadlock found when trying to get lock; Try restarting transaction
ThoughtWorks.QRCode和ZXing.Net 二维码,网址可以直接跳转
How many days are there between the two timestamps of PHP
看完這篇 教你玩轉滲透測試靶機Vulnhub——DriftingBlues-5
JasperReport报表生成工具的基本使用和常见问题
验证码是自动化的天敌?看看大神是怎么解决的
Maui uses Masa blazor component library
Kubernetes monitoring: grafana adds datasource and dashboard through automation
怎样在手机上开户?网上开户安全么?
开源SPL重新定义OLAP Server
基于SSM框架实现的甜品饮品店前后台管理系统甜品商城蛋糕店【源码+数据库】
Mysql学习笔记2022
[introduction to postgraduate entrance examination] analysis of postgraduate entrance examination data of Cyberspace Security Major of Beijing Jiaotong University from 2018 to 2022
S7-200SMART与FANUC机器人进行Profinet通信的具体方法和步骤
想知道股票开户优惠链接,如何得知?网上开户安全么?
技术实践 | 场景导向的音视频通话体验优化