2
votes

I have integrated Sikuli with my Selenium project. For the sake of learning, I have used simple gmail login application to automate it using Sikuli. Well, I am able to execute script. Now let's say, I'm typing something in my Username field. And sometimes, the mouse is not hovered to the username field. So my test scripts failed. And it is intermittent behavior.

public static void main(String[] args) throws Exception {

    Screen screen = new Screen();

    Pattern pattern1 = new Pattern("E:\\Projects\\Java\\Demo\\Images\\UserName.PNG");
    Pattern pattern2 = new Pattern("E:\\Projects\\Java\\Demo\\Images\\Password.PNG");
    Pattern pattern3 = new Pattern("E:\\Projects\\Java\\Demo\\Images\\SignIn.PNG");
    Pattern pattern4 = new Pattern("E:\\Projects\\Java\\Demo\\Images\\Next.PNG");
    Pattern pattern5 = new Pattern("E:\\Projects\\Java\\Demo\\Images\\SignedIn.PNG");
    Pattern pattern6 = new Pattern("E:\\Projects\\Java\\Demo\\Images\\SentMail.PNG");
    Pattern pattern7 = new Pattern("E:\\Projects\\Java\\Demo\\Images\\SentMessage.PNG");

    System.setProperty("webdriver.chrome.driver","E:\\Projects\\Java\\Demo\\Drivers\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
    driver.navigate().to("https://www.gmail.com");
    driver.manage().window().maximize();
    screen.type(pattern1,"email id");
    screen.click(pattern4);
    screen.type(pattern2,"password");
    screen.click(pattern5);
    screen.click(pattern3);
    screen.wait(pattern6,20);
    screen.click(pattern6);
    screen.wait(pattern7,5);
    screen.click(pattern7);
}

Does anyone have an idea why this happens?

2
please post what code you can to help us debug this situation, if you create a jsfiddle.net do you get the same issues?haxxxton
@haxxxton - I have updated my code as wellAishu

2 Answers

0
votes

First of all, share your code.

Usually, intermittent behavior like you describe is caused by timeouts. Meaning that you are looking for an element that is not there yet or has not yet become stable.

A practical example in your scenario can be trying to detect the username field before the page has fully loaded. It will be useful to know how you have used both tools. What you used for navigation and what for elements identification?

Saying that, the quickest way to try and solve this problem is to put few seconds delay before you start searching for username element. See if that helps you.

EDIT Now when you have posted your code, have a look at these two lines:

driver.manage().window().maximize();
screen.type(pattern1,"email id");

Here, you maximize the browser window and immediately try to find and type into the element described by pattern1. This is likely to be a problem since your driver instance does not wait for the window to become maximized and the next command will start executing immediately. You should allow some time to ensure that the window has finished resizing. just add a short sleep between these lines and see if that helps.

0
votes

As it happens intermittently and occurs for the very first action in a newly drawn screen this looks like a timing problem.
The Sikuli solution here is to wait until your input field is available before you use it.

The statement to use is:

wait(pattern1[, seconds])

Insert just before:

screen.type(pattern1,"email id");

Reference:
http://doc.sikuli.org/region.html#Region.wait