Added helpers, logs

This commit is contained in:
SemenovaMasha 2018-04-05 13:26:02 +04:00
parent 0deb6f91e2
commit fc913632db
33 changed files with 927 additions and 428 deletions

156
Semenova/.gitignore vendored Normal file
View File

@ -0,0 +1,156 @@
# Created by https://www.gitignore.io/api/intellij,java,maven,gradle,eclipse,netbeans
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
*.iml
nb-configuration.xml
## Directory-based project format:
.idea/
.target
# if you remove the above rule, at least ignore the following:
# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries
# .idea/shelf
# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml
# Gradle:
# .idea/gradle.xml
# .idea/libraries
# Mongo Explorer plugin:
# .idea/mongoSettings.xml
## File-based project format:
*.ipr
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Java ###
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
### Gradle ###
.gradle
build/
# Ignore Gradle GUI config
gradle-app.setting
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
# Cache of project
.gradletasknamecache
### Eclipse ###
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
# Eclipse Core
.project
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# JDT-specific (Eclipse Java Development Tools)
.classpath
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
.nb-gradle/
*.log
csv/

View File

2
Semenova/README.md Normal file
View File

@ -0,0 +1,2 @@
Selenium WebDriver example project

View File

@ -1,3 +1,4 @@
import PageHelpers.CalculatorPageHelper;
import Pages.CalculatorPage;
import context.ChromeContext;
import context.Context;
@ -8,10 +9,14 @@ import org.junit.Test;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.support.PageFactory;
import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
public class CalculatorTest {
private final static String APP_URL = "http://www.gazprom.ru/investors/stock/investor-tools/calc/";
private static Logger log = Logger.getLogger(CalculatorTest.class.getName());
private static Context context;
@Before
@ -25,40 +30,28 @@ public class CalculatorTest {
@After
public void quit() {
context.close();
}
@Test
public void countInvestor() throws InterruptedException {
System.out.println("Investor's count test");
Thread.sleep(1000);
log.logp(INFO, getClass().getName(), "countInvestor", "Investor's count test");
CalculatorPage calculatorPage = PageFactory.initElements(context.getDriver(), CalculatorPage.class);
calculatorPage.switchToCalcFrame();
calculatorPage.insertFromDate("30.09.2011");
calculatorPage.insertToDate("01.02.2018");
calculatorPage.insertAmount("1");
CalculatorPageHelper calculatorPageHelper = new CalculatorPageHelper(calculatorPage);
calculatorPageHelper.waitAndInsertFromDate("30.09.2011");
calculatorPageHelper.waitAndInsertToDate("01.02.2018");
calculatorPageHelper.waitAndInsertAmount("1");
calculatorPage.clickCalcBtn();
Thread.sleep(1000);
double startPrice = calculatorPage.getStartPrice();
double endPrice = calculatorPage.getEndPrice();
double reInvPrice = calculatorPage.getReInvPrice();
double changePrice = calculatorPage.getChangePrice();
double changePriceRe = calculatorPage.getChangePriceRe();
double income = calculatorPage.getIncome();
// System.out.println(startPrice+"!"+endPrice+"!"+reInvPrice+"!"+changePrice+"!"+changePriceRe+"!"+income+"!");
Assert.assertTrue(((double)Math.round((endPrice-startPrice) * 100))/100==income
&&((double)Math.round(income/startPrice * 100*100))/100==changePrice
&&((double)Math.round((reInvPrice-startPrice)/startPrice*100 *100))/100 ==changePriceRe);
Assert.assertTrue(calculatorPageHelper.isCalculationRight());
}
}

View File

@ -12,11 +12,15 @@ import org.openqa.selenium.Dimension;
import org.openqa.selenium.support.PageFactory;
import java.io.File;
import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
public class DocumentTests {
private final static String APP_URL = "http://www.gazprom.ru/";
private static Logger log = Logger.getLogger(DocumentTests.class.getName());
private static Context context;
private String tmpPath;
@ -39,25 +43,29 @@ public class DocumentTests {
@Test
public void downloadDocs() throws InterruptedException {
System.out.println("Downloading test");
log.logp(INFO, getClass().getName(), "downloadDocs", "Downloading test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickMenuElement(1);
page.clickMenuElementShareholder();
ForShareholders shareholdersPage = PageFactory.initElements(context.getDriver(), ForShareholders.class);
int elementNumber = 0;
String fileName = shareholdersPage.getFileName(elementNumber);
shareholdersPage.clickDownloadLink(elementNumber);
File f = new File(tmpPath +fileName);
System.out.println(tmpPath + fileName);
log.logp(INFO, getClass().getName(), "downloadDocs", "Path: "+tmpPath +fileName);
int timeout=0;
while(!f.exists()&&timeout<100){
Thread.sleep(500);
timeout++;
checkDownload(fileName,100,500);
}
private void checkDownload(String fileName,int timeout, int period) throws InterruptedException {
File f = new File(tmpPath +fileName);
int time=0;
while(!f.exists()&&time<timeout){
Thread.sleep(period);
time++;
}
Assert.assertTrue(f.exists());
if(f.exists()) {
f.delete();
@ -66,33 +74,22 @@ public class DocumentTests {
@Test
public void downloadJournal() throws InterruptedException {
System.out.println("Downloading journal test");
log.logp(INFO, getClass().getName(), "downloadJournal", "Downloading journal test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickMenuElement(2);
page.clickMenuElementPress();
PressPage pressPage = PageFactory.initElements(context.getDriver(), PressPage.class);
pressPage.clickMenuElement(2);
pressPage.clickMenuElementJournal();
JournalsPage journalsPage = PageFactory.initElements(context.getDriver(), JournalsPage.class);
int elementNumber = 0;
String fileName = journalsPage.getFileName(elementNumber);
journalsPage.clickImgLink(elementNumber);
File f = new File(tmpPath +fileName);
System.out.println(tmpPath + fileName);
int timeout=0;
while(!f.exists()&&timeout<150){
Thread.sleep(1000);
timeout++;
}
Assert.assertTrue(f.exists());
if(f.exists()) {
f.delete();
}
log.logp(INFO, getClass().getName(), "downloadJournal", "Path: "+tmpPath +fileName);
checkDownload(fileName,150,1000);
}
}

View File

@ -1,3 +1,4 @@
import PageHelpers.FeedbackPageHelper;
import Pages.*;
import context.ChromeContext;
import context.Context;
@ -7,17 +8,19 @@ import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.support.PageFactory;
import twitter4j.*;
import twitter4j.conf.ConfigurationBuilder;
import java.util.List;
import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
public class FeedbackTests {
private final static String APP_URL = "http://www.gazprom.ru/";
private static java.util.logging.Logger log = Logger.getLogger(FeedbackTests.class.getName());
private static Context context;
@Before
public void setup() {
context = new ChromeContext();
@ -29,55 +32,52 @@ public class FeedbackTests {
@After
public void quit() {
context.close();
}
@Test
public void offer() {
System.out.println("Offer test");
log.logp(INFO, getClass().getName(), "offer", "Offer test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickAdditionalMenuElement(1);
page.clickAdditionalMenuElementPurchase();
PurchasesPage purchasesPage = PageFactory.initElements(context.getDriver(), PurchasesPage.class);
purchasesPage.clickMenuItem(10);
purchasesPage.clickMenuItemFeedback();
FeedbackPage feedbackPage = PageFactory.initElements(context.getDriver(), FeedbackPage.class);
feedbackPage.insertEmail("test@mail.ru");
feedbackPage.insertText("test text");
feedbackPage.submitFeedback();
String output = feedbackPage.getOutput();
FeedbackPageHelper helper = new FeedbackPageHelper(feedbackPage);
Assert.assertTrue(output.equals("Ваше сообщение отправлено."));
Assert.assertTrue(helper.isReceiveSuccess());
}
@Test
public void shareFunction() throws TwitterException {
System.out.println("Sharing test");
public void shareFunction() {
log.logp(INFO, getClass().getName(), "shareFunction", "Sharing test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickMenuElement(2);
page.clickMenuElementPress();
PressPage pressPage = PageFactory.initElements(context.getDriver(), PressPage.class);
pressPage.clickMenuElement(1);
pressPage.clickMenuElementMedia();
MediaLib mediaLib = PageFactory.initElements(context.getDriver(), MediaLib.class);
mediaLib.clickItemImage(0);
int elementNumber = 0;
mediaLib.clickItemImage(elementNumber);
mediaLib.clickSocialLink(2);
// String title = mediaLib.getAlbumTitle();
mediaLib.clickSocialLinkTwitter();
for (String winHandle : context.getDriver().getWindowHandles()) {
context.getDriver().switchTo().window(winHandle);
}
mediaLib.switchToTwitterPopup();
TwitterSharingPopup twitterSharingPopup = PageFactory.initElements(context.getDriver(), TwitterSharingPopup.class);
Assert.assertTrue(twitterSharingPopup.submitBtnPresent());
Assert.assertTrue(twitterSharingPopup.isSubmitBtnPresent());
}
}

View File

@ -1,3 +1,7 @@
import PageHelpers.EventsPageHelper;
import PageHelpers.PurchasePageHelper;
import PageHelpers.SearchResultsPageHelper;
import PageHelpers.SubsidiariesPageHelper;
import Pages.*;
import context.ChromeContext;
import context.Context;
@ -8,13 +12,14 @@ import org.junit.Test;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.support.PageFactory;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
public class FilterTests {
private final static String APP_URL = "http://www.gazprom.ru/";
private static java.util.logging.Logger log = Logger.getLogger(FilterTests.class.getName());
private static Context context;
@ -33,8 +38,8 @@ public class FilterTests {
}
@Test
public void simpleSearch() throws ParseException, InterruptedException {
System.out.println("Simple search test");
public void simpleSearch() throws ParseException {
log.logp(INFO, getClass().getName(), "simpleSearch", "Simple search test");
MainPage mainPage = PageFactory.initElements(context.getDriver(), MainPage.class);
mainPage.clickSearchBtn();
@ -44,86 +49,33 @@ public class FilterTests {
mainPage.submitSearch();
SearchResultsPage searchResultsPage = PageFactory.initElements(context.getDriver(), SearchResultsPage.class);
boolean order = true;
DateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
Date datePrev = new Date();
boolean suitable = true;
SearchResultsPageHelper helper = new SearchResultsPageHelper(searchResultsPage);
Thread.sleep(2000);
for (int i = 0; i < searchResultsPage.getItemsCount(); i++) {
Date dateCur = format.parse(searchResultsPage.getItemsDate(i));
if(dateCur.after(datePrev)) {
System.out.println(dateCur +"!"+datePrev);
order = false;
break;
}
if(!searchResultsPage.getItemsText(i).toLowerCase().contains(queryString)){
System.out.println("1"+searchResultsPage.getItemsText(i).toLowerCase());
System.out.println("2"+queryString);
suitable = false;
break;
}
datePrev= dateCur;
}
Assert.assertTrue(order&&suitable);
Assert.assertTrue(helper.isSuitable(queryString));
}
@Test
public void sorting() {
System.out.println("Sorting test");
log.logp(INFO, getClass().getName(), "sorting", "Sorting test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickMenuElement(0);
page.clickMenuElementAbout();
AboutPage aboutPage = PageFactory.initElements(context.getDriver(), AboutPage.class);
aboutPage.clickMenuElement(4);
aboutPage.clickMenuElementSubsidaries();
SubsidiariesPage subsidiariesPage = PageFactory.initElements(context.getDriver(), SubsidiariesPage.class);
subsidiariesPage.clickPercentFilter();
boolean order = true;
SubsidiariesPageHelper helper = new SubsidiariesPageHelper(subsidiariesPage);
for (int i = 0; i < subsidiariesPage.getItemsPercent100Count(); i++) {
float percent = subsidiariesPage.getPartOfItemPercent100(i);
// System.out.println(percent);
if(percent!= 100.0f){
System.out.println("!"+percent);
order = false;
break;
}
}
for (int i = 0; i < subsidiariesPage.getItemsPercentMore50Count(); i++) {
float percent = subsidiariesPage.getPartOfItemPercentMore50(i);
// System.out.println(percent);
if(percent<= 50.0f){
System.out.println("!"+percent);
order = false;
break;
}
}
for (int i = 0; i < subsidiariesPage.getItemsPercentLess50Count(); i++) {
float percent = subsidiariesPage.getPartOfItemPercentLess50(i);
// System.out.println(percent);
if(percent> 50.0f){
System.out.println("!"+percent);
order = false;
break;
}
}
Assert.assertTrue(order);
Assert.assertTrue(helper.isOrder());
}
@Test
public void filteredSearch() throws ParseException, InterruptedException {
System.out.println("Filtered search test");
log.logp(INFO, getClass().getName(), "filteredSearch", "Filtered search test");
MainPage mainPage = PageFactory.initElements(context.getDriver(), MainPage.class);
mainPage.clickSearchBtn();
@ -133,109 +85,54 @@ public class FilterTests {
mainPage.submitSearch();
SearchResultsPage searchResultsPage = PageFactory.initElements(context.getDriver(), SearchResultsPage.class);
SearchResultsPageHelper helper = new SearchResultsPageHelper(searchResultsPage);
searchResultsPage.setFilterOn();
searchResultsPage.selectYear(13);
searchResultsPage.selectYearByPosition(13);
int year = 2017;
Thread.sleep(2000);
boolean order = true;
DateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
Calendar calendar = new GregorianCalendar();
Date datePrev = new Date();
boolean suitable = true;
for (int i = 0; i < searchResultsPage.getItemsCount(); i++) {
Date dateCur = format.parse(searchResultsPage.getItemsDate(i));
if(dateCur.after(datePrev)) {
System.out.println(dateCur +"!"+datePrev);
order = false;
break;
}
calendar.setTime(dateCur);
if(!searchResultsPage.getItemsText(i).toLowerCase().contains(queryString)||calendar.get(Calendar.YEAR)!=year){
System.out.println("1"+searchResultsPage.getItemsText(i).toLowerCase().contains(queryString));
System.out.println("2"+calendar.get(Calendar.YEAR));
suitable = false;
break;
}
}
Assert.assertTrue(order&&suitable);
Assert.assertTrue(helper.isSuitable(queryString,year));
}
@Test
public void leftMenuFilter() throws ParseException {
System.out.println("Filter by left menu test");
log.logp(INFO, getClass().getName(), "leftMenuFilter", "Filter by left menu test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickMenuElement(2);
page.clickMenuElementPress();
PressPage pressPage = PageFactory.initElements(context.getDriver(), PressPage.class);
pressPage.clickMenuElement(0);
pressPage.clickMenuElementEventpage();
EventsPage eventsPage = PageFactory.initElements(context.getDriver(), EventsPage.class);
eventsPage.selectYear(1);
eventsPage.selectMonth(1);
eventsPage.selectYearByPosition(1);
eventsPage.selectMonthByPosition(1);
int year = 2017;
int month = 1;
boolean suitable = true;
DateFormat format = new SimpleDateFormat("d MMMM, hh:mm");
Calendar calendar = new GregorianCalendar();
for (int i = 0; i < eventsPage.getResultsCount(); i++) {
Date dateCur = format.parse(eventsPage.getDateOfResult(i));
calendar.setTime(dateCur);
// System.out.println(calendar.get(Calendar.MONTH));
EventsPageHelper helper = new EventsPageHelper(eventsPage);
if(calendar.get(Calendar.MONTH)!=month){
suitable = false;
break;
}
}
Assert.assertTrue(suitable);
Assert.assertTrue(helper.isSuitable(month));
}
@Test
public void pagination() throws InterruptedException {
System.out.println("Pagination test");
public void pagination() {
log.logp(INFO, getClass().getName(), "pagination", "Pagination test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickAdditionalMenuElement(1);
page.clickAdditionalMenuElementPurchase();
PurchasesPage purchasesPage = PageFactory.initElements(context.getDriver(), PurchasesPage.class);
purchasesPage.clickMenuItem(2);
// Thread.sleep(2000);
List<String> purchaseNumbers = new ArrayList();
for (int i = 0; i < purchasesPage.getItemsCount(); i++) {
purchaseNumbers.add(purchasesPage.getPurchaseNumber(i));
// System.out.println(purchasesPage.getPurchaseNumber(i));
}
purchasesPage.clickMenuItemInWork();
int pageNumber = 1;
purchasesPage.clickPage(pageNumber);
Thread.sleep(2000);
boolean turn = purchasesPage.isSelectedPage(pageNumber);
boolean found = false;
purchasesPage = PageFactory.initElements(context.getDriver(), PurchasesPage.class);
PurchasePageHelper helper = new PurchasePageHelper(purchasesPage);
for (int i = 0; i < purchasesPage.getItemsCount(); i++) {
if(purchaseNumbers.contains(purchasesPage.getPurchaseNumber(i)))
found=true;
// System.out.println(purchasesPage.getPurchaseNumber(i));
Assert.assertTrue(helper.waitAndCheckPageSelection(pageNumber));
}
Assert.assertTrue(turn&&!found);
}
}

View File

@ -1,3 +1,5 @@
import PageHelpers.AlbumPageHelper;
import PageHelpers.MediaLibPageHelper;
import Pages.AlbumPage;
import Pages.MediaLib;
import Pages.VideoPage;
@ -10,14 +12,15 @@ import org.junit.Test;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.support.PageFactory;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
public class MultimediaTests {
private final static String APP_URL = "http://www.gazprom.ru/press/media/";
private static java.util.logging.Logger log = Logger.getLogger(MultimediaTests.class.getName());
private static Context context;
@ -36,117 +39,75 @@ public class MultimediaTests {
}
@Test
public void albumList() throws ParseException, InterruptedException {
System.out.println("List of albums test");
public void albumList() throws ParseException {
log.logp(INFO, getClass().getName(), "albumList", "List of albums test");
MediaLib mediaLib = PageFactory.initElements(context.getDriver(), MediaLib.class);
mediaLib.selectMonth(1);
// Thread.sleep(2000);
mediaLib.selectMonthByPosition(1);
boolean order = true;
DateFormat format = new SimpleDateFormat("yyyy.M.d H:m");
Date datePrev = format.parse(mediaLib.getDateOfItem(0));
for (int i = 1; i < mediaLib.getItemsCount(); i++) {
Date dateCur = format.parse(mediaLib.getDateOfItem(i));
if(dateCur.after(datePrev)) {
System.out.println(dateCur+"!"+datePrev);
order = false;
break;
}
datePrev = dateCur;
}
Assert.assertTrue(order);
MediaLibPageHelper helper = new MediaLibPageHelper(mediaLib);
Assert.assertTrue(helper.isOrder());
}
@Test
public void photoList() {
System.out.println("List of photos test");
log.logp(INFO, getClass().getName(), "photoList", "List of photos test");
MediaLib mediaLib = PageFactory.initElements(context.getDriver(), MediaLib.class);
int elementNumber = 0;
String preview = mediaLib.getItemImageName(elementNumber);
mediaLib.clickItemImage(elementNumber);
System.out.println(preview);
AlbumPage albumPage = PageFactory.initElements(context.getDriver(), AlbumPage.class);
AlbumPageHelper helper = new AlbumPageHelper(albumPage);
boolean containsPreview = false;
for (int i = 0; i < albumPage.getImagesCount(); i++) {
String previewCur = albumPage.getImageName(i);
if(preview.equals(previewCur)) {
containsPreview = true;
System.out.println(previewCur);
}
}
Assert.assertTrue(containsPreview);
Assert.assertTrue(helper.containsPreview(preview));
}
@Test
public void photosView() throws InterruptedException {
System.out.println("View of photos test");
log.logp(INFO, getClass().getName(), "photosView", "View of photos test");
MediaLib mediaLib = PageFactory.initElements(context.getDriver(), MediaLib.class);
mediaLib.clickItemImage(0);
AlbumPage albumPage = PageFactory.initElements(context.getDriver(), AlbumPage.class);
albumPage.clickPhotoLink(0);
Thread.sleep(2000);
AlbumPageHelper helper = new AlbumPageHelper(albumPage);
helper.clickPhotoLink(0);
int elementNumber = 1;
albumPage.clickPhotoPopup(elementNumber);
Assert.assertTrue(albumPage.isSelectedPhoto(elementNumber));
Assert.assertTrue(helper.isSelectedPhoto(elementNumber));
}
@Test
public void videoList() throws ParseException, InterruptedException {
System.out.println("List of video test");
public void videoList() throws ParseException {
log.logp(INFO, getClass().getName(), "videoList", "List of video test");
MediaLib mediaLib = PageFactory.initElements(context.getDriver(), MediaLib.class);
mediaLib.clickVideoFilter();
// Thread.sleep(1000);
MediaLibPageHelper helper = new MediaLibPageHelper(mediaLib);
boolean order = true;
DateFormat format = new SimpleDateFormat("yyyy.M.d H:m");
Date datePrev = format.parse(mediaLib.getDateOfItem(0));
for (int i = 1; i < mediaLib.getItemsCount(); i++) {
Date dateCur = format.parse(mediaLib.getDateOfItem(i));
System.out.println(dateCur);
if(dateCur.after(datePrev)) {
order = false;
break;
}
}
Assert.assertTrue(order);
Assert.assertTrue(helper.isOrder());
}
@Test
public void videoPage () throws InterruptedException {
System.out.println("Page with video test");
public void videoPage () {
log.logp(INFO, getClass().getName(), "videoPage", "Page with video test");
MediaLib mediaLibPhoto = PageFactory.initElements(context.getDriver(), MediaLib.class);
mediaLibPhoto.clickVideoFilter();
MediaLib mediaLibVideo = PageFactory.initElements(context.getDriver(), MediaLib.class);
// Thread.sleep(3000);
int elementNumber = 0;
String title = mediaLibVideo.getItemTitle(elementNumber);
mediaLibVideo.clickItem(elementNumber);
mediaLibVideo.clickItem(0);
VideoPage videoPage = PageFactory.initElements(context.getDriver(), VideoPage.class);
Assert.assertTrue(videoPage.getVideoTitle().equals(title));
Assert.assertTrue(videoPage.isVideoPresent());
}

View File

@ -9,10 +9,14 @@ import org.openqa.selenium.Dimension;
import org.openqa.selenium.support.PageFactory;
import java.util.ArrayList;
import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
public class NavigationTests {
private final static String APP_URL = "http://www.gazprom.ru/";
private static java.util.logging.Logger log = Logger.getLogger(NavigationTests.class.getName());
private static Context context;
@ -32,78 +36,69 @@ public class NavigationTests {
@Test
public void topMenuTest() {
System.out.println("Top menu test");
log.logp(INFO, getClass().getName(), "topMenuTest", "Top menu test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
int elementNumber = 2;
String title = page.getTitleMenuElement(elementNumber);
page.clickMenuElement(elementNumber);
page.clickMenuElementPress();
PressPage pressPage = PageFactory.initElements(context.getDriver(), PressPage.class);
Assert.assertTrue(pressPage.getTitle().contains(title));
Assert.assertTrue(pressPage.isNewsPresent());
}
@Test
public void subMenu(){
System.out.println("Sub menu test");
log.logp(INFO, getClass().getName(), "subMenu", "Sub menu test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickMenuElement(0);
page.clickMenuElementPress();
PressPage pressPage = PageFactory.initElements(context.getDriver(), PressPage.class);
int elementNumber = 1;
String title = pressPage.getTitleMenuElement(elementNumber);
pressPage.clickMenuElement(elementNumber);
pressPage.clickMenuElementMedia();
MediaLib mediaLib = PageFactory.initElements(context.getDriver(), MediaLib.class);
Assert.assertTrue(mediaLib.getTitle().contains(title));
Assert.assertTrue(mediaLib.isMediaListPresent());
}
@Test
public void hyperlinks(){
System.out.println("Hyperlinks test");
log.logp(INFO, getClass().getName(), "hyperlinks", "Hyperlinks test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickMenuElement(0);
page.clickMenuElementAbout();
AboutPage aboutPage = PageFactory.initElements(context.getDriver(), AboutPage.class);
int elementNumber = 0;
String title = aboutPage.getTextHyperlinksElement(elementNumber);
aboutPage.clickHyperlinksElement(elementNumber);
aboutPage.clickHyperlinksMiningElement();
MiningPage miningPage = PageFactory.initElements(context.getDriver(), MiningPage.class);
Assert.assertTrue(miningPage.getTitle().toLowerCase().contains(title));
Assert.assertTrue(miningPage.isMainContentPresent());
}
@Test
public void sideMenu() {
System.out.println("Side menu test");
log.logp(INFO, getClass().getName(), "sideMenu", "Side menu test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickLayButton();
int elementNumber = 3;
String title = page.getTitleLayMenuElement(elementNumber);
page.clickLayMenuElement(elementNumber);
page.clickMarketingLayMenuElement();
MarketingPage marketingPage = PageFactory.initElements(context.getDriver(), MarketingPage.class);
Assert.assertTrue(marketingPage.getTitle().contains(title));
Assert.assertTrue(marketingPage.isMainContentPresent());
}
@Test
public void externalLinks() throws InterruptedException {
System.out.println("External links test");
public void externalLinks() {
log.logp(INFO, getClass().getName(), "externalLinks", "External links test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickExternalSitesBtn();
int elementNumber = 0;
String title = page.getTitleExternalLink(elementNumber);
page.clickExternalLink(elementNumber);
page.clickExternalLink(0);
ArrayList<String> tabs2 = new ArrayList<String> (context.getDriver().getWindowHandles());
context.getDriver().switchTo().window(tabs2.get(1));

View File

@ -0,0 +1,68 @@
package PageHelpers;
import Pages.AlbumPage;
import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
public class AlbumPageHelper {
private static java.util.logging.Logger log = Logger.getLogger(SearchResultsPageHelper.class.getName());
private AlbumPage page;
public AlbumPageHelper(AlbumPage page){
this.page = page;
}
public boolean containsPreview(String preview) {
boolean containsPreview = false;
for (int i = 0; i < page.getImagesCount(); i++) {
String previewCur = page.getImageName(i);
if(preview.equals(previewCur)) {
containsPreview = true;
}
}
return containsPreview;
}
public boolean isSelectedPhoto(int elementNumber) throws InterruptedException {
int timeout = 10;
boolean isSelected = false;
for(int i=0;i<timeout;i++){
page.clickPhotoPopup();
isSelected = page.isSelectedPhoto(elementNumber);
if(isSelected) {
log.logp(INFO, getClass().getName(), "pagination", "time: " + i*200);
break;
}
Thread.sleep(200);
}
return isSelected;
}
private int tryLimit = 10;
public void clickPhotoLink(int elementNumber) {
boolean breakIt = true;
int attempt =0;
while (true&&attempt<tryLimit) {
attempt++;
breakIt = true;
try {
page.clickPhotoLink(elementNumber);
} catch (Exception e) {
log.logp(WARNING, getClass().getName(), "clickPhotoLink","Exception in clickPhotoLink method");
breakIt = false;
}
if (breakIt) {
break;
}
}
}
}

View File

@ -0,0 +1,81 @@
package PageHelpers;
import Pages.CalculatorPage;
import org.openqa.selenium.WebElement;
import java.util.logging.Logger;
import static java.lang.Math.round;
import static java.util.logging.Level.WARNING;
public class CalculatorPageHelper {
private static Logger log = Logger.getLogger(CalculatorPageHelper.class.getName());
private CalculatorPage page;
public CalculatorPageHelper(CalculatorPage page){
this.page = page;
}
public boolean isCalculationRight( ){
double startPrice = page.getStartPrice();
double endPrice = page.getEndPrice();
double reInvPrice = page.getReInvPrice();
double changePrice = page.getChangePrice();
double changePriceRe = page.getChangePriceRe();
double income = page.getIncome();
return isIncomeRight(startPrice,endPrice,income)
&&isChangePriceRight(startPrice,changePrice,income)
&&isChangePriceReRight(startPrice,changePriceRe,reInvPrice);
}
private boolean isIncomeRight( double startPrice,double endPrice, double income){
return ((double) round((endPrice-startPrice) * 100))/100==income;
}
private boolean isChangePriceRight( double startPrice,double changePrice, double income){
return ((double) round(income/startPrice * 100*100))/100==changePrice;
}
private boolean isChangePriceReRight( double startPrice,double changePriceRe, double reInvPrice){
return ((double) round((reInvPrice-startPrice)/startPrice*100 *100))/100 ==changePriceRe;
}
public void waitAndInsertFromDate(String date){
waitForInputsPresent(page.getFromDateInput(),date);
}
private int tryLimit = 10;
public void waitForInputsPresent(WebElement element,String text){
boolean breakIt = true;
int attempt = 0;
while (true&&attempt<tryLimit) {
attempt++;
breakIt = true;
try {
element.clear();
element.sendKeys(text);
} catch (Exception e) {
log.logp(WARNING, getClass().getName(), "waitForInputsPresent","Exception in waitForInputsPresent method. Element: "+element);
breakIt = false;
}
if (breakIt) {
break;
}
}
}
public void waitAndInsertToDate(String date){
waitForInputsPresent(page.getToDateInput(),date);
}
public void waitAndInsertAmount(String amount){
waitForInputsPresent(page.getAmountInput(),amount);
}
}

View File

@ -0,0 +1,37 @@
package PageHelpers;
import Pages.EventsPage;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.logging.Logger;
public class EventsPageHelper {
private static java.util.logging.Logger log = Logger.getLogger(SearchResultsPageHelper.class.getName());
private EventsPage page;
public EventsPageHelper(EventsPage page){
this.page = page;
}
public boolean isSuitable(int month) throws ParseException {
boolean suitable = true;
DateFormat format = new SimpleDateFormat("d MMMM, hh:mm");
Calendar calendar = new GregorianCalendar();
for (int i = 0; i < page.getResultsCount(); i++) {
Date dateCur = format.parse(page.getDateOfResult(i));
calendar.setTime(dateCur);
if(calendar.get(Calendar.MONTH)!=month){
suitable = false;
break;
}
}
return suitable;
}
}

View File

@ -0,0 +1,19 @@
package PageHelpers;
import Pages.FeedbackPage;
import java.util.logging.Logger;
public class FeedbackPageHelper {
private static java.util.logging.Logger log = Logger.getLogger(SearchResultsPageHelper.class.getName());
private FeedbackPage page;
public FeedbackPageHelper(FeedbackPage page){
this.page = page;
}
String successMessage = "Ваше сообщение отправлено.";
public boolean isReceiveSuccess(){
String output = page.getOutput();
return output.equals(successMessage);
}
}

View File

@ -0,0 +1,50 @@
package PageHelpers;
import Pages.MediaLib;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Logger;
import static java.util.logging.Level.WARNING;
public class MediaLibPageHelper {
private static java.util.logging.Logger log = Logger.getLogger(SearchResultsPageHelper.class.getName());
private MediaLib page;
public MediaLibPageHelper(MediaLib page){
this.page = page;
}
public boolean isOrder() throws ParseException {
boolean order = true;
DateFormat format = new SimpleDateFormat("yyyy.M.d H:m");
Date datePrev = format.parse(page.getDateOfItem(0));
for (int i = 1; i < page.getItemsCount(); i++) {
Date dateCur = format.parse(page.getDateOfItem(i));
if(dateCur.after(datePrev)) {
log.logp(WARNING, getClass().getName(), "albumList", "Date current: '"+dateCur +"', Date previous: '"+datePrev+"'");
order = false;
break;
}
datePrev = dateCur;
}
return order;
}
public boolean order() throws ParseException {
boolean order = true;
DateFormat format = new SimpleDateFormat("yyyy.M.d H:m");
Date datePrev = format.parse(page.getDateOfItem(0));
for (int i = 1; i < page.getItemsCount(); i++) {
Date dateCur = format.parse(page.getDateOfItem(i));
if(dateCur.after(datePrev)) {
order = false;
break;
}
}
return order;
}
}

View File

@ -0,0 +1,49 @@
package PageHelpers;
import Pages.PurchasesPage;
import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
public class PurchasePageHelper {
private static java.util.logging.Logger log = Logger.getLogger(SearchResultsPageHelper.class.getName());
private PurchasesPage page;
public PurchasePageHelper(PurchasesPage page){
this.page = page;
}
private int tryLimit = 10;
public boolean waitAndCheckPageSelection(int pageNumber){
boolean breakIt = true;
boolean turn = false;
int attempt = 0;
while (true&&attempt<tryLimit) {
attempt++;
breakIt = true;
try {
int timeout = 10;
for(int i=0;i<timeout;i++){
turn = page.isSelectedPage(pageNumber);
if(turn) {
log.logp(INFO, getClass().getName(), "pagination", "time: " + i*200);
break;
}
Thread.sleep(200);
}
} catch (Exception e) {
log.logp(WARNING, getClass().getName(), "waitAndCheckPageSelection","Exception in waitAndCheckPageSelection method");
breakIt = false;
}
if (breakIt) {
break;
}
}
return turn;
}
}

View File

@ -0,0 +1,137 @@
package PageHelpers;
import Pages.SearchResultsPage;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
public class SearchResultsPageHelper {
private static java.util.logging.Logger log = Logger.getLogger(SearchResultsPageHelper.class.getName());
private SearchResultsPage page;
public SearchResultsPageHelper(SearchResultsPage page){
this.page = page;
}
public boolean isSuitable(String queryString) throws ParseException {
boolean order = true;
DateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
Date datePrev = new Date();
boolean suitable = true;
for (int i = 0; i < page.getItemsCount(); i++) {
Date dateCur = format.parse(waitAngGetItemsDate(i));
if(dateCur.after(datePrev)) {
log.logp(WARNING, getClass().getName(), "simpleSearch", "Date current: '"+dateCur +"', Date previous: '"+datePrev+"'");
order = false;
break;
}
if(!waitAndGetItemsText(i).toLowerCase().contains(queryString)){
log.logp(WARNING, getClass().getName(), "simpleSearch", "'" + waitAndGetItemsText(i)+"' is not suitable for '"+queryString+"'");
suitable = false;
break;
}
datePrev= dateCur;
}
return order&&suitable;
}
public boolean isSuitable(String queryString,int year) throws InterruptedException, ParseException {
boolean order = true;
DateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
Calendar calendar = new GregorianCalendar();
Date datePrev = new Date();
boolean suitable = true;
for (int i = 0; i < page.getItemsCount(); i++) {
Date dateCur = new Date();
int timeout = 10;
boolean isSuitableElement = false;
for(int k=0;k<timeout;k++){
dateCur = format.parse(waitAngGetItemsDate(i));
calendar.setTime(dateCur);
isSuitableElement = matchedByYearAndQuery(waitAndGetItemsText(i),queryString,calendar,year);
if(isSuitableElement) {
log.logp(INFO, getClass().getName(), "filteredSearch", "time: " + k*200);
break;
}
Thread.sleep(200);
}
if(dateCur.after(datePrev)) {
log.logp(WARNING, getClass().getName(), "filteredSearch", "Date current: '"+dateCur +"', Date previous: '"+datePrev+"'");
order = false;
break;
}
if(!isSuitableElement){
log.logp(WARNING, getClass().getName(), "filteredSearch",
"'" + waitAndGetItemsText(i)+"' is not suitable for '"+queryString+"' or '"+calendar.get(Calendar.YEAR)+"' != '"+year+"'");
suitable = false;
break;
}
}
return order&&suitable;
}
private boolean matchedByYearAndQuery(String itemText, String query, Calendar calendar, int year){
return itemText.toLowerCase().contains(query)&&calendar.get(Calendar.YEAR)==year;
}
private int tryLimit = 10;
public String waitAndGetItemsText(int itemNumber){
String text="";
boolean breakIt = true;
int attempt =0;
while (true&&attempt<tryLimit) {
attempt++;
breakIt = true;
try {
text=page.getItemsText(itemNumber);
} catch (Exception e) {
log.logp(WARNING, getClass().getName(), "waitAndGetItemsText","Exception in waitAndGetItemsText method");
breakIt = false;
}
if (breakIt) {
break;
}
}
return text;
}
public String waitAngGetItemsDate(int itemNumber){
String date="";
boolean breakIt = true;
int attempt =0;
while (true&&attempt<tryLimit) {
attempt++;
breakIt = true;
try {
date=page.getItemsDate(itemNumber);
} catch (Exception e) {
log.logp(WARNING, getClass().getName(), "waitAngGetItemsDate","Exception in waitAngGetItemsDate method");
breakIt = false;
}
if (breakIt) {
break;
}
}
return date;
}
}

View File

@ -0,0 +1,49 @@
package PageHelpers;
import Pages.SubsidiariesPage;
import java.util.logging.Logger;
import static java.util.logging.Level.WARNING;
public class SubsidiariesPageHelper {
private static java.util.logging.Logger log = Logger.getLogger(SearchResultsPageHelper.class.getName());
private SubsidiariesPage page;
public SubsidiariesPageHelper(SubsidiariesPage page){
this.page = page;
}
public boolean isOrder() {
boolean order = true;
for (int i = 0; i < page.getItemsPercent100Count(); i++) {
float percent = page.getPartOfItemPercent100(i);
if(percent!= 100.0f){
log.logp(WARNING, getClass().getName(), "sorting", "'" + percent+"' is not '100'");
order = false;
break;
}
}
for (int i = 0; i < page.getItemsPercentMore50Count(); i++) {
float percent = page.getPartOfItemPercentMore50(i);
if(percent<= 50.0f){
log.logp(WARNING, getClass().getName(), "sorting", "'" + percent+"' is not more than '50'");
order = false;
break;
}
}
for (int i = 0; i < page.getItemsPercentLess50Count(); i++) {
float percent = page.getPartOfItemPercentLess50(i);
if(percent> 50.0f){
log.logp(WARNING, getClass().getName(), "sorting", "'" + percent+"' is not less than '50'");
order = false;
break;
}
}
return order;
}
}

View File

@ -3,7 +3,6 @@ package Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.List;
@ -16,20 +15,19 @@ public class AboutPage {
@FindBy(css = ".subnavigation li")
private List<WebElement> subMenuElements;
private static int subsidariesPageMenuElementNumber = 4;
private static int miningHyperLinkNumber = 0;
public AboutPage(WebDriver driver) {
this.driver = driver;
}
public void clickHyperlinksElement(int elementNumber){
hyperlinkElements.get(elementNumber).click();
public void clickHyperlinksMiningElement(){
hyperlinkElements.get(miningHyperLinkNumber).click();
}
public String getTextHyperlinksElement(int elementNumber){
return hyperlinkElements.get(elementNumber).getText();
}
public void clickMenuElement(int elementNumber){
subMenuElements.get(elementNumber).click();
public void clickMenuElementSubsidaries(){
subMenuElements.get(subsidariesPageMenuElementNumber).click();
}
}

View File

@ -1,25 +1,36 @@
package Pages;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.List;
import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
public class AlbumPage {
private WebDriverWait wait;
private WebDriver driver;
private static java.util.logging.Logger log = Logger.getLogger(AlbumPage.class.getName());
@FindBy(css = ".media__list .media__item img")
private List<WebElement> albumImages;
@FindBy(css = ".media__popup__thumbs .media__popup__thumb img")
private List<WebElement> photosPopupImg;
@FindBy(css = ".media__popup__thumbs .media__popup__thumb")
private List<WebElement> photosPopup;
@FindBy(css = ".media__popup__thumbs .media__popup__thumb:not(.media__popup__thumb--selected)")
private WebElement notSelectedThump;
public AlbumPage(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver,30,500);
@ -39,13 +50,20 @@ public class AlbumPage {
}
public void clickPhotoLink(int elementNumber) {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("media__item")));
wait.until(ExpectedConditions.visibilityOf(albumImages.get(elementNumber)));
albumImages.get(elementNumber).click();
}
public void clickPhotoPopup(int elementNumber) {
wait.until(ExpectedConditions.visibilityOfAllElements(photosPopup.get(elementNumber)));
photosPopup.get(elementNumber).click();
public void clickPhotoPopup() {
try{
notSelectedThump.click();
}catch (WebDriverException e){
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click()", notSelectedThump);
log.logp(INFO, getClass().getName(), "clickPhotoPopup", "Exception in clickPhotoPopup method");
}
}
public boolean isSelectedPhoto(int elementNumber){

View File

@ -57,9 +57,11 @@ public class CalculatorPage {
}
public void switchToCalcFrame(){
wait.until(ExpectedConditions.visibilityOfAllElements(ruCalcFrame));
wait.until(ExpectedConditions.visibilityOf(ruCalcFrame));
driver.switchTo().frame(ruCalcFrame);
wait.until(ExpectedConditions.visibilityOf(chartFrame));
driver.switchTo().frame(chartFrame);
}
public void clickCalcBtn(){
@ -68,63 +70,49 @@ public class CalculatorPage {
public double getStartPrice(){
wait.until(ExpectedConditions.visibilityOfAllElements(startPrice));
String tmp = startPrice.getText();
tmp = tmp.substring(0,tmp.lastIndexOf(" ")+1);
return Double.parseDouble(tmp.replace(",",".").replace(" ",""));
}
public double getEndPrice(){
wait.until(ExpectedConditions.visibilityOfAllElements(endPrice));
String tmp = endPrice.getText();
tmp = tmp.substring(0,tmp.lastIndexOf(" ")+1);
return Double.parseDouble(tmp.replace(",",".").replace(" ",""));
}
public double getReInvPrice(){
wait.until(ExpectedConditions.visibilityOfAllElements(reInvPrice));
String tmp = reInvPrice.getText();
tmp = tmp.substring(0,tmp.lastIndexOf(" ")+1);
return Double.parseDouble(tmp.replace(",",".").replace(" ",""));
}
public double getChangePrice(){
wait.until(ExpectedConditions.visibilityOfAllElements(changePrice));
String tmp = changePrice.getText();
tmp = tmp.substring(0,tmp.lastIndexOf("%"));
return Double.parseDouble(tmp.replace(",",".").replace(" ",""));
}
public double getChangePriceRe(){
wait.until(ExpectedConditions.visibilityOfAllElements(changePriceRe));
String tmp = changePriceRe.getText();
tmp = tmp.substring(0,tmp.lastIndexOf("%"));
return Double.parseDouble(tmp.replace(",",".").replace(" ",""));
}
public double getIncome(){
wait.until(ExpectedConditions.visibilityOfAllElements(income));
String tmp = income.getText();
return Double.parseDouble(tmp.replace(",",".").replace(" ",""));
}
public void insertFromDate(String text){
wait.until(ExpectedConditions.visibilityOfAllElements(fromDateInput));
fromDateInput.clear();
fromDateInput.sendKeys(text);
public WebElement getFromDateInput() {
return fromDateInput;
}
public void insertToDate(String text){
wait.until(ExpectedConditions.visibilityOfAllElements(toDateInput));
toDateInput.clear();
toDateInput.sendKeys(text);
public WebElement getToDateInput() {
return toDateInput;
}
public void insertAmount(String text){
wait.until(ExpectedConditions.visibilityOfAllElements(amountInput));
amountInput.clear();
amountInput.sendKeys(text);
public WebElement getAmountInput() {
return amountInput;
}
}

View File

@ -23,11 +23,11 @@ public class EventsPage {
this.driver = driver;
}
public void selectYear(int itemNumber){
public void selectYearByPosition(int itemNumber){
yearsFilter.get(itemNumber).click();
}
public void selectMonth(int itemNumber){
public void selectMonthByPosition(int itemNumber){
monthFilter.get(itemNumber).click();
}

View File

@ -29,7 +29,4 @@ public class ForShareholders {
downloadLinks.get(elementNumber).click();
}
public void clickMenuElement(int elementNumber){
subMenuElements.get(elementNumber).click();
}
}

View File

@ -37,31 +37,35 @@ public class MainPage {
@FindBy(css = ".additional_top_navigation a")
private List<WebElement> additionalMenu;
private static int shareholdersPageMenuElementNumber = 1;
private static int aboutPageMenuElementNumber = 0;
private static int pressPageMenuElementNumber = 2;
private static int purchasePageMenuElementNumber = 1;
private static int marketingPageMenuElementNumber = 3;
public MainPage(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver,30,500);
}
public void clickMenuElement(int elementNumber){
wait.until(ExpectedConditions.visibilityOfAllElements(menuElements));
menuElements.get(elementNumber).click();
public void clickMenuElementShareholder(){
wait.until(ExpectedConditions.visibilityOfAllElements(menuElements.get(shareholdersPageMenuElementNumber)));
menuElements.get(shareholdersPageMenuElementNumber).click();
}
public String getTitleMenuElement(int elementNumber){
wait.until(ExpectedConditions.visibilityOfAllElements(menuElements));
return menuElements.get(elementNumber).getText();
public void clickMenuElementAbout(){
wait.until(ExpectedConditions.visibilityOfAllElements(menuElements.get(shareholdersPageMenuElementNumber)));
menuElements.get(aboutPageMenuElementNumber).click();
}
public void clickMenuElementPress(){
wait.until(ExpectedConditions.visibilityOfAllElements(menuElements.get(shareholdersPageMenuElementNumber)));
menuElements.get(pressPageMenuElementNumber).click();
}
public void clickLayButton(){
layButton.click();
}
public void clickLayMenuElement(int elementNumber){
layMenuElements.get(elementNumber).click();
}
public String getTitleLayMenuElement(int elementNumber){
return layMenuElements.get(elementNumber).getText();
public void clickMarketingLayMenuElement(){
layMenuElements.get(marketingPageMenuElementNumber).click();
}
public void clickExternalSitesBtn(){
@ -84,6 +88,7 @@ public class MainPage {
}
public void insertSearchText(String text){
wait.until(ExpectedConditions.visibilityOf(searchField));
searchField.sendKeys(text);
}
@ -91,7 +96,7 @@ public class MainPage {
searchField.sendKeys(Keys.RETURN);
}
public void clickAdditionalMenuElement(int elementNumber){
additionalMenu.get(elementNumber).click();
public void clickAdditionalMenuElementPurchase(){
additionalMenu.get(purchasePageMenuElementNumber).click();
}
}

View File

@ -1,18 +1,21 @@
package Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
public class MarketingPage {
private WebDriver driver;
@FindBy(css = ".main-content")
private WebElement mainContentElement;
public MarketingPage(WebDriver driver) {
this.driver = driver;
}
public String getTitle(){
return driver.getTitle();
public boolean isMainContentPresent(){
return mainContentElement.isDisplayed();
}
}

View File

@ -1,6 +1,5 @@
package Pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -37,15 +36,16 @@ public class MediaLib {
@FindBy(css = ".h1--semi-margin-bottom")
private WebElement albumTitle;
@FindBy(css = ".media__list ")
private WebElement mediaListElement;
private static int socialLinkTwitter = 2;
public MediaLib(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver,10,500);
}
public String getTitle(){
return driver.getTitle();
}
public String getDateOfItem(int elementNumber){
wait.until(ExpectedConditions.visibilityOfAllElements(itemsDates.get(elementNumber)));
return itemsDates.get(elementNumber).getAttribute("value");
@ -56,11 +56,12 @@ public class MediaLib {
}
public void clickItemImage(int elementNumber){
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("media__item")));
wait.until(ExpectedConditions.visibilityOf( albumsImages.get(elementNumber)));
albumsImages.get(elementNumber).click();
}
public String getItemImageName(int elementNumber){
wait.until(ExpectedConditions.visibilityOf(albumsImages.get(elementNumber)));
String preview = albumsImages.get(elementNumber).getAttribute("src");
preview = preview.substring(preview.lastIndexOf("_")+1);
@ -71,25 +72,26 @@ public class MediaLib {
contentFilter.get(0).click();
}
public String getItemTitle(int elementNumber){
wait.until(ExpectedConditions.visibilityOfAllElements(itemsTitles.get(elementNumber)));
return itemsTitles.get(elementNumber).getText();
}
public void clickItem(int elementNumber){
itemsLinks.get(elementNumber).click();
}
public void selectMonth(int itemNumber){
public void selectMonthByPosition(int itemNumber){
monthFilter.get(itemNumber).click();
}
public void clickSocialLink(int itemNumber){
socialLinks.get(itemNumber).click();
public void clickSocialLinkTwitter(){
socialLinks.get(socialLinkTwitter).click();
}
public String getAlbumTitle(){
return albumTitle.getText();
public void switchToTwitterPopup(){
for (String winHandle : driver.getWindowHandles()) {
driver.switchTo().window(winHandle);
}
}
public boolean isMediaListPresent(){
return mediaListElement.isDisplayed();
}
}

View File

@ -1,18 +1,21 @@
package Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
public class MiningPage {
private WebDriver driver;
@FindBy(css = ".main-content")
private WebElement mainContentElement;
public MiningPage(WebDriver driver) {
this.driver = driver;
}
public String getTitle(){
return driver.getTitle();
public boolean isMainContentPresent(){
return mainContentElement.isDisplayed();
}
}

View File

@ -15,25 +15,33 @@ public class PressPage {
@FindBy(css = ".subnavigation li")
private List<WebElement> menuElements;
@FindBy(css = ".news-list")
private WebElement newsElement;
private static int journalPageMenuElementNumber = 2;
private static int mediaPageMenuElementNumber = 1;
private static int eventPageMenuElementNumber = 0;
public PressPage(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver,30,500);
}
public String getTitle(){
return driver.getTitle();
}
public void clickMenuElement(int elementNumber){
public void clickMenuElementJournal(){
wait.until(ExpectedConditions.visibilityOfAllElements(menuElements));
menuElements.get(elementNumber).click();
menuElements.get(journalPageMenuElementNumber).click();
}
public String getTitleMenuElement(int elementNumber){
public void clickMenuElementEventpage(){
wait.until(ExpectedConditions.visibilityOfAllElements(menuElements));
return menuElements.get(elementNumber).getText();
menuElements.get(eventPageMenuElementNumber).click();
}
public void clickMenuElementMedia(){
wait.until(ExpectedConditions.visibilityOfAllElements(menuElements));
menuElements.get(mediaPageMenuElementNumber).click();
}
public boolean isNewsPresent(){
return newsElement.isDisplayed();
}
}

View File

@ -1,10 +1,8 @@
package Pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.List;
@ -25,21 +23,19 @@ public class PurchasesPage {
@FindBy(css = ".dataTables_paginate span")
private List<WebElement> paginationElements;
private static int feedbackMenuElementNumber = 10;
private static int inWorkPurchaseMenuElementNumber = 2;
public PurchasesPage(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver,30,500);
}
public void clickMenuItem(int itemNumber){
menuElements.get(itemNumber).click();
public void clickMenuItemInWork(){
menuElements.get(inWorkPurchaseMenuElementNumber).click();
}
public String getPurchaseNumber(int itemNumber){
return purchasesNumbers.get(itemNumber).getText();
}
public int getItemsCount(){
return searchResults.size();
public void clickMenuItemFeedback(){
menuElements.get(feedbackMenuElementNumber).click();
}
public void clickPage(int pageNumber){
@ -47,6 +43,7 @@ public class PurchasesPage {
}
public boolean isSelectedPage(int pageNumber){
return paginationElements.get(pageNumber).getAttribute("class").equals("paginate_active");
boolean isSelect = paginationElements.get(pageNumber).getAttribute("class").equals("paginate_active");
return isSelect;
}
}

View File

@ -3,7 +3,6 @@ package Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.List;
@ -31,6 +30,7 @@ public class SearchResultsPage {
}
public String getItemsText(int itemNumber){
return searchResultsTexts.get(itemNumber).getText();
}
@ -39,16 +39,18 @@ public class SearchResultsPage {
}
public int getItemsCount() {
int size = searchResultsTexts.size();
System.out.println(size);
return size;
wait.until(ExpectedConditions.visibilityOfAllElements(searchResultsTexts));
return searchResultsTexts.size();
}
public void setFilterOn(){
filterOn.click();
}
public void selectYear(int itemNumber){
public void selectYearByPosition(int itemNumber){
yearsFilter.get(itemNumber).click();
}
}

View File

@ -3,7 +3,6 @@ package Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.List;

View File

@ -20,19 +20,7 @@ public class TwitterSharingPopup {
this.driver = driver;
}
public void insertUsername(String username){
usernameInput.sendKeys(username);
}
public void insertPassword(String password){
passInput.sendKeys(password);
}
public void clickSubmit(){
submitBtn.click();
}
public boolean submitBtnPresent(){
public boolean isSubmitBtnPresent(){
return submitBtn.isDisplayed();
}
}

View File

@ -3,7 +3,6 @@ package Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.List;
@ -20,14 +19,15 @@ public class VideoPage {
@FindBy(css = ".media_filter h1")
private WebElement videoTitle;
@FindBy(css = ".media__iframe")
private WebElement videoElement;
public VideoPage(WebDriver driver) {
this.driver = driver;
}
public String getTitle(){
return driver.getTitle();
public boolean isVideoPresent(){
return videoElement.isDisplayed();
}
public String getVideoTitle(){
return videoTitle.getText();
}
}

View File

@ -16,12 +16,12 @@ public class ChromeContext extends Context {
protected void createDriver() {
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("plugins.always_open_pdf_externally", true);
// tmpPath = System.getProperty("java.io.tmpdir");
tmpPath = System.getProperty("user.dir") + "/src/main/resources/downloads/";
prefs.put("download.default_directory", tmpPath);
prefs.put("plugins.always_open_pdf_externally", true);
options.setExperimentalOption("prefs",prefs);
driver = new ChromeDriver(options);