Intermittent failure of Sikuli

戏子无情 提交于 2019-12-11 01:42:04

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/40859753/intermittent-failure-of-sikuli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!