Skip to content
Merged
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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
<artifactId>browserstack-local-java</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>com.deque.html.axe-core</groupId>
<artifactId>selenium</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class ConfirmationPage extends BasePage {
@FindBy(css = ".continueButtonContainer button")
private WebElement continueShoppingButton;

@FindBy(id = "downloadpdf")
private WebElement downloadpdf;

private By confirmationMessage = By.id("confirmation-message");

public ConfirmationPage(WebDriver driver) {
Expand All @@ -25,4 +28,8 @@ public HomePage continueShopping() {
continueShoppingButton.click();
return new HomePage(driver);
}

public void downloadPDF() {
downloadpdf.click();
}
}
6 changes: 6 additions & 0 deletions src/test/java/com/browserstack/test/suites/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@ public class TestBase {
private static final long TIMESTAMP = new Date().getTime();
private Local local;
protected WebDriverWait wait;
private String environment;

public WebDriver getDriver() {
return driver.get();
}

public boolean isRemoteExecution() {
return environment.equalsIgnoreCase("remote");
}

@BeforeMethod
@Parameters(value = {"environment", "testType", "env_cap_id"})
public void setUp(@Optional("on-prem") String environment, @Optional("single") String testType, @Optional("0") int env_cap_id, Method m) throws Exception {
this.environment = environment;
JSONParser parser = new JSONParser();
JSONObject testCapsConfig = (JSONObject) parser.parse(new FileReader(PATH_TO_TEST_CAPS_JSON));
String url = (String) testCapsConfig.get("application_endpoint");
Expand Down
19 changes: 15 additions & 4 deletions src/test/java/com/browserstack/test/suites/e2e/OrderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import com.browserstack.app.pages.HomePage;
import com.browserstack.app.pages.OrdersPage;
import com.browserstack.test.suites.TestBase;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.JavascriptExecutor;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;

public class OrderTest extends TestBase {

@Test
public void placeOrder() {
SoftAssert softly = new SoftAssert();
ConfirmationPage page = new HomePage(getDriver())
.navigateToSignIn()
.loginWith("fav_user", "testingisfun99")
Expand All @@ -24,9 +25,19 @@ public void placeOrder() {
.enterShippingDetails("firstname", "lastname", "address", "state", "12345");
Assert.assertTrue(page.isConfirmationDisplayed());

if (isRemoteExecution()) {
page.downloadPDF();
softly.assertTrue(downloadedFileExists("confirmation.pdf"));
}

OrdersPage ordersPage = page.continueShopping().navigateToOrders();
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".spinner")));

Assert.assertEquals(ordersPage.getItemsFromOrder(), 3);
softly.assertEquals(ordersPage.getItemsFromOrder(), 3);
softly.assertAll();
}

private boolean downloadedFileExists(String fileName) {
JavascriptExecutor jse = (JavascriptExecutor) getDriver();
return Boolean.parseBoolean(jse.executeScript("browserstack_executor: {\"action\": \"fileExists\", \"arguments\": {\"fileName\": \"" + fileName + "\"}}").toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.browserstack.test.suites.login;

import com.browserstack.test.suites.TestBase;
import com.deque.html.axecore.results.Results;
import com.deque.html.axecore.results.Rule;
import com.deque.html.axecore.selenium.AxeBuilder;
import org.assertj.core.api.Assertions;
import org.testng.annotations.Test;

import java.util.List;

public class AccessibilityTest extends TestBase {

@Test
public void testForAccessibility() {
AxeBuilder builder = new AxeBuilder();
Results results = builder.analyze(getDriver());
List<Rule> violations = results.getViolations();

Assertions.assertThat(violations).isEmpty();
}
}
12 changes: 12 additions & 0 deletions src/test/resources/axe/axe.min.js

Large diffs are not rendered by default.