Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SikulixJava中查找图像_Java_Selenium Webdriver_Webdriver_Appium_Sikuli - Fatal编程技术网

在SikulixJava中查找图像

在SikulixJava中查找图像,java,selenium-webdriver,webdriver,appium,sikuli,Java,Selenium Webdriver,Webdriver,Appium,Sikuli,我在试图在屏幕上找到图像时遇到了问题,我尝试了两种不同的方法,但似乎对我不起作用。 我尝试在IOS模拟器上运行Appium,它会显示在屏幕上,所以我不认为这是拍摄屏幕截图的问题 我在运行MacOSX El Capitan 我已经在我的项目中导入了SikulixJavaAPI 我是否还需要导入MAC Sikuli库jar 这就是我迄今为止所尝试的: 一, 二, 我总是找不到错误 错误消息: FindFailed:在S(0)[0,0 1440x900]中找不到/Users/ealiaj/Deskto

我在试图在屏幕上找到图像时遇到了问题,我尝试了两种不同的方法,但似乎对我不起作用。 我尝试在IOS模拟器上运行Appium,它会显示在屏幕上,所以我不认为这是拍摄屏幕截图的问题

我在运行MacOSX El Capitan 我已经在我的项目中导入了SikulixJavaAPI

我是否还需要导入MAC Sikuli库jar

这就是我迄今为止所尝试的:

一,

二,

我总是找不到错误

错误消息:

FindFailed:在S(0)[0,0 1440x900]中找不到/Users/ealiaj/Desktop/Automation/workspace/WheelsUp-IOS/screenshot1.jpg 第2189行,在Region.java文件中

这是屏幕上的图像,大的红色矩形是我创建了一个屏幕截图并试图找到的图像,但是出现了错误


我能成功找到的唯一东西是灰色矩形,或者至少它不会引发错误。

错误消息说程序正在查找.PNG文件,并且在代码中放置了.JPG文件。

您可以使用此方法验证图像:

@Test
public void verifyImages() {    

    //WebElement img = driver.findElementByClassName("android.widget.ImageView");

   //take screen shot
    File screen = ((TakesScreenshot) driver)
                        .getScreenshotAs(OutputType.FILE);


    //capture image of searched contact icon
    List<WebElement > imageList = driver.findElementsByXPath("//*[@class='android.widget.ImageView' and @index='0']");
    System.out.println(imageList.size());

    System.out.println(i);
    WebElement image = imageList.get(1);
    Point point = image.getLocation();

    //get element dimension
    int width = image.getSize().getWidth();
    int height = image.getSize().getHeight();

    BufferedImage img = ImageIO.read(screen);
    BufferedImage dest = img.getSubimage(point.getX(), point.getY(), width,
                                                                 height);
    ImageIO.write(dest, "png", screen);
    File file = new File("Menu.png");
    FileUtils.copyFile(screen, file);

    //verify images
    verifyImage("Menu.png", "Menu.png" );
}



public void verifyImage(String image1, String image2) throws IOException{
    File fileInput = new File(image1);
    File fileOutPut = new File(image2);

    BufferedImage bufileInput = ImageIO.read(fileInput);
    DataBuffer dafileInput = bufileInput.getData().getDataBuffer();
    int sizefileInput = dafileInput.getSize();                     
    BufferedImage bufileOutPut = ImageIO.read(fileOutPut);
    DataBuffer dafileOutPut = bufileOutPut.getData().getDataBuffer();
    int sizefileOutPut = dafileOutPut.getSize();
    Boolean matchFlag = true;
    if(sizefileInput == sizefileOutPut) {                         
       for(int j=0; j<sizefileInput; j++) {
             if(dafileInput.getElem(j) != dafileOutPut.getElem(j)) {
                   matchFlag = false;
                   break;
             }
        }
    }
    else                            
       matchFlag = false;
    Assert.assertTrue(matchFlag, "Images are not same");    
 }
@测试
public void verifyImages(){
//WebElement img=driver.findElementByClassName(“android.widget.ImageView”);
//截屏
文件屏幕=((TakesScreenshot)驱动程序)
.getScreenshotAs(OutputType.FILE);
//捕获搜索到的联系人图标的图像
List imageList=driver.findElementsByXPath(“//*[@class='android.widget.ImageView'和@index='0']);
System.out.println(imageList.size());
系统输出打印LN(i);
WebElement image=imageList.get(1);
Point=image.getLocation();
//获取元素维度
int width=image.getSize().getWidth();
int height=image.getSize().getHeight();
BuffereImage img=图像IO.read(屏幕);
BuffereImage dest=img.getSubimage(point.getX(),point.getY(),width,
高度);
ImageIO.write(目标,“png”,屏幕);
File File=新文件(“Menu.png”);
FileUtils.copyFile(屏幕,文件);
//验证图像
verifyImage(“Menu.png”、“Menu.png”);
}
public void verifyImage(字符串image1、字符串image2)引发IOException{
文件输入=新文件(图像1);
文件输出=新文件(图像2);
BuffereImage bufileInput=ImageIO.read(fileInput);
DataBuffer dafileInput=bufileInput.getData().getDataBuffer();
int-sizefileInput=dafileInput.getSize();
BuffereImage bufileOutPut=ImageIO.read(文件输出);
DataBuffer dafileOutPut=bufileOutPut.getData().getDataBuffer();
int-sizefileOutPut=dafileOutPut.getSize();
布尔匹配标志=真;
如果(sizefileInput==sizefileOutPut){

对于(int j=0;jj)您可以在不使用Sikuli.Create函数的情况下执行此操作,该函数在appium中捕获特定元素的屏幕截图(您要验证的内容)在运行时将其保存在您的系统中。并使用Java代码与您的基本映像文件匹配。您能提供示例代码吗?谢谢您发布您看到的确切错误?以原始版本更新post@SadikAli我也对你在评论中的表现方式感兴趣。你能添加一个示例或任何(文档)的链接吗来源?很抱歉,这是我将文件类型更改为.PNG时复制的。它是.PNG,两者都是。这验证了两个图像是否完全相同吗?我正在尝试在屏幕中查找一个图像。例如,在整个图像中查找一个按钮。谢谢,它确实找到了完全相同的两个图像。我用它测试了我这边的两个图像,我工作正常。谢谢。嗨,高拉夫,说清楚了,我有整个屏幕的image1和一个按钮的image2,这将在image1中找到image2?是的,就像我的代码中一样传递定位器。我正在尝试匹配整个屏幕中的联系人图标。测试它,如果您遇到问题,我将帮助您。谢谢
Screen s = new Screen();
try {
    s.find("screenshot.jpg");
} catch (FindFailed e) {

}
@Test
public void verifyImages() {    

    //WebElement img = driver.findElementByClassName("android.widget.ImageView");

   //take screen shot
    File screen = ((TakesScreenshot) driver)
                        .getScreenshotAs(OutputType.FILE);


    //capture image of searched contact icon
    List<WebElement > imageList = driver.findElementsByXPath("//*[@class='android.widget.ImageView' and @index='0']");
    System.out.println(imageList.size());

    System.out.println(i);
    WebElement image = imageList.get(1);
    Point point = image.getLocation();

    //get element dimension
    int width = image.getSize().getWidth();
    int height = image.getSize().getHeight();

    BufferedImage img = ImageIO.read(screen);
    BufferedImage dest = img.getSubimage(point.getX(), point.getY(), width,
                                                                 height);
    ImageIO.write(dest, "png", screen);
    File file = new File("Menu.png");
    FileUtils.copyFile(screen, file);

    //verify images
    verifyImage("Menu.png", "Menu.png" );
}



public void verifyImage(String image1, String image2) throws IOException{
    File fileInput = new File(image1);
    File fileOutPut = new File(image2);

    BufferedImage bufileInput = ImageIO.read(fileInput);
    DataBuffer dafileInput = bufileInput.getData().getDataBuffer();
    int sizefileInput = dafileInput.getSize();                     
    BufferedImage bufileOutPut = ImageIO.read(fileOutPut);
    DataBuffer dafileOutPut = bufileOutPut.getData().getDataBuffer();
    int sizefileOutPut = dafileOutPut.getSize();
    Boolean matchFlag = true;
    if(sizefileInput == sizefileOutPut) {                         
       for(int j=0; j<sizefileInput; j++) {
             if(dafileInput.getElem(j) != dafileOutPut.getElem(j)) {
                   matchFlag = false;
                   break;
             }
        }
    }
    else                            
       matchFlag = false;
    Assert.assertTrue(matchFlag, "Images are not same");    
 }