-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TestNG template project
- Loading branch information
Showing
16 changed files
with
363 additions
and
27 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...cumber/src/test/java/aquality/selenium/template/cucumber/hooks/AqualityServicesHooks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
package aquality.selenium.template.cucumber.hooks; | ||
|
||
import aquality.selenium.browser.AqualityServices; | ||
import aquality.selenium.template.cucumber.objectfactory.CustomBrowserModule; | ||
import aquality.selenium.template.modules.CustomBrowserModule; | ||
import io.cucumber.java.Before; | ||
|
||
public class AqualityServicesHooks { | ||
|
||
@Before(order = 0) | ||
public void reinitializeAqualityServices() { | ||
AqualityServices.initInjector(new CustomBrowserModule(AqualityServices::getBrowser)); | ||
AqualityServices.initInjector(new CustomBrowserModule()); | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
.../src/test/java/aquality/selenium/template/cucumber/objectfactory/CustomBrowserModule.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?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-selenium-template-project</artifactId> | ||
<version>1.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>aquality-selenium-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-selenium-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> |
56 changes: 56 additions & 0 deletions
56
...plate-testng/src/test/java/aquality/selenium/template/testng/steps/ui/ContactUsSteps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package aquality.selenium.template.testng.steps.ui; | ||
|
||
import aquality.selenium.template.forms.pages.ContactUsPage; | ||
import aquality.selenium.template.models.ContactUsInfo; | ||
import com.google.inject.Inject; | ||
import io.qameta.allure.Step; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
public class ContactUsSteps { | ||
@Inject | ||
private ContactUsPage contactUsPage; | ||
|
||
@Step("Contact us page is opened") | ||
public void checkContactUsPageIsOpened() { | ||
assertThat(contactUsPage.state().isDisplayed()) | ||
.describedAs(contactUsPage.getName() + " must be opened") | ||
.isTrue(); | ||
} | ||
|
||
@Step("I fill contact form using following data:") | ||
public void fillContactUsPage(ContactUsInfo contactUsInfo) { | ||
contactUsPage.setName(contactUsInfo.getName()) | ||
.setCompany(contactUsInfo.getCompany()) | ||
.setPhone(contactUsInfo.getPhone()) | ||
.setComment(contactUsInfo.getComment()); | ||
} | ||
|
||
@Step("I accept Privacy and Cookies Policy") | ||
public void acceptPrivacyAndCookiesPolicy() { | ||
contactUsPage.checkPrivacyAndCookies(); | ||
} | ||
|
||
@Step("I click Send button") | ||
public void clickSendButton(){ | ||
contactUsPage.clickSend(); | ||
} | ||
|
||
@Step("Notification about empty fields is present") | ||
public void checkEmptyFieldWarning() { | ||
assertThat(contactUsPage.isEmailValidationMessagePresent()) | ||
.describedAs("Email validation message should be displayed") | ||
.isTrue(); | ||
} | ||
|
||
@Step("I save Contact us page dump") | ||
public void saveContactUsPageDump() { | ||
contactUsPage.dump().save(); | ||
} | ||
|
||
@Step("Contact us page dump is different") | ||
public void contactUsPageDumpIsDifferent() { | ||
assertTrue(contactUsPage.dump().compare() > 0, "The form dump should differ"); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...emplate-testng/src/test/java/aquality/selenium/template/testng/steps/ui/LandingSteps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package aquality.selenium.template.testng.steps.ui; | ||
|
||
import aquality.selenium.template.forms.TopBarMenu; | ||
import aquality.selenium.template.forms.pages.MainPage; | ||
import com.google.inject.Inject; | ||
import io.qameta.allure.Step; | ||
|
||
import static aquality.selenium.template.forms.TopBarMenu.Item.CONTACT_US; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class LandingSteps { | ||
|
||
@Inject | ||
private MainPage mainPage; | ||
@Inject | ||
private TopBarMenu topBarMenu; | ||
|
||
@Step("Main page is opened") | ||
public void checkMainPageIsOpened() { | ||
assertThat(mainPage.state().waitForDisplayed()) | ||
.describedAs(mainPage.getName() + " must be opened") | ||
.isTrue(); | ||
} | ||
|
||
@Step("I open Contact us page") | ||
public void openContactUsPage() { | ||
mainPage.acceptCookies(); | ||
topBarMenu.openHeaderMenu(CONTACT_US); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...enium-template-testng/src/test/java/aquality/selenium/template/testng/tests/BaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package aquality.selenium.template.testng.tests; | ||
|
||
import aquality.selenium.browser.AqualityServices; | ||
import aquality.selenium.browser.Browser; | ||
import aquality.selenium.core.localization.ILocalizedLogger; | ||
import aquality.selenium.template.configuration.Configuration; | ||
import aquality.selenium.template.modules.CustomBrowserModule; | ||
import aquality.selenium.template.testng.steps.ui.LandingSteps; | ||
import aquality.selenium.template.testng.utilities.ModuleFactory; | ||
import aquality.selenium.template.utilities.IScreenshotProvider; | ||
import com.google.inject.Inject; | ||
import io.qameta.allure.Allure; | ||
import org.assertj.core.api.Assertions; | ||
import org.assertj.core.description.Description; | ||
import org.testng.ITestContext; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.BeforeTest; | ||
import org.testng.annotations.Guice; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.util.function.Consumer; | ||
|
||
@Guice(moduleFactory = ModuleFactory.class) | ||
public class BaseTest { | ||
@Inject | ||
LandingSteps landingSteps; | ||
@Inject | ||
IScreenshotProvider screenshotProvider; | ||
@Inject | ||
ILocalizedLogger localizedLogger; | ||
@Inject | ||
CustomBrowserModule customBrowserModule; | ||
private Browser browser; | ||
|
||
@BeforeTest | ||
public void beforeTest() { | ||
Consumer<Description> descriptionConsumer = description -> localizedLogger.info("Assertion: %s", description.value()); | ||
Assertions.setDescriptionConsumer(descriptionConsumer); | ||
} | ||
|
||
@BeforeMethod | ||
public void setup() { | ||
AqualityServices.initInjector(customBrowserModule); | ||
browser = AqualityServices.getBrowser(); | ||
browser.goTo(Configuration.getStartUrl()); | ||
browser.waitForPageToLoad(); | ||
} | ||
|
||
@AfterMethod | ||
public void cleanUp(ITestContext context) { | ||
if (AqualityServices.isBrowserStarted()) { | ||
Allure.addAttachment("page source", "text/html", | ||
browser.getDriver().getPageSource(), "html"); | ||
Allure.addAttachment("screenshot", "image/png", | ||
new ByteArrayInputStream(screenshotProvider.takeScreenshot()), "png"); | ||
browser.quit(); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...template-testng/src/test/java/aquality/selenium/template/testng/tests/ContactUsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package aquality.selenium.template.testng.tests; | ||
|
||
import aquality.selenium.template.models.ContactUsInfo; | ||
import aquality.selenium.template.testng.steps.ui.ContactUsSteps; | ||
import aquality.selenium.template.testng.utilities.JsonDataProvider; | ||
import com.google.inject.Inject; | ||
import org.testng.annotations.Test; | ||
|
||
public class ContactUsTests extends BaseTest { | ||
@Inject | ||
ContactUsSteps contactUsSteps; | ||
|
||
@Test(description = "Empty email validation is working on Contact Us page", | ||
dataProvider = "getContacts", dataProviderClass = JsonDataProvider.class) | ||
public void testEmailValidation(ContactUsInfo contactInfo) { | ||
landingSteps.checkMainPageIsOpened(); | ||
landingSteps.openContactUsPage(); | ||
contactUsSteps.checkContactUsPageIsOpened(); | ||
|
||
contactUsSteps.saveContactUsPageDump(); | ||
contactUsSteps.fillContactUsPage(contactInfo); | ||
contactUsSteps.acceptPrivacyAndCookiesPolicy(); | ||
contactUsSteps.clickSendButton(); | ||
|
||
contactUsSteps.checkEmptyFieldWarning(); | ||
contactUsSteps.contactUsPageDumpIsDifferent(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...te-testng/src/test/java/aquality/selenium/template/testng/utilities/JsonDataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package aquality.selenium.template.testng.utilities; | ||
|
||
import aquality.selenium.browser.AqualityServices; | ||
import aquality.selenium.template.models.ContactUsInfo; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.SneakyThrows; | ||
import lombok.experimental.UtilityClass; | ||
import org.testng.annotations.DataProvider; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Paths; | ||
|
||
@UtilityClass | ||
public class JsonDataProvider { | ||
private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
||
@DataProvider | ||
@SneakyThrows | ||
public Object[][] getContacts() { | ||
return getDataListFromJson("contacts", ContactUsInfo[].class); | ||
} | ||
|
||
private Object[][] getDataListFromJson(String filename, Class<? extends Object[]> valueType) throws IOException { | ||
Object[] dataList; | ||
try { | ||
File file = Paths.get(String.format("src/test/resources/data/%s.json", filename)).toFile(); | ||
dataList = MAPPER.readValue(file, valueType); | ||
} | ||
catch (IOException exception) { | ||
AqualityServices.getLogger().debug("IO error occurred while reading the data from the file " + filename, exception); | ||
throw exception; | ||
} | ||
return new Object[][] {dataList}; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...plate-testng/src/test/java/aquality/selenium/template/testng/utilities/ModuleFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package aquality.selenium.template.testng.utilities; | ||
|
||
import aquality.selenium.template.modules.CustomBrowserModule; | ||
import aquality.selenium.template.modules.ServiceModule; | ||
import com.google.inject.Module; | ||
import com.google.inject.util.Modules; | ||
import org.testng.IModuleFactory; | ||
import org.testng.ITestContext; | ||
|
||
public class ModuleFactory implements IModuleFactory { | ||
@Override | ||
public Module createModule(ITestContext iTestContext, Class<?> aClass) { | ||
return Modules.combine(new CustomBrowserModule(), new ServiceModule()); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
aquality-selenium-template-testng/src/test/resources/data/contacts.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
{ | ||
"name": "Peter Parker", | ||
"company": "Aquality Automation", | ||
"phone": "+44 208 816 7320", | ||
"comment": "I'd like to contact you!" | ||
} | ||
] |
28 changes: 28 additions & 0 deletions
28
...lenium-template/src/main/java/aquality/selenium/template/modules/CustomBrowserModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package aquality.selenium.template.modules; | ||
|
||
import aquality.selenium.browser.AqualityServices; | ||
import aquality.selenium.browser.Browser; | ||
import aquality.selenium.browser.BrowserModule; | ||
import aquality.selenium.core.localization.ILocalizedLogger; | ||
import aquality.selenium.core.utilities.IElementActionRetrier; | ||
import aquality.selenium.template.utilities.AllureBasedLocalizedLogger; | ||
import aquality.selenium.template.utilities.CustomActionRetrier; | ||
import com.google.inject.Provider; | ||
|
||
public class CustomBrowserModule extends BrowserModule { | ||
private static final Provider<Browser> browserProvider = AqualityServices::getBrowser; | ||
|
||
public CustomBrowserModule() { | ||
super(browserProvider); | ||
} | ||
|
||
@Override | ||
public Class<? extends ILocalizedLogger> getLocalizedLoggerImplementation() { | ||
return AllureBasedLocalizedLogger.class; | ||
} | ||
|
||
@Override | ||
public Class<? extends IElementActionRetrier> getElementActionRetrierImplementation() { | ||
return CustomActionRetrier.class; | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...cucumber/objectfactory/ServiceModule.java → ...enium/template/modules/ServiceModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.