Completing the following steps will instantiate Eyes and pass your API key to Applitools.
Eyes eyes = new Eyes();
eyes.setApiKey(System.getProperty("applitools.api.key"));
Note:
REMEMBER: We have the API Key stored in our property file, so we are going to read it from there
An example of the entire class:
package base;
import com.applitools.eyes.selenium.Eyes;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
public class BaseTests {
protected static WebDriver driver;
protected static Eyes eyes;
@BeforeClass
public static void setUp() {
Properties props = System.getProperties();
try {
props.load(new FileInputStream(new File("resources/test.properties")));
} catch(Exception e) {
e.printStackTrace();
System.exit(-1);
}
driver = new ChromeDriver();
initiateEyes();
driver.get(System.getProperty("site.url"));
}
@AfterClass
public static void tearDown() {
driver.quit();
eyes.abortIfNotClosed();
}
private static void initiateEyes(){
eyes = new Eyes();
eyes.setApiKey(System.getProperty("applitools.api.key"));
}
}