Skip to content

Commit

Permalink
TestNG template project with allure report (#24)
Browse files Browse the repository at this point in the history
* TestNG template project with allure report

* Remove unused method and rename AlertSteps

* add missed env vars to ios job

* Rework test name listener to correct name in allure report

* Terminate app before quitting the driver

* Update package and terminate app callings

* Update pipeline to run on macos-12

* Fix workflow triggers - on PR - path

* Stabilize test on Android

* Exclude old guice from cucumber project. Increase retries count

* Increase timeouts
  • Loading branch information
mialeska authored May 14, 2024
1 parent 7592f2f commit 876420d
Show file tree
Hide file tree
Showing 31 changed files with 458 additions and 88 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/test-with-allure-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
paths:
- 'aquality-appium-mobile-template/**'
- 'aquality-appium-mobile-template-cucumber/**'
- 'aquality-appium-mobile-template-testng/**'
- 'scripts/**'
push:
branches: [ master ]
Expand All @@ -23,6 +24,8 @@ on:
jobs:
build-and-test-android:
env:
CUCUMBER_ALLURE_RESULTS: aquality-appium-mobile-template-cucumber/target/allure-results
TESTNG_ALLURE_RESULTS: aquality-appium-mobile-template-testng/target/allure-results
SUBPROJECT_NAME: aquality-appium-mobile-template-cucumber
ENVIRONMENT: ${{ github.event.inputs.environment == '' && 'stage' || github.event.inputs.environment }}
ANDROID_PROFILE: Nexus 6
Expand All @@ -32,7 +35,7 @@ jobs:

concurrency: test-android-${{ github.event.inputs.environment == '' && 'stage' || github.event.inputs.environment }}
name: Run tests against Android
runs-on: macos-latest
runs-on: macos-12
outputs:
maven_tests: ${{ steps.maven_tests.outcome }}
steps:
Expand Down Expand Up @@ -60,6 +63,10 @@ jobs:
profile: ${{ env.ANDROID_PROFILE }}
script: mvn test -DisRemote=true -DplatformName=android

- name: Copy TestNG allure result to the Cucumber allure result
if: always()
run: cp -r ${{ env.TESTNG_ALLURE_RESULTS }}/. ${{ env.CUCUMBER_ALLURE_RESULTS }}

- name: Upload results as artifacts
if: always()
uses: actions/upload-artifact@master
Expand All @@ -69,13 +76,15 @@ jobs:

build-and-test-ios:
env:
CUCUMBER_ALLURE_RESULTS: aquality-appium-mobile-template-cucumber/target/allure-results
TESTNG_ALLURE_RESULTS: aquality-appium-mobile-template-testng/target/allure-results
SUBPROJECT_NAME: aquality-appium-mobile-template-cucumber
ENVIRONMENT: ${{ github.event.inputs.environment == '' && 'stage' || github.event.inputs.environment }}
IOS_SIM_MODEL: iPhone 8

concurrency: test-ios-${{ github.event.inputs.environment == '' && 'stage' || github.event.inputs.environment }}
name: Run tests against iOS
runs-on: macos-latest
runs-on: macos-12
outputs:
maven_tests: ${{ steps.maven_tests.outcome }}
steps:
Expand Down Expand Up @@ -109,6 +118,10 @@ jobs:
id: maven_tests
run: mvn test -DisRemote=true -DplatformName=ios

- name: Copy TestNG allure result to the Cucumber allure result
if: always()
run: cp -r ${{ env.TESTNG_ALLURE_RESULTS }}/. ${{ env.CUCUMBER_ALLURE_RESULTS }}

- name: Upload results as artifacts
if: always()
uses: actions/upload-artifact@master
Expand Down
10 changes: 9 additions & 1 deletion aquality-appium-mobile-template-cucumber/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand All @@ -45,6 +49,10 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand All @@ -63,7 +71,7 @@
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-cucumber5-jvm</artifactId>
<version>2.13.3</version>
<version>${allure.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Feature: Demo
Background:
Given Allure test name has been updated by the platform parameter

@demo
Scenario: I try to login with invalid credentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import aquality.appium.mobile.application.AqualityServices;
import io.cucumber.java.After;

import static aquality.appium.mobile.application.AqualityServices.getApplication;

public class ApplicationHooks {

@After(order = 0)
public void closeApplication() {
if (AqualityServices.isApplicationStarted()) {
AqualityServices.getApplication().quit();
getApplication().terminate();
getApplication().quit();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package aquality.appium.mobile.template.cucumber.objectfactory;

import aquality.appium.mobile.application.AqualityServices;
import aquality.appium.mobile.template.modules.CustomMobileModule;
import aquality.appium.mobile.template.modules.ServiceModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
Expand All @@ -13,7 +15,7 @@ public class CustomObjectFactory implements ObjectFactory {
private final Injector injector;

public CustomObjectFactory() {
CustomMobileModule mobileModule = new CustomMobileModule(AqualityServices::getApplication);
CustomMobileModule mobileModule = new CustomMobileModule();
AqualityServices.initInjector(mobileModule);
this.injector = Guice.createInjector(Stage.PRODUCTION, CucumberModules.createScenarioModule(),
new ServiceModule(), mobileModule);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package aquality.appium.mobile.template.cucumber.stepdefinitions;

import aquality.appium.mobile.screens.screenfactory.IScreenFactory;
import aquality.appium.mobile.template.screens.Alert;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

import javax.inject.Inject;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

public class AlertSteps {

private final Alert alert;

@Inject
public AlertSteps(IScreenFactory screenFactory) {
alert = screenFactory.getScreen(Alert.class);
}

@Then("'{}' alert appears")
public void alertAppears(String alertMessage) {
assertTrue(alert.state().waitForDisplayed(), "Alert appeared");
assertEquals(alert.getMessage(), alertMessage, "Alert message is correct");
}

@When("I accept the alert")
public void acceptAlert() {
alert.tapOk();
}
}

This file was deleted.

58 changes: 58 additions & 0 deletions aquality-appium-mobile-template-testng/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-appium-mobile-java-template-project</artifactId>
<version>1.0.1-SNAPSHOT</version>
</parent>

<artifactId>aquality-appium-mobile-template-testng</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-appium-mobile-template</artifactId>
<version>1.0.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.9.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>${allure.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.25.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.10</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package aquality.appium.mobile.template.testng.constants;

import lombok.experimental.UtilityClass;

@UtilityClass
public class AlertMessages {
public static final String INVALID_CREDENTIALS = "Invalid login credentials, please try again";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package aquality.appium.mobile.template.testng.constants;

import lombok.experimental.UtilityClass;

@UtilityClass
public class ViewNames {
public static final String LOGIN_SCREEN = "Login Screen";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package aquality.appium.mobile.template.testng.steps;

import aquality.appium.mobile.template.screens.Alert;
import io.qameta.allure.Step;

import javax.inject.Inject;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

public class AlertSteps {

@Inject
private Alert alert;

@Step("'{alertMessage}' alert appears")
public void checkAlertAppears(String alertMessage) {
assertTrue(alert.state().waitForDisplayed(), "Alert appeared");
assertEquals(alert.getMessage(), alertMessage, "Alert message is correct");
}

@Step("I accept the alert")
public void acceptAlert() {
alert.tapOk();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package aquality.appium.mobile.template.testng.steps;

import aquality.appium.mobile.template.screens.chooseview.ChooseViewScreen;
import io.qameta.allure.Step;

import javax.inject.Inject;

public class ChooseViewSteps {

@Inject
private ChooseViewScreen chooseViewScreen;

@Step("I open '{viewName}' view")
public void openView(String viewName) {
chooseViewScreen.openView(viewName);
}
}
Loading

0 comments on commit 876420d

Please sign in to comment.