java.lang.IllegalStateException: Eyes not open

2k Views Asked by At

I'm using Selenium WebDriver 3.0 and AppliToolsEyes 2.54 for selenium-java

<dependency>
            <groupId>com.applitools</groupId>
            <artifactId>eyes-selenium-java</artifactId>
            <version>2.54</version>
</dependency>

For visual testing wrote following code -

private WebDriver driver;
private Eyes eyes;
private static final String url = "http://www.google.com";

@BeforeClass
public void setUp(){
    eyes = new Eyes();
    System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "//src//test//resources//geckodriver.exe");
    driver = new FirefoxDriver();
    driver.manage().window().maximize();
}

@AfterClass
public void tearDown(){
    eyes.abortIfNotClosed();
    driver.quit();
}

@Test
public void visualTest(){ 
    eyes.checkWindow();
    driver.get(url);
    eyes.checkWindow();
    eyes.close();
}

but getting following error when ran the code for eyes.checkWindow()

java.lang.IllegalStateException: Eyes not open at com.applitools.utils.ArgumentGuard.isValidState(ArgumentGuard.java:117) at com.applitools.eyes.EyesBase.checkWindowBase(EyesBase.java:977) at com.applitools.eyes.Eyes.checkWindow(Eyes.java:359) at com.applitools.eyes.Eyes.checkWindow(Eyes.java:335) at com.applitools.eyes.Eyes.checkWindow(Eyes.java:325)

2

There are 2 best solutions below

0
On

You need to use the eyes.open() method. You then pass your webdriver, etc. in the open method, along with other parameters to initialize eyes.

From their SDK: driver = eyes.open(driver, appName, testName, viewportSize); is the proper way to initialize Eyes.

See their SDK for further help: https://applitools.atlassian.net/wiki/display/Java/SDK+Guide

0
On

In order to solve this you need to open eyes before checking a window.

One way of doing this is to add the following line at the begining of your test as follows:

@Test
public void visualTest(){ 
    driver = eyes.open(driver, appName, testName, new RectangleSize(width, height));
    eyes.checkWindow();
    driver.get(url);
    eyes.checkWindow();
    eyes.close();
}

Alternatively add a JUnit rule, which will open eyes separately for each test:

@Rule
    public TestWatcher watcher = new TestWatcher() {
        protected void starting(Description description) {
            eyes.open(driver, appName, description.getMethodName(), new RectangleSize(width, height) );
        }
    };

On a different matter, I saw that in your test you are calling: driver.manage().window().maximize(); This way for setting the browser size may cause unstable visual tests - you should specify a viewport size when opening eyes.

For more information please check this article regarding setting the viewport size in Applitools tests, or contact [email protected]