sikuli实例
代码:
package selenium.sikuli; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.sikuli.script.FindFailed; import org.sikuli.script.Screen; import org.sikuli.script.Settings; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; public class Practice { WebDriver driver; // @BeforeMethod // public void begin(){ // System.out.println("执行测试之前"); // } @Test public void Login() throws FindFailed, InterruptedException{ System.setProperty("webdriver.firefox.bin", "D:\\ruanjian\\Firefox\\azml\\firefox.exe"); //打开火狐浏览器 driver= new FirefoxDriver(); // System.setProperty("webdriver.firefox.bin", "D:\\ruanjian\\Firefox\\azml\\firefox.exe"); // WebDriver driver; // //实例化火狐,即打开火狐浏览器 // driver= new FirefoxDriver(); //String url = "http://localhost:8080/portal/main/domain/index.htm"; String url = "https://www.yuncourt.com/portal/main/domain/index.htm"; //打开网页 driver.get(url); //打开窗口 driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); System.out.println("执行到这里啦"); Screen screen = new Screen(); //screen.wait("src/img/firefox.png",20); //绝对路径 //String imgpath = "D:\\study\\eclipse\\workspace\\test-sikuli-java\\src\\image\\"; //相对路径 String imgpath = ".\\src\\image\\"; screen.click(imgpath+"login.png"); Thread.sleep(2000); //输入用户名 screen.type(imgpath+"loginName.png","18698580755"); //输入密码 screen.type(imgpath+"loginPassword.png","a111111"); //点击登录 screen.click(imgpath+"login_click.png"); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); String str = driver.findElement(By.xpath("/html/body/div[3]/div/div/div/a[1]")).getText(); System.out.println(str); driver.findElement(By.xpath("/html/body/div[3]/div/div/div/a[1]")).click(); // String imgpath1 = ".\\src\\image.information\\"; // screen.click(imgpath1+"accuser.png"); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } }
例子2:打开谷歌》打开百度一下链接》输入sikuli》进行百度(运行成功)
public class TestSikuli { @Test public static void openPage() throws FindFailed, InterruptedException { Screen s = new Screen(); //定义图片存放路径 //方法一 绝对路径 String imgpath = "D:\\study\\eclipse\\workspace\\test-sikuli-java\\src\\image\\"; //方法二 相对路径 //String imgpath = ".\\src\\image\\"; //双击桌面chrome浏览器图标 s.doubleClick(imgpath+"chrome.png"); s.click(imgpath+"baidu.png"); Thread.sleep(2000); //在输入框输入搜索关键字:sikuli,并点击搜索按钮 //s.type(imgpath+"search_input.png", "sikuli"); s.find(imgpath+"search_input.png"); s.paste(imgpath+"search_input.png", "sikuli"); s.click(imgpath+"search_button.png"); System.out.println("end"); } }