Skip to content
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
77 changes: 77 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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>

<groupId>SeleniumWebdriver</groupId>
<artifactId>WikipediaPDF_0001</artifactId>
<version>1.0-SNAPSHOT</version>

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

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>

<dependency>
<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-selenium-java</artifactId>
<version>4.0.1-SNAPSHOT</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.17.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.9.0</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.15.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>7.15.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.25.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>

</dependencies>

</project>
17 changes: 17 additions & 0 deletions src/test/java/wikipedia/TestRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package wikipedia;

import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;

@CucumberOptions(
features = {"src/test/java/wikipedia/features"},
glue = {"wikipedia.hooks", "wikipedia.stepDefinitions"}
)
public class TestRunner extends AbstractTestNGCucumberTests {
@Override
@DataProvider(parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}
}
6 changes: 6 additions & 0 deletions src/test/java/wikipedia/data/preTestData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"URL": "https://www.wikipedia.org/",
"SearchContext": "Albert Einstein",
"FileName": "Albert_Einstein.pdf",
"PageInformationHeader": "Information for \"Albert Einstein\""
}
24 changes: 24 additions & 0 deletions src/test/java/wikipedia/features/wikipeadia.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@


Feature: Wikipedia Functionality Testing

Background:
Given the user is on the Main page
Then the user inputs "Albert Einstein" in the search field

Scenario: Download PDF from Albert Einstein Article
Then the user clicks on the search submit button
And the user clicks the Tool menu button on the Article page
And the user clicks the Download as PDF button on the Article page
Then the file with the provided name on the Download as PDF page should be downloaded

Scenario: View Page Information for Albert Einstein Article
Then the user clicks on the search submit button
And the user clicks the Tool menu button on the Article page
And the user clicks the Page information button on the Article page
Then the Information page for the "Albert Einstein" article should be displayed

Scenario: Search Albert Einstein in Spanish Language
When the user changes the search language to "Español"
Then the user clicks on the search submit button
Then the Article page for "Albert Einstein" in Spanish should be open
29 changes: 29 additions & 0 deletions src/test/java/wikipedia/hooks/Hooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package wikipedia.hooks;

import aquality.selenium.browser.AqualityServices;
import aquality.selenium.browser.Browser;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.en.Given;
import org.testng.Assert;
import wikipedia.utils.DataProcessor;
import wikipedia.utils.DriverTools;
import static io.qameta.allure.Allure.step;

public class Hooks {

private Browser browser= AqualityServices.getBrowser();

@Before
public void setUp(){
// browser.maximize();
browser.setWindowSize(1440, 900);
browser.goTo(DataProcessor.processedData().getURL());
}

@After
public void tearDown(){
browser.quit();
}

}
37 changes: 37 additions & 0 deletions src/test/java/wikipedia/pages/ArticlePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package wikipedia.pages;

import aquality.selenium.browser.AqualityServices;
import aquality.selenium.browser.Browser;
import aquality.selenium.elements.interfaces.IButton;
import aquality.selenium.elements.interfaces.IElementFactory;
import aquality.selenium.elements.interfaces.ILabel;
import aquality.selenium.elements.interfaces.ILink;
import aquality.selenium.forms.Form;
import org.openqa.selenium.By;
import wikipedia.utils.DriverTools;

public class ArticlePage extends Form {

public ArticlePage() {
super(By.xpath("//*[contains(@class,'mw-page-title-main')]"),"Result page header");
}

private IElementFactory iElementFactory=AqualityServices.getElementFactory();

private final ILabel PAGE_HEADER= iElementFactory.getLabel(By.cssSelector("#firstHeading .mw-page-title-main"),"Page Header");
private final ILink PAGE_INFORMATION_LINK=iElementFactory.getLink(By.cssSelector("a[title='More information about this page'] span"),"Page information link");
private final IButton TOOLS_DROPDOWN_BTN=iElementFactory.getButton(By.cssSelector(".vector-page-tools-landmark #vector-page-tools-dropdown"),"Tools Dropdown button");
private final ILink PDF_DOWNLOAD_LINK=iElementFactory.getLink(By.xpath("//*[text()='Download as PDF']"),"PDF Download link");




public ILabel getPAGE_HEADER(){return PAGE_HEADER;}
public String getPageHeaderText(){return getPAGE_HEADER().getText();}
public ILink getPAGE_INFORMATION_LINK(){return PAGE_INFORMATION_LINK;}
public void clickOnPageInformationLink(){getPAGE_INFORMATION_LINK().click();}
public IButton getTOOLS_DROPDOWN_BTN(){return TOOLS_DROPDOWN_BTN;}
public void clickOnToolsDropdownBtn(){getTOOLS_DROPDOWN_BTN().click();}
public ILink getPDF_DOWNLOAD_LINK(){return PDF_DOWNLOAD_LINK;}
public void clickOnPdfDownloadLink(){getPDF_DOWNLOAD_LINK().click();}
}
34 changes: 34 additions & 0 deletions src/test/java/wikipedia/pages/InformationPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package wikipedia.pages;

import aquality.selenium.browser.AqualityServices;
import aquality.selenium.elements.interfaces.IElementFactory;
import aquality.selenium.elements.interfaces.ILabel;
import aquality.selenium.forms.Form;
import org.openqa.selenium.By;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class InformationPage extends Form {
public InformationPage() {
super(By.xpath("//*[@role='main']"), "Information page");
}

private IElementFactory iElementFactory= AqualityServices.getElementFactory();

private final ILabel PAGE_HEADER=iElementFactory.getLabel(By.xpath("//*[@id='firstHeading']"),",Page header");




public String getPAGE_HEADER(){
Pattern pattern = Pattern.compile("\"(.*?)\"");
Matcher matcher = pattern.matcher(PAGE_HEADER.getText());
String lastMatchedValue = "";
while (matcher.find()) {
lastMatchedValue = matcher.group(1).trim();
}
return lastMatchedValue;
}

}
54 changes: 54 additions & 0 deletions src/test/java/wikipedia/pages/MainPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package wikipedia.pages;

import aquality.selenium.browser.AqualityServices;
import aquality.selenium.elements.ElementType;
import aquality.selenium.elements.interfaces.*;
import aquality.selenium.forms.Form;
import org.openqa.selenium.By;
import java.util.List;

public class MainPage extends Form {

public MainPage() {
super(By.id("www-wikipedia-org"), "Search Page");
}

private IElementFactory iElementFactory= AqualityServices.getElementFactory();

private final ITextBox SEARCH_FIELD=iElementFactory.getTextBox(By.xpath("//*[@id='searchInput']"),"Search field on the search page");
private final IButton LANGUAGE_SELECITOR_BTN=iElementFactory.getButton(By.xpath("//*[contains(@class,'hide-arrow')]"),"Language selector button");
private List<IElement> languages;
private final IButton SEARCH_SUBMIT_BTN=iElementFactory.getButton(By.xpath("//*[@type='submit']"),"Search submit button on the search page");
private List<IElement> searchResults;





public ITextBox getSEARCH_FIELD(){return SEARCH_FIELD;}

public void typeInTheSearchField(String text){getSEARCH_FIELD().clearAndType(text);}

public IButton getSEARCH_SUBMIT_BTN(){return SEARCH_SUBMIT_BTN;}
public void clickOnSearchSubmitBtn(){getSEARCH_SUBMIT_BTN().click();}

public IButton getLANGUAGE_SELECTOR_BTN(){return LANGUAGE_SELECITOR_BTN;}
public void clickOnTheLanguageSelectorBtn(){getLANGUAGE_SELECTOR_BTN().click();}
public List<IElement> setLanguages(){
languages=iElementFactory.findElements(By.xpath("//*[@id='searchLanguage']/option"), "List of languages", ElementType.BUTTON);
return languages;
}
public void setLanguageToEspanol(String text){
setLanguages();
for(IElement language:languages){
if(language.getText().equals(text)){
language.click();
}
}
}
public List<IElement> getSearchResults(){
searchResults=iElementFactory.findElements(By.xpath("//*[@class='suggestion-link']"),"Search results",ElementType.LABEL);
return searchResults;
}

}
30 changes: 30 additions & 0 deletions src/test/java/wikipedia/pages/PDFDownloadPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package wikipedia.pages;

import aquality.selenium.browser.AqualityServices;
import aquality.selenium.elements.interfaces.IButton;
import aquality.selenium.elements.interfaces.IElementFactory;
import aquality.selenium.elements.interfaces.ILabel;
import aquality.selenium.forms.Form;
import org.openqa.selenium.By;
import wikipedia.utils.DriverTools;

public class PDFDownloadPage extends Form {

public PDFDownloadPage() {
super(By.xpath("//h1[contains(@class,'mw-first-heading') and text()='Download as PDF']"), "PDF Download page");
}

private IElementFactory iElementFactory= AqualityServices.getElementFactory();

private final ILabel FILE_DOWNLOAD_BOX= iElementFactory.getLabel(By.xpath("//*[contains(@class,'mw-electronpdfservice-selection-label-text')]"),"File download box");
private final IButton FILE_DOWNLOAD_BTN=iElementFactory.getButton(By.xpath("//*[contains(@class,'oo-ui-labelElement-label')and text()='Download']"),"File download button");




public ILabel getFILE_DOWNLOAD_BOX(){return FILE_DOWNLOAD_BOX;}
public String getFileDownloadBoxText(){return getFILE_DOWNLOAD_BOX().getText();}
public IButton getFILE_DOWNLOAD_BTN(){return FILE_DOWNLOAD_BTN;}
public void clickOnFileDownloadBtn(){getFILE_DOWNLOAD_BTN().click();}

}
29 changes: 29 additions & 0 deletions src/test/java/wikipedia/stepDefinitions/ArticlePageSteps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package wikipedia.stepDefinitions;

import io.cucumber.java.en.And;
import io.cucumber.java.en.Then;
import org.testng.Assert;
import wikipedia.pages.ArticlePage;
import wikipedia.utils.DataProcessor;

public class ArticlePageSteps {

private ArticlePage articlePage=new ArticlePage();

@And("the user clicks the Tool menu button on the Article page")
public void theUserClicksTheToolMenuButtonOnTheArticlePage() {
articlePage.clickOnToolsDropdownBtn();
}
@And("the user clicks the Download as PDF button on the Article page")
public void theUserClicksTheDownloadAsPDFBtn(){
articlePage.clickOnPdfDownloadLink();
}
@And("the user clicks the Page information button on the Article page")
public void theUserClicksThePageInformationButtonOnTheArticlePage() {
articlePage.clickOnPageInformationLink();
}
@Then("the Article page for {string} in Spanish should be open")
public void checkPageHeader(String string){
Assert.assertEquals(articlePage.getPageHeaderText(),string,"Page header does not match");
}
}
19 changes: 19 additions & 0 deletions src/test/java/wikipedia/stepDefinitions/InformationPageSteps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package wikipedia.stepDefinitions;

import io.cucumber.java.en.Then;
import org.testng.Assert;
import wikipedia.pages.InformationPage;

public class InformationPageSteps {

private InformationPage informationPage=new InformationPage();




@Then("the Information page for the {string} article should be displayed")
public void infoPageIsDisplayed(String string){
Assert.assertEquals(informationPage.getPAGE_HEADER(), string,"Page informaiton is not correct");
}

}
Loading