Skip to content

Commit 1d673d6

Browse files
committed
Added percy Test
1 parent 14e8ff5 commit 1d673d6

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ buildscript {
1717
dependencies {
1818
implementation 'org.seleniumhq.selenium:selenium-java:3.141.59'
1919
implementation 'com.browserstack:browserstack-local-java:1.0.6'
20+
implementation 'io.percy:percy-java-selenium:1.0.0'
2021
implementation 'org.testng:testng:7.1.0'
2122
implementation 'io.qameta.allure:allure-testng:2.13.8'
2223
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
@@ -96,6 +97,14 @@ tasks.register('bstack-single', Test) {
9697
}
9798
}
9899

100+
tasks.register('percy', Test) {
101+
useTestNG() {}
102+
include '**/LoginVisualTest.class'
103+
testLogging {
104+
events "PASSED", "FAILED", "SKIPPED"
105+
}
106+
}
107+
99108
tasks.register('bstack-local', Test) {
100109
useTestNG() {
101110
listeners.add("com.browserstack.test.utils.BrowserstackTestStatusListener")

pom.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@
7878
<artifactId>browserstack-local-java</artifactId>
7979
<version>1.0.6</version>
8080
</dependency>
81+
<dependency>
82+
<groupId>io.percy</groupId>
83+
<artifactId>percy-java-selenium</artifactId>
84+
<version>1.0.0</version>
85+
</dependency>
8186
<dependency>
8287
<groupId>com.deque.html.axe-core</groupId>
8388
<artifactId>selenium</artifactId>
@@ -225,6 +230,24 @@
225230
</plugins>
226231
</build>
227232
</profile>
233+
<profile>
234+
<id>percy</id>
235+
<build>
236+
<plugins>
237+
<plugin>
238+
<groupId>org.apache.maven.plugins</groupId>
239+
<artifactId>maven-surefire-plugin</artifactId>
240+
<configuration>
241+
<includes>
242+
<include>
243+
com.browserstack.test.suites.login.LoginVisualTest
244+
</include>
245+
</includes>
246+
</configuration>
247+
</plugin>
248+
</plugins>
249+
</build>
250+
</profile>
228251
<profile>
229252
<id>bstack-local</id>
230253
<build>

src/test/java/com/browserstack/test/suites/TestBase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.browserstack.local.Local;
44
import com.browserstack.test.utils.DriverUtil;
55
import com.browserstack.test.utils.ScreenshotListener;
6+
import io.percy.selenium.Percy;
67
import org.json.simple.JSONObject;
78
import org.json.simple.parser.JSONParser;
89
import org.openqa.selenium.WebDriver;
@@ -34,6 +35,7 @@ public class TestBase {
3435
private Local local;
3536
protected WebDriverWait wait;
3637
private String environment;
38+
public static Percy percy;
3739

3840
public WebDriver getDriver() {
3941
return driver.get();
@@ -83,6 +85,7 @@ public void setUp(@Optional("on-prem") String environment, @Optional("single") S
8385
dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
8486
driver.set(new RemoteWebDriver(new URL(DOCKER_SELENIUM_HUB_URL), dc));
8587
}
88+
percy = new Percy(getDriver());
8689
getDriver().get(url);
8790
getDriver().manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
8891
wait = new WebDriverWait(getDriver(), 30);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.browserstack.test.suites.login;
2+
3+
import com.browserstack.test.suites.TestBase;
4+
import org.openqa.selenium.By;
5+
import org.openqa.selenium.Keys;
6+
import org.testng.Assert;
7+
import org.testng.annotations.Test;
8+
9+
public class LoginVisualTest extends TestBase {
10+
11+
@Test
12+
public void loginLockedUser() {
13+
14+
percy.snapshot("Check Homepage");
15+
getDriver().findElement(By.id("signin")).click();
16+
percy.snapshot("Check Signin page");
17+
getDriver().findElement(By.cssSelector("#username input")).sendKeys("locked_user" + Keys.ENTER);
18+
getDriver().findElement(By.cssSelector("#password input")).sendKeys("testingisfun99" + Keys.ENTER);
19+
getDriver().findElement(By.id("login-btn")).click();
20+
percy.snapshot("Check Login result");
21+
22+
Assert.assertEquals(getDriver().findElement(By.className("api-error")).getText(), "Your account has been locked.");
23+
}
24+
}

0 commit comments

Comments
 (0)