Search in sources :

Example 6 with FindFailed

use of org.sikuli.script.FindFailed in project selenium_java by sergueik.

the class AppTest method testCalendar.

@Ignore
@Test
public void testCalendar() {
    driver.navigate().to(getPageContent("calendar.html"));
    WebElement calendarElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector("input[name='calendar']"))));
    int xOffset = calendarElement.getSize().getWidth() - 2;
    int yOffset = calendarElement.getSize().getHeight() - 2;
    System.err.println(String.format("Hover at (%d, %d)", xOffset, yOffset));
    actions.moveToElement(calendarElement, xOffset, yOffset).build().perform();
    // Sometimes hover is not enough here for some reason
    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
    }
    actions.moveToElement(calendarElement, xOffset, yOffset).click().build().perform();
    String calendarDropDownImage = fullPath("calendar_dropdown_1920x1080.png");
    try {
        screen.exists(calendarDropDownImage, sikuliTimeout);
        screen.click(calendarDropDownImage, 0);
    } catch (FindFailed e) {
        verificationErrors.append(e.toString());
    }
    // Month Navigation
    String monthNavigateImage = fullPath("month_navigate_1920x1080.png");
    match = screen.exists(monthNavigateImage, sikuliTimeout);
    // Sikuli highlight method would force the Chrome native calendar to close
    // only useful for debugging during script development
    // match.highlight((float) 3.0);
    match.offset(-32, 0).click();
    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
    }
    match = screen.exists(monthNavigateImage, sikuliTimeout);
    match.offset(32, 0).click();
    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
    }
    // Year Navigation
    String yearDropdownImage = "year_dropdown_1920x1080.png";
    match = screen.exists(fullPath(yearDropdownImage), sikuliTimeout);
    match.offset(-40, 0).click();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    ArrayList<String> yearImages = new ArrayList<>(Arrays.asList(new String[] { "jan_1920x1080.png", "jan_highlight_1920x1080.png" }));
    Boolean done = false;
    for (String image : yearImages) {
        if (!done) {
            match = screen.exists(fullPath(image), sikuliTimeout);
            if (match != null) {
                String text = match.text();
                System.err.format("Sikuli read: '%s'\n", text);
                // if --- no text --- is printed
                // make sure tessdata is copied to
                // ${env:APPDATA}\Sikulix\SikulixTesseract\tessdata
                match.click();
                done = true;
            }
        }
    }
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
}
Also used : FindFailed(org.sikuli.script.FindFailed) ArrayList(java.util.ArrayList) WebElement(org.openqa.selenium.WebElement) Boolean(java.lang.Boolean) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with FindFailed

use of org.sikuli.script.FindFailed in project selenium_java by sergueik.

the class ChromeExtensionSikuliTest method openExtensionPopupTest.

@Test(priority = 1, enabled = false)
public void openExtensionPopupTest() {
    Screen screen = new Screen();
    String imagePath = getResourcePath("chropath.png");
    try {
        screen.find(imagePath);
        screen.click(imagePath);
    } catch (FindFailed e) {
        e.printStackTrace();
    }
    WebDriverWait wait = new WebDriverWait(driver, 5);
    wait.until(ExpectedConditions.numberOfWindowsToBe(2));
    String parentWindow = driver.getWindowHandle();
    Set<String> allWindows = driver.getWindowHandles();
    for (String curWindow : allWindows) {
        if (!parentWindow.equals(curWindow)) {
            driver.switchTo().window(curWindow);
        }
    }
}
Also used : FindFailed(org.sikuli.script.FindFailed) Screen(org.sikuli.script.Screen) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Test(org.testng.annotations.Test)

Example 8 with FindFailed

use of org.sikuli.script.FindFailed in project sakuli by ConSol.

the class RegionImpl method clickMe.

/**
 * {@link org.sakuli.actions.screenbased.Region#click()}
 */
public RegionImpl clickMe() {
    int ret;
    try {
        Location center = this.getCenter();
        ret = this.click(center);
    } catch (FindFailed findFailed) {
        ret = 0;
    }
    loader.loadSettingDefaults();
    if (ret != 1) {
        loader.getExceptionHandler().handleException("Couldn't click on region " + this, this, resumeOnException);
        return null;
    }
    return this;
}
Also used : FindFailed(org.sikuli.script.FindFailed) Location(org.sikuli.script.Location)

Example 9 with FindFailed

use of org.sikuli.script.FindFailed in project sakuli by ConSol.

the class RegionImpl method mouseMoveMe.

/**
 * wrapper implementation for {@link #mouseMove(Object)} ()}
 */
public RegionImpl mouseMoveMe() {
    int ret;
    try {
        Location center = this.getCenter();
        ret = this.mouseMove(center);
    } catch (FindFailed findFailed) {
        ret = 0;
    }
    loader.loadSettingDefaults();
    if (ret != 1) {
        loader.getExceptionHandler().handleException("Could not move the mouse on region " + this, this, resumeOnException);
        return null;
    }
    return this;
}
Also used : FindFailed(org.sikuli.script.FindFailed) Location(org.sikuli.script.Location)

Example 10 with FindFailed

use of org.sikuli.script.FindFailed in project sakuli by ConSol.

the class RegionImpl method find.

/**
 * {@link Region#find(String)}.
 */
public RegionImpl find(String imageName) {
    Match match;
    Pattern imagePattern = loadPattern(imageName);
    try {
        match = this.find(imagePattern);
    } catch (FindFailed findFailed) {
        match = null;
    }
    if (match != null) {
        return toRegion(match);
    }
    loader.getExceptionHandler().handleException("Can't find \"" + imagePattern + "\" in " + this.toString(), this, resumeOnException);
    return null;
}
Also used : Pattern(org.sikuli.script.Pattern) FindFailed(org.sikuli.script.FindFailed) Match(org.sikuli.script.Match)

Aggregations

FindFailed (org.sikuli.script.FindFailed)11 Location (org.sikuli.script.Location)4 Ignore (org.junit.Ignore)3 Test (org.junit.Test)3 WebElement (org.openqa.selenium.WebElement)3 Match (org.sikuli.script.Match)3 Pattern (org.sikuli.script.Pattern)2 File (java.io.File)1 IOException (java.io.IOException)1 Boolean (java.lang.Boolean)1 RuntimeException (java.lang.RuntimeException)1 ArrayList (java.util.ArrayList)1 Dimension (org.openqa.selenium.Dimension)1 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)1 ImageLibObject (org.sakuli.datamodel.actions.ImageLibObject)1 Screen (org.sikuli.script.Screen)1 Test (org.testng.annotations.Test)1