Not able to validate if image is exists on screen or not

Asked by sneha

I have below code.

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.internal.Locatable;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.internal.Coordinates;
import org.sikuli.basics.Debug;
//import org.sikuli.basics.Settings;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Match;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;
import org.sikuli.script.Settings;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import static org.testng.Assert.*;

public class Sikuli_Play_Video {

 private static WebDriver driver;
 Screen screen = new Screen();
  static {
      Debug.setLogFile(System.getProperty("user.dir") + "\\logs\\log.txt");
        }

  @BeforeClass
  public void setUp() throws FindFailed, InterruptedException
  {

    System.setProperty("webdriver.chrome.driver", "C:/Program Files/Google/Chrome/Application/chromedriver.exe");
    driver = new ChromeDriver();

  }

  public boolean ensureExists(Pattern image5) {

   Match m = screen.exists(image5);
   System.out.println("Result of m is " + m);

   if (m != null) {
    return true;
   }
   return false;
  }
  @Test

  public void TestplayVideo() throws FindFailed, InterruptedException
      {

       try
       {
       // Load
     driver.get("sitename");
     driver.manage().window().maximize();
     driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

 //Create and initialize an instance of Screen object

 String path_or = System.getProperty("user.dir") + "\\imgs";
 Settings.DebugLogs = true;
 //Add image path
 Pattern image5 = new Pattern("imgs/play.png");
 image5.similar((float)0.77);

 WebElement element = driver.findElement(By.xpath("//*[@id='article-body']/article/div[1]"));
 Coordinates coordinate = ((Locatable)element).getCoordinates();
 coordinate.inViewPort();
 //Wait 10ms for image
     screen.wait(path_or+"image5",10000);
 System.out.println("Video Still is displayed");

 Debug.user("Pass",image1,screen.getLastMatch());

 screen.wait(image5, 10);
 System.out.println("Play button is displayed");
 Thread.sleep(1000);

 Assert.assertTrue(ensureExists(image5));
 //play video
 screen.click(image5);

 Debug.user("we clicked %s at %s", image5, screen.getLastMatch());

 // Assert.assertTrue(ensureExists("image5.png"));
 //Thread.sleep(5000);
 }
       catch(Exception e)
       {
        assertTrue(false, e.toString());
        }
      }
 @AfterClass
 public static void tearDown()
 {
   driver.close();
          driver.quit();
 }

}

I am not able to pass this test case It does not identify image.

i dont understand what is wrong here and it does not capture any log details as well

log.txt file is created but its shows blank.

Please help

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

--1:
screen.wait(path_or+"image5",10000);

- not a valid image filename: path_or+"image5.png" (why are you not using your already defined Pattern ?
- 10000 means 10000 seconds - I guess you do not mean that

So it might not get beyond that, if you have a standard timeout for your test case.

--2:
To use Debug.user() Settings.DebugLogs = true; is not needed.
Since the first Debug.user() comes after the above wait() the file might well be empty.I would put a Debug.user() at least at the beginning of your test case.

Can you help with this problem?

Provide an answer of your own, or ask sneha for more information if necessary.

To post a message you must log in.