前言
Sikuli-IDE用起来方便,但是用到实际项目中还是有局限性的,Sikuli提供了Sikuli-Script的jar包,在Sikuli-X的安装目录下,这样就可以在Idea中使用JAVA编写代码了,并用Sikuli-Script和selenium完美结合使用。
模拟场景
- 打开百度地图
- 切换城市到北京
- 使用测距工具
- 测量 奥林匹克森林公园 —— 北京南苑机场 的距离
安装配置
- 首先下载sikuliX的jar包:https://launchpad.net/sikuli/sikulix/1.1.0
- 导入jar包:sikulixsetup-1.1.0.jar
- 双击java -jar sikulixsetup-1.1.0.jar,则会出现如下图,选择相应选项后,启动会下载sikulixapi.jar。不然会报错:libs to export not found on above classpath: /sikulixlibs/mac/libs64
- 启动成功后会出现如下提示
sikuli操作Flash网页
具体示例代码如下;
import org.openqa.selenium.By; org.openqa.selenium.WebDriver; org.openqa.selenium.chrome.ChromeDriver; java.util.concurrent.TimeUnit; org.sikuli.script.FindFailed; org.sikuli.script.Pattern; org.sikuli.script.Screen; org.testng.annotations.BeforeClass; org.testng.annotations.Test; /** * @rongrong
* Selenium结合sikuliX操作Flash网页案例 */ public class TestSikuli { WebDriver driver; @BeforeClass void beforeClass() { System.setProperty("webdriver.chrome.driver","driver/chromedriver.exe"); driver = new ChromeDriver(); } @Test testBaiDuMap() { driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(10); //打开城市下拉框 driver.findElement(By.cssSelector(".ui3-city-change-inner")).click(); 选择北京 driver.findElement(By.cssSelector("[citycode='131']")).click();; 打开工具下拉框 driver.findElement(By.cssSelector("[map-on-click='Box'] em" 选择测距 driver.findElement(By.cssSelector("[map-on-click='measure'] i")).click(); Screen screen = Screen(); String start = "D:\\picture\\奥林匹克森林公园.png"; String end = "D:\\picture\\北京南苑机场.png"; Pattern from = Pattern(start); Pattern to = Pattern(end); try { if (screen.find(from) != null) { screen.click(from); } if (screen.find(to) != ) { screen.click(to); } screen.doubleClick(); } catch (FindFailed e) { e.printStackTrace(); } } }
运行效果如下: