diff --git a/Semenova/.gitignore b/Semenova/.gitignore new file mode 100644 index 0000000..3bac491 --- /dev/null +++ b/Semenova/.gitignore @@ -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/ \ No newline at end of file diff --git a/Semenova/.gitkeep b/Semenova/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Semenova/README.md b/Semenova/README.md new file mode 100644 index 0000000..635e81b --- /dev/null +++ b/Semenova/README.md @@ -0,0 +1,2 @@ +Selenium WebDriver example project + diff --git a/Semenova/src/test/java/CalculatorTest.java b/Semenova/src/test/java/CalculatorTest.java index 3f9220b..a392b91 100644 --- a/Semenova/src/test/java/CalculatorTest.java +++ b/Semenova/src/test/java/CalculatorTest.java @@ -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()); } } diff --git a/Semenova/src/test/java/DocumentTests.java b/Semenova/src/test/java/DocumentTests.java index 6cf9f1c..ece2d90 100644 --- a/Semenova/src/test/java/DocumentTests.java +++ b/Semenova/src/test/java/DocumentTests.java @@ -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); + log.logp(INFO, getClass().getName(), "downloadDocs", "Path: "+tmpPath +fileName); + + checkDownload(fileName,100,500); + } + + private void checkDownload(String fileName,int timeout, int period) throws InterruptedException { + File f = new File(tmpPath +fileName); - System.out.println(tmpPath + fileName); - - int timeout=0; - while(!f.exists()&&timeout<100){ - Thread.sleep(500); - timeout++; + int time=0; + while(!f.exists()&&time 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 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(turn&&!found); + Assert.assertTrue(helper.waitAndCheckPageSelection(pageNumber)); } - - } diff --git a/Semenova/src/test/java/MultimediaTests.java b/Semenova/src/test/java/MultimediaTests.java index b26e298..1864898 100644 --- a/Semenova/src/test/java/MultimediaTests.java +++ b/Semenova/src/test/java/MultimediaTests.java @@ -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()); } diff --git a/Semenova/src/test/java/NavigationTests.java b/Semenova/src/test/java/NavigationTests.java index 0b05b49..7c57b05 100644 --- a/Semenova/src/test/java/NavigationTests.java +++ b/Semenova/src/test/java/NavigationTests.java @@ -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 tabs2 = new ArrayList (context.getDriver().getWindowHandles()); context.getDriver().switchTo().window(tabs2.get(1)); diff --git a/Semenova/src/test/java/PageHelpers/AlbumPageHelper.java b/Semenova/src/test/java/PageHelpers/AlbumPageHelper.java new file mode 100644 index 0000000..55c1de6 --- /dev/null +++ b/Semenova/src/test/java/PageHelpers/AlbumPageHelper.java @@ -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 50.0f){ + log.logp(WARNING, getClass().getName(), "sorting", "'" + percent+"' is not less than '50'"); + order = false; + break; + } + } + return order; + + } +} diff --git a/Semenova/src/test/java/Pages/AboutPage.java b/Semenova/src/test/java/Pages/AboutPage.java index ece6a0b..bc02e93 100644 --- a/Semenova/src/test/java/Pages/AboutPage.java +++ b/Semenova/src/test/java/Pages/AboutPage.java @@ -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 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(); } } diff --git a/Semenova/src/test/java/Pages/AlbumPage.java b/Semenova/src/test/java/Pages/AlbumPage.java index 4fc3373..8d0bda2 100644 --- a/Semenova/src/test/java/Pages/AlbumPage.java +++ b/Semenova/src/test/java/Pages/AlbumPage.java @@ -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 albumImages; + @FindBy(css = ".media__popup__thumbs .media__popup__thumb img") + private List photosPopupImg; + @FindBy(css = ".media__popup__thumbs .media__popup__thumb") private List 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){ diff --git a/Semenova/src/test/java/Pages/CalculatorPage.java b/Semenova/src/test/java/Pages/CalculatorPage.java index 811280a..eaa2658 100644 --- a/Semenova/src/test/java/Pages/CalculatorPage.java +++ b/Semenova/src/test/java/Pages/CalculatorPage.java @@ -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; } - } diff --git a/Semenova/src/test/java/Pages/EventsPage.java b/Semenova/src/test/java/Pages/EventsPage.java index 0d39bc1..4bf9347 100644 --- a/Semenova/src/test/java/Pages/EventsPage.java +++ b/Semenova/src/test/java/Pages/EventsPage.java @@ -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(); } diff --git a/Semenova/src/test/java/Pages/ForShareholders.java b/Semenova/src/test/java/Pages/ForShareholders.java index 93b3254..c4b026c 100644 --- a/Semenova/src/test/java/Pages/ForShareholders.java +++ b/Semenova/src/test/java/Pages/ForShareholders.java @@ -29,7 +29,4 @@ public class ForShareholders { downloadLinks.get(elementNumber).click(); } - public void clickMenuElement(int elementNumber){ - subMenuElements.get(elementNumber).click(); - } } diff --git a/Semenova/src/test/java/Pages/MainPage.java b/Semenova/src/test/java/Pages/MainPage.java index ae23fa8..8e7f2a3 100644 --- a/Semenova/src/test/java/Pages/MainPage.java +++ b/Semenova/src/test/java/Pages/MainPage.java @@ -37,31 +37,35 @@ public class MainPage { @FindBy(css = ".additional_top_navigation a") private List 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(); } } diff --git a/Semenova/src/test/java/Pages/MarketingPage.java b/Semenova/src/test/java/Pages/MarketingPage.java index 79c8b71..29635b7 100644 --- a/Semenova/src/test/java/Pages/MarketingPage.java +++ b/Semenova/src/test/java/Pages/MarketingPage.java @@ -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(); } - } diff --git a/Semenova/src/test/java/Pages/MediaLib.java b/Semenova/src/test/java/Pages/MediaLib.java index 34b34ed..cae95a6 100644 --- a/Semenova/src/test/java/Pages/MediaLib.java +++ b/Semenova/src/test/java/Pages/MediaLib.java @@ -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(); + } } diff --git a/Semenova/src/test/java/Pages/MiningPage.java b/Semenova/src/test/java/Pages/MiningPage.java index 5465f3e..4357d89 100644 --- a/Semenova/src/test/java/Pages/MiningPage.java +++ b/Semenova/src/test/java/Pages/MiningPage.java @@ -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(); } - } diff --git a/Semenova/src/test/java/Pages/PressPage.java b/Semenova/src/test/java/Pages/PressPage.java index 7b68a39..2e4fab5 100644 --- a/Semenova/src/test/java/Pages/PressPage.java +++ b/Semenova/src/test/java/Pages/PressPage.java @@ -15,25 +15,33 @@ public class PressPage { @FindBy(css = ".subnavigation li") private List 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(); + } } diff --git a/Semenova/src/test/java/Pages/PurchasesPage.java b/Semenova/src/test/java/Pages/PurchasesPage.java index 0919da0..8fc0092 100644 --- a/Semenova/src/test/java/Pages/PurchasesPage.java +++ b/Semenova/src/test/java/Pages/PurchasesPage.java @@ -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 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; } } diff --git a/Semenova/src/test/java/Pages/SearchResultsPage.java b/Semenova/src/test/java/Pages/SearchResultsPage.java index a7fd310..d8a7a0f 100644 --- a/Semenova/src/test/java/Pages/SearchResultsPage.java +++ b/Semenova/src/test/java/Pages/SearchResultsPage.java @@ -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(); } @@ -38,17 +38,19 @@ public class SearchResultsPage { return searchResultsDates.get(itemNumber).getAttribute("value"); } - public int getItemsCount(){ + 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(); } + } diff --git a/Semenova/src/test/java/Pages/SubsidiariesPage.java b/Semenova/src/test/java/Pages/SubsidiariesPage.java index 8a42330..5685c08 100644 --- a/Semenova/src/test/java/Pages/SubsidiariesPage.java +++ b/Semenova/src/test/java/Pages/SubsidiariesPage.java @@ -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; diff --git a/Semenova/src/test/java/Pages/TwitterSharingPopup.java b/Semenova/src/test/java/Pages/TwitterSharingPopup.java index 5d3a3fa..e0ed237 100644 --- a/Semenova/src/test/java/Pages/TwitterSharingPopup.java +++ b/Semenova/src/test/java/Pages/TwitterSharingPopup.java @@ -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(); } } diff --git a/Semenova/src/test/java/Pages/VideoPage.java b/Semenova/src/test/java/Pages/VideoPage.java index 9bb015f..f8b86bb 100644 --- a/Semenova/src/test/java/Pages/VideoPage.java +++ b/Semenova/src/test/java/Pages/VideoPage.java @@ -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(); - } } diff --git a/Semenova/src/test/java/context/ChromeContext.java b/Semenova/src/test/java/context/ChromeContext.java index 71dc411..7c46e44 100644 --- a/Semenova/src/test/java/context/ChromeContext.java +++ b/Semenova/src/test/java/context/ChromeContext.java @@ -16,12 +16,12 @@ public class ChromeContext extends Context { protected void createDriver() { ChromeOptions options = new ChromeOptions(); Map prefs = new HashMap(); - 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);