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");        
        }
}

 

转载于:https://www.cnblogs.com/dieyaxianju/p/5415754.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值