Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

#174 Support for Applitools Eyes added #251

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions bb-eyes/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#%L
Bobcat
%%
Copyright (C) 2018 Cognifide Ltd.
%%
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#L%
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>bobcat</artifactId>
<groupId>com.cognifide.qa.bb</groupId>
<version>1.5.1-SNAPSHOT</version>
</parent>

<artifactId>bb-eyes</artifactId>
<name>Bobcat Eyes</name>

<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>com.applitools</groupId>
<artifactId>eyes-selenium-java3</artifactId>
<version>RELEASE</version>
<exclusions>
<exclusion>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--BB dependencies-->
<dependency>
<groupId>com.cognifide.qa.bb</groupId>
<artifactId>bb-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.cognifide.qa.bb</groupId>
<artifactId>bb-junit5</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 Cognifide Ltd.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.eyes.guice;

import com.applitools.eyes.selenium.Eyes;
import com.google.inject.AbstractModule;

/**
* Eyes Guice module. Provides an {@link Eyes} instance.
*/
public class EyesModule extends AbstractModule {

@Override
protected void configure() {
bind(Eyes.class).toProvider(EyesProvider.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 Cognifide Ltd.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.eyes.guice;

import com.applitools.eyes.selenium.Eyes;
import com.cognifide.qa.bb.guice.ThreadScoped;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.name.Named;

/**
* Provides a thread-scoped {@link Eyes} instance. Bound in {@link EyesModule}.
* <br>
* Requires {@code eyes.apiKey} property.
* <br>
* Additional configurable options:
* <ul>
* <li>{@code eyes.fullPageScreenshots} - defines if full-page screenshots should be captured</li>
* </ul>
*/
@ThreadScoped
public class EyesProvider implements Provider<Eyes> {

private Eyes cachedEyes;

@Inject
@Named("eyes.apiKey")
private String apiKey;

@Inject
@Named("eyes.fullPageScreenshots")
private boolean fullPageScreenshots;

@Override
public Eyes get() {
if (cachedEyes == null) {
cachedEyes = create();
}
return cachedEyes;
}

private Eyes create() {
Eyes eyes = new Eyes();
eyes.setApiKey(apiKey);
eyes.setForceFullPageScreenshot(fullPageScreenshots);
return eyes;
}
}
102 changes: 102 additions & 0 deletions bb-eyes/src/main/java/com/cognifide/qa/bb/eyes/junit4/WithEyes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 Cognifide Ltd.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.eyes.junit4;

import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;

import com.applitools.eyes.selenium.Eyes;
import com.google.inject.Inject;
import com.google.inject.name.Named;

/**
* JUnit 4 {@link TestRule} that enables Eyes integration.
* <p>
* Example usage:
* <pre>
* public class ExampleTest {
* &#64;Rule
* &#64;Inject
* public WithEyes withEyes;
*
* public void test() {
* // test actions
* withEyes.getEyes().checkWindow("Example checkpoint");
* }
* }
* </pre>
*/
public class WithEyes implements TestRule {

private final WebDriver webDriver;
private final Eyes eyes;
private String appName;

@Inject
public WithEyes(WebDriver webDriver, Eyes eyes, @Named("eyes.appName") String appName) {
this.webDriver = webDriver;
this.eyes = eyes;
this.appName = appName;
}

/**
* @return the avaialable WebDriver instance
*/
public WebDriver getWebDriver() {
return webDriver;
}

/**
* @return the configured and initialized {@link Eyes} instance.
*/
public Eyes getEyes() {
return eyes;
}

/**
* {@inheritDoc}
*/
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
WebDriver wrappedDriver = ((EventFiringWebDriver) webDriver).getWrappedDriver();
eyes.open(wrappedDriver, appName, description.getMethodName());
base.evaluate();
} finally {
closeEyes();
}
}
};
}

private void closeEyes() {
try {
eyes.close();
} finally {
eyes.abortIfNotClosed();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 Cognifide Ltd.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.eyes.junit5;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.extension.ExtendWith;

/**
* Meta-annotation enabling the {@link WithEyesExtension}.
*/
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(WithEyesExtension.class)
public @interface WithEyes {
}
Loading