Semenova #2

Closed
SemenovaMasha wants to merge 4 commits from Semenova into master
29 changed files with 1771 additions and 0 deletions
Showing only changes of commit 0deb6f91e2 - Show all commits

41
Semenova/pom.xml Normal file
View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>AutoTesting</groupId>
<artifactId>AutoTesting</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>4.0.4</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,5 @@
public class App {
public static void main(String[] args) {
}
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,64 @@
import Pages.CalculatorPage;
import context.ChromeContext;
import context.Context;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.support.PageFactory;
public class CalculatorTest {
private final static String APP_URL = "http://www.gazprom.ru/investors/stock/investor-tools/calc/";
private static Context context;
@Before
public void setup() {
context = new ChromeContext();
context.start();
context.getDriver().manage().window().setSize(new Dimension(1600, 900));
context.getDriver().get(APP_URL);
}
@After
public void quit() {
context.close();
}
@Test
public void countInvestor() throws InterruptedException {
System.out.println("Investor's count test");
Thread.sleep(1000);
CalculatorPage calculatorPage = PageFactory.initElements(context.getDriver(), CalculatorPage.class);
calculatorPage.switchToCalcFrame();
calculatorPage.insertFromDate("30.09.2011");
calculatorPage.insertToDate("01.02.2018");
calculatorPage.insertAmount("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);
}
}

View File

@ -0,0 +1,98 @@
import Pages.ForShareholders;
import Pages.JournalsPage;
import Pages.MainPage;
import Pages.PressPage;
import context.ChromeContext;
import context.Context;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.support.PageFactory;
import java.io.File;
public class DocumentTests {
private final static String APP_URL = "http://www.gazprom.ru/";
private static Context context;
private String tmpPath;
@Before
public void setup() {
context = new ChromeContext();
context.start();
context.getDriver().manage().window().setSize(new Dimension(1600, 900));
context.getDriver().get(APP_URL);
tmpPath = context.getTmpPath();
}
@After
public void quit() {
context.close();
}
@Test
public void downloadDocs() throws InterruptedException {
System.out.println("Downloading test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickMenuElement(1);
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);
int timeout=0;
while(!f.exists()&&timeout<100){
Thread.sleep(500);
timeout++;
}
Assert.assertTrue(f.exists());
if(f.exists()) {
f.delete();
}
}
@Test
public void downloadJournal() throws InterruptedException {
System.out.println("Downloading journal test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickMenuElement(2);
PressPage pressPage = PageFactory.initElements(context.getDriver(), PressPage.class);
pressPage.clickMenuElement(2);
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();
}
}
}

View File

@ -0,0 +1,83 @@
import Pages.*;
import context.ChromeContext;
import context.Context;
import org.junit.After;
import org.junit.Assert;
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;
public class FeedbackTests {
private final static String APP_URL = "http://www.gazprom.ru/";
private static Context context;
@Before
public void setup() {
context = new ChromeContext();
context.start();
context.getDriver().manage().window().setSize(new Dimension(1600, 900));
context.getDriver().get(APP_URL);
}
@After
public void quit() {
context.close();
}
@Test
public void offer() {
System.out.println("Offer test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickAdditionalMenuElement(1);
PurchasesPage purchasesPage = PageFactory.initElements(context.getDriver(), PurchasesPage.class);
purchasesPage.clickMenuItem(10);
FeedbackPage feedbackPage = PageFactory.initElements(context.getDriver(), FeedbackPage.class);
feedbackPage.insertEmail("test@mail.ru");
feedbackPage.insertText("test text");
feedbackPage.submitFeedback();
String output = feedbackPage.getOutput();
Assert.assertTrue(output.equals("Ваше сообщение отправлено."));
}
@Test
public void shareFunction() throws TwitterException {
System.out.println("Sharing test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickMenuElement(2);
PressPage pressPage = PageFactory.initElements(context.getDriver(), PressPage.class);
pressPage.clickMenuElement(1);
MediaLib mediaLib = PageFactory.initElements(context.getDriver(), MediaLib.class);
mediaLib.clickItemImage(0);
mediaLib.clickSocialLink(2);
// String title = mediaLib.getAlbumTitle();
for (String winHandle : context.getDriver().getWindowHandles()) {
context.getDriver().switchTo().window(winHandle);
}
TwitterSharingPopup twitterSharingPopup = PageFactory.initElements(context.getDriver(), TwitterSharingPopup.class);
Assert.assertTrue(twitterSharingPopup.submitBtnPresent());
}
}

View File

@ -0,0 +1,241 @@
import Pages.*;
import context.ChromeContext;
import context.Context;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
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.*;
public class FilterTests {
private final static String APP_URL = "http://www.gazprom.ru/";
private static Context context;
@Before
public void setup() {
context = new ChromeContext();
context.start();
context.getDriver().manage().window().setSize(new Dimension(1600, 900));
context.getDriver().get(APP_URL);
}
@After
public void quit() {
context.close();
}
@Test
public void simpleSearch() throws ParseException, InterruptedException {
System.out.println("Simple search test");
MainPage mainPage = PageFactory.initElements(context.getDriver(), MainPage.class);
mainPage.clickSearchBtn();
String queryString = "рейтинг";
mainPage.insertSearchText(queryString);
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;
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);
}
@Test
public void sorting() {
System.out.println("Sorting test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickMenuElement(0);
AboutPage aboutPage = PageFactory.initElements(context.getDriver(), AboutPage.class);
aboutPage.clickMenuElement(4);
SubsidiariesPage subsidiariesPage = PageFactory.initElements(context.getDriver(), SubsidiariesPage.class);
subsidiariesPage.clickPercentFilter();
boolean order = true;
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);
}
@Test
public void filteredSearch() throws ParseException, InterruptedException {
System.out.println("Filtered search test");
MainPage mainPage = PageFactory.initElements(context.getDriver(), MainPage.class);
mainPage.clickSearchBtn();
String queryString = "рейтинг";
mainPage.insertSearchText(queryString);
mainPage.submitSearch();
SearchResultsPage searchResultsPage = PageFactory.initElements(context.getDriver(), SearchResultsPage.class);
searchResultsPage.setFilterOn();
searchResultsPage.selectYear(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);
}
@Test
public void leftMenuFilter() throws ParseException {
System.out.println("Filter by left menu test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickMenuElement(2);
PressPage pressPage = PageFactory.initElements(context.getDriver(), PressPage.class);
pressPage.clickMenuElement(0);
EventsPage eventsPage = PageFactory.initElements(context.getDriver(), EventsPage.class);
eventsPage.selectYear(1);
eventsPage.selectMonth(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));
if(calendar.get(Calendar.MONTH)!=month){
suitable = false;
break;
}
}
Assert.assertTrue(suitable);
}
@Test
public void pagination() throws InterruptedException {
System.out.println("Pagination test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickAdditionalMenuElement(1);
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));
}
int pageNumber = 1;
purchasesPage.clickPage(pageNumber);
Thread.sleep(2000);
boolean turn = purchasesPage.isSelectedPage(pageNumber);
boolean found = false;
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);
}
}

View File

@ -0,0 +1,153 @@
import Pages.AlbumPage;
import Pages.MediaLib;
import Pages.VideoPage;
import context.ChromeContext;
import context.Context;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
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;
public class MultimediaTests {
private final static String APP_URL = "http://www.gazprom.ru/press/media/";
private static Context context;
@Before
public void setup() {
context = new ChromeContext();
context.start();
context.getDriver().manage().window().setSize(new Dimension(1600, 900));
context.getDriver().get(APP_URL);
}
@After
public void quit() {
context.close();
}
@Test
public void albumList() throws ParseException, InterruptedException {
System.out.println("List of albums test");
MediaLib mediaLib = PageFactory.initElements(context.getDriver(), MediaLib.class);
mediaLib.selectMonth(1);
// Thread.sleep(2000);
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);
}
@Test
public void photoList() {
System.out.println("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);
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);
}
@Test
public void photosView() throws InterruptedException {
System.out.println("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);
int elementNumber = 1;
albumPage.clickPhotoPopup(elementNumber);
Assert.assertTrue(albumPage.isSelectedPhoto(elementNumber));
}
@Test
public void videoList() throws ParseException, InterruptedException {
System.out.println("List of video test");
MediaLib mediaLib = PageFactory.initElements(context.getDriver(), MediaLib.class);
mediaLib.clickVideoFilter();
// Thread.sleep(1000);
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);
}
@Test
public void videoPage () throws InterruptedException {
System.out.println("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);
VideoPage videoPage = PageFactory.initElements(context.getDriver(), VideoPage.class);
Assert.assertTrue(videoPage.getVideoTitle().equals(title));
}
}

View File

@ -0,0 +1,113 @@
import Pages.*;
import context.ChromeContext;
import context.Context;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.support.PageFactory;
import java.util.ArrayList;
public class NavigationTests {
private final static String APP_URL = "http://www.gazprom.ru/";
private static Context context;
@Before
public void setup() {
context = new ChromeContext();
context.start();
context.getDriver().manage().window().setSize(new Dimension(1600, 900));
context.getDriver().get(APP_URL);
}
@After
public void quit() {
context.close();
}
@Test
public void topMenuTest() {
System.out.println("Top menu test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
int elementNumber = 2;
String title = page.getTitleMenuElement(elementNumber);
page.clickMenuElement(elementNumber);
PressPage pressPage = PageFactory.initElements(context.getDriver(), PressPage.class);
Assert.assertTrue(pressPage.getTitle().contains(title));
}
@Test
public void subMenu(){
System.out.println("Sub menu test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickMenuElement(0);
PressPage pressPage = PageFactory.initElements(context.getDriver(), PressPage.class);
int elementNumber = 1;
String title = pressPage.getTitleMenuElement(elementNumber);
pressPage.clickMenuElement(elementNumber);
MediaLib mediaLib = PageFactory.initElements(context.getDriver(), MediaLib.class);
Assert.assertTrue(mediaLib.getTitle().contains(title));
}
@Test
public void hyperlinks(){
System.out.println("Hyperlinks test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickMenuElement(0);
AboutPage aboutPage = PageFactory.initElements(context.getDriver(), AboutPage.class);
int elementNumber = 0;
String title = aboutPage.getTextHyperlinksElement(elementNumber);
aboutPage.clickHyperlinksElement(elementNumber);
MiningPage miningPage = PageFactory.initElements(context.getDriver(), MiningPage.class);
Assert.assertTrue(miningPage.getTitle().toLowerCase().contains(title));
}
@Test
public void sideMenu() {
System.out.println("Side menu test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickLayButton();
int elementNumber = 3;
String title = page.getTitleLayMenuElement(elementNumber);
page.clickLayMenuElement(elementNumber);
MarketingPage marketingPage = PageFactory.initElements(context.getDriver(), MarketingPage.class);
Assert.assertTrue(marketingPage.getTitle().contains(title));
}
@Test
public void externalLinks() throws InterruptedException {
System.out.println("External links test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
page.clickExternalSitesBtn();
int elementNumber = 0;
String title = page.getTitleExternalLink(elementNumber);
page.clickExternalLink(elementNumber);
ArrayList<String> tabs2 = new ArrayList<String> (context.getDriver().getWindowHandles());
context.getDriver().switchTo().window(tabs2.get(1));
Assert.assertTrue(context.getDriver().getTitle().contains(title));
}
}

View File

@ -0,0 +1,35 @@
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;
public class AboutPage {
private WebDriver driver;
@FindBy(css = ".content_wrapper a")
private List<WebElement> hyperlinkElements;
@FindBy(css = ".subnavigation li")
private List<WebElement> subMenuElements;
public AboutPage(WebDriver driver) {
this.driver = driver;
}
public void clickHyperlinksElement(int elementNumber){
hyperlinkElements.get(elementNumber).click();
}
public String getTextHyperlinksElement(int elementNumber){
return hyperlinkElements.get(elementNumber).getText();
}
public void clickMenuElement(int elementNumber){
subMenuElements.get(elementNumber).click();
}
}

View File

@ -0,0 +1,54 @@
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;
public class AlbumPage {
private WebDriverWait wait;
private WebDriver driver;
@FindBy(css = ".media__list .media__item img")
private List<WebElement> albumImages;
@FindBy(css = ".media__popup__thumbs .media__popup__thumb")
private List<WebElement> photosPopup;
public AlbumPage(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver,30,500);
}
public String getImageName(int elementNumber){
String imageName = albumImages.get(elementNumber).getAttribute("src");
imageName = imageName.substring(imageName.lastIndexOf("/")+1);
if(imageName.contains("_"))
imageName = imageName.substring(imageName.lastIndexOf("_")+1);
return imageName;
}
public int getImagesCount(){
return albumImages.size();
}
public void clickPhotoLink(int elementNumber) {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("media__item")));
albumImages.get(elementNumber).click();
}
public void clickPhotoPopup(int elementNumber) {
wait.until(ExpectedConditions.visibilityOfAllElements(photosPopup.get(elementNumber)));
photosPopup.get(elementNumber).click();
}
public boolean isSelectedPhoto(int elementNumber){
return photosPopup.get(elementNumber).getAttribute("class").contains("media__popup__thumb--selected");
}
}

View File

@ -0,0 +1,130 @@
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;
public class CalculatorPage {
private WebDriverWait wait;
private WebDriver driver;
@FindBy(css = ".tbl_box #fromDate")
private WebElement fromDateInput;
@FindBy(css = ".tbl_box #toDate")
private WebElement toDateInput;
@FindBy(css = ".tbl_box #amountOfShares")
private WebElement amountInput;
@FindBy(css = ".tbl_box table tr:nth-child(8) input")
private WebElement calculateBtn;
@FindBy(css = ".result tr")
private List<WebElement> tableElements;
@FindBy(css = ".result tr:nth-child(11) td:nth-child(2)")
private WebElement startPrice;
@FindBy(css = ".result tr:nth-child(12) td:nth-child(2)")
private WebElement endPrice;
@FindBy(css = ".result tr:nth-child(13) td:nth-child(3)")
private WebElement reInvPrice;
@FindBy(css = ".result tr:nth-child(3) td:nth-child(2)")
private WebElement changePrice;
@FindBy(css = ".result tr:nth-child(7) td:nth-child(2)")
private WebElement changePriceRe;
@FindBy(css = ".result tr:nth-child(1) span")
private WebElement income;
@FindBy(id = "ruCalc")
private WebElement ruCalcFrame;
@FindBy(name = "chart")
private WebElement chartFrame;
public CalculatorPage(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver,30,500);
}
public void switchToCalcFrame(){
wait.until(ExpectedConditions.visibilityOfAllElements(ruCalcFrame));
driver.switchTo().frame(ruCalcFrame);
driver.switchTo().frame(chartFrame);
}
public void clickCalcBtn(){
calculateBtn.click();
}
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 void insertToDate(String text){
wait.until(ExpectedConditions.visibilityOfAllElements(toDateInput));
toDateInput.clear();
toDateInput.sendKeys(text);
}
public void insertAmount(String text){
wait.until(ExpectedConditions.visibilityOfAllElements(amountInput));
amountInput.clear();
amountInput.sendKeys(text);
}
}

View File

@ -0,0 +1,42 @@
package Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import java.util.List;
public class EventsPage {
private WebDriver driver;
@FindBy(css = ".years-navigation li")
private List<WebElement> yearsFilter;
@FindBy(css = ".years-navigation__months li")
private List<WebElement> monthFilter;
@FindBy(css = ".news-list li .date")
private List<WebElement> searchResultsDates;
public EventsPage (WebDriver driver) {
this.driver = driver;
}
public void selectYear(int itemNumber){
yearsFilter.get(itemNumber).click();
}
public void selectMonth(int itemNumber){
monthFilter.get(itemNumber).click();
}
public String getDateOfResult(int itemNumber){
return searchResultsDates.get(itemNumber).getText();
}
public int getResultsCount(){
return searchResultsDates.size();
}
}

View File

@ -0,0 +1,49 @@
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;
public class FeedbackPage {
private WebDriverWait wait;
private WebDriver driver;
@FindBy(id = "email")
private WebElement emailInput;
@FindBy(id = "text")
private WebElement textInput;
@FindBy(id = "btnSubmit")
private WebElement btnSubmit;
@FindBy(id = "output")
private WebElement output;
public FeedbackPage(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver,30,500);
}
public void insertEmail(String email){
emailInput.sendKeys(email);
}
public void insertText(String text){
textInput.sendKeys(text);
}
public void submitFeedback(){
btnSubmit.click();
}
public String getOutput(){
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("output")));
return output.getText();
}
}

View File

@ -0,0 +1,35 @@
package Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import java.util.List;
public class ForShareholders {
private WebDriver driver;
@FindBy(css = ".reports_cont .file a")
private List<WebElement> downloadLinks;
@FindBy(css = ".subnavigation li")
private List<WebElement> subMenuElements;
public ForShareholders(WebDriver driver) {
this.driver = driver;
}
public String getFileName(int elementNumber){
String fileName = downloadLinks.get(elementNumber).getAttribute("href");
fileName = fileName.substring(fileName.lastIndexOf("/")+1);
return fileName;
}
public void clickDownloadLink(int elementNumber){
downloadLinks.get(elementNumber).click();
}
public void clickMenuElement(int elementNumber){
subMenuElements.get(elementNumber).click();
}
}

View File

@ -0,0 +1,36 @@
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;
public class JournalsPage {
private WebDriverWait wait;
private WebDriver driver;
@FindBy(css = ".journals__img-link")
private List<WebElement> imgLinks;
public JournalsPage(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver,30,500);
}
public void clickImgLink(int elementNumber){
wait.until(ExpectedConditions.visibilityOfAllElements(imgLinks));
imgLinks.get(elementNumber).click();
}
public String getFileName(int elementNumber){
String fileName = imgLinks.get(elementNumber).getAttribute("href");
fileName = fileName.substring(fileName.lastIndexOf("/")+1);
return fileName;
}
}

View File

@ -0,0 +1,97 @@
package Pages;
import org.openqa.selenium.Keys;
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;
public class MainPage {
private WebDriverWait wait;
private WebDriver driver;
@FindBy(css = ".navigation li")
private List<WebElement> menuElements;
@FindBy(css = ".lay_button")
private WebElement layButton;
@FindBy(css = ".menu-map__col a")
private List<WebElement> layMenuElements;
@FindBy(id = "sites_link")
private WebElement externalSitesBtn;
@FindBy(css = "#sites_list .column_wrapper a")
private List<WebElement> externalLinks;
@FindBy(css = ".main_menu_search")
private WebElement searchBtn;
@FindBy(id = "search-field__query")
private WebElement searchField;
@FindBy(css = ".additional_top_navigation a")
private List<WebElement> additionalMenu;
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 String getTitleMenuElement(int elementNumber){
wait.until(ExpectedConditions.visibilityOfAllElements(menuElements));
return menuElements.get(elementNumber).getText();
}
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 clickExternalSitesBtn(){
externalSitesBtn.click();
}
public void clickExternalLink(int elementNumber) {
wait.until(ExpectedConditions.visibilityOfAllElements(externalLinks.get(elementNumber)));
externalLinks.get(elementNumber).click();
}
public String getTitleExternalLink(int elementNumber) {
wait.until(ExpectedConditions.visibilityOfAllElements(externalLinks.get(elementNumber)));
return externalLinks.get(elementNumber).getText();
}
public void clickSearchBtn(){
searchBtn.click();
}
public void insertSearchText(String text){
searchField.sendKeys(text);
}
public void submitSearch(){
searchField.sendKeys(Keys.RETURN);
}
public void clickAdditionalMenuElement(int elementNumber){
additionalMenu.get(elementNumber).click();
}
}

View File

@ -0,0 +1,18 @@
package Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
public class MarketingPage {
private WebDriver driver;
public MarketingPage(WebDriver driver) {
this.driver = driver;
}
public String getTitle(){
return driver.getTitle();
}
}

View File

@ -0,0 +1,95 @@
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;
public class MediaLib {
private WebDriverWait wait;
private WebDriver driver;
@FindBy(css = ".media__list:first-child .media__item .media__date:first-child")
private List<WebElement> itemsDates;
@FindBy(css = ".media__list:first-child .media__item .media__name a")
private List<WebElement> itemsTitles;
@FindBy(css = ".media__list:first-child .media__item a:first-child")
private List<WebElement> itemsLinks;
@FindBy(css = ".media__list:first-child .media__item a:first-child img")
private List<WebElement> albumsImages;
@FindBy(css = ".content__filter a")
private List<WebElement> contentFilter;
@FindBy(css = ".years-navigation__months li")
private List<WebElement> monthFilter;
@FindBy(css = ".media__popup__social span")
private List<WebElement> socialLinks;
@FindBy(css = ".h1--semi-margin-bottom")
private WebElement albumTitle;
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");
}
public int getItemsCount(){
return itemsDates.size();
}
public void clickItemImage(int elementNumber){
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("media__item")));
albumsImages.get(elementNumber).click();
}
public String getItemImageName(int elementNumber){
String preview = albumsImages.get(elementNumber).getAttribute("src");
preview = preview.substring(preview.lastIndexOf("_")+1);
return preview;
}
public void clickVideoFilter() {
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){
monthFilter.get(itemNumber).click();
}
public void clickSocialLink(int itemNumber){
socialLinks.get(itemNumber).click();
}
public String getAlbumTitle(){
return albumTitle.getText();
}
}

View File

@ -0,0 +1,18 @@
package Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
public class MiningPage {
private WebDriver driver;
public MiningPage(WebDriver driver) {
this.driver = driver;
}
public String getTitle(){
return driver.getTitle();
}
}

View File

@ -0,0 +1,39 @@
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;
public class PressPage {
private WebDriverWait wait;
private WebDriver driver;
@FindBy(css = ".subnavigation li")
private List<WebElement> menuElements;
public PressPage(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver,30,500);
}
public String getTitle(){
return driver.getTitle();
}
public void clickMenuElement(int elementNumber){
wait.until(ExpectedConditions.visibilityOfAllElements(menuElements));
menuElements.get(elementNumber).click();
}
public String getTitleMenuElement(int elementNumber){
wait.until(ExpectedConditions.visibilityOfAllElements(menuElements));
return menuElements.get(elementNumber).getText();
}
}

View File

@ -0,0 +1,52 @@
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;
public class PurchasesPage {
private WebDriverWait wait;
private WebDriver driver;
@FindBy(css = ".subnavigation a")
private List<WebElement> menuElements;
@FindBy(css = ".text_data tbody tr")
private List<WebElement> searchResults;
@FindBy(css = ".text_data tbody tr td:nth-child(2) p:first-child span")
private List<WebElement> purchasesNumbers;
@FindBy(css = ".dataTables_paginate span")
private List<WebElement> paginationElements;
public PurchasesPage(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver,30,500);
}
public void clickMenuItem(int itemNumber){
menuElements.get(itemNumber).click();
}
public String getPurchaseNumber(int itemNumber){
return purchasesNumbers.get(itemNumber).getText();
}
public int getItemsCount(){
return searchResults.size();
}
public void clickPage(int pageNumber){
paginationElements.get(pageNumber).click();
}
public boolean isSelectedPage(int pageNumber){
return paginationElements.get(pageNumber).getAttribute("class").equals("paginate_active");
}
}

View File

@ -0,0 +1,54 @@
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;
public class SearchResultsPage {
private WebDriverWait wait;
private WebDriver driver;
@FindBy(css = ".search_results .search_results__item[data-ng-repeat='item in searchResults'] .search_results__date")
private List<WebElement> searchResultsDates;
@FindBy(css = ".search_results .search_results__item[data-ng-repeat='item in searchResults'] .search_results__text")
private List<WebElement> searchResultsTexts;
@FindBy(css = ".toggle span")
private WebElement filterOn;
@FindBy(css = ".search__tags--years .tag-button")
private List<WebElement> yearsFilter;
public SearchResultsPage (WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver,30,500);
}
public String getItemsText(int itemNumber){
return searchResultsTexts.get(itemNumber).getText();
}
public String getItemsDate(int itemNumber){
return searchResultsDates.get(itemNumber).getAttribute("value");
}
public int getItemsCount(){
wait.until(ExpectedConditions.visibilityOfAllElements(searchResultsTexts));
return searchResultsTexts.size();
}
public void setFilterOn(){
filterOn.click();
}
public void selectYear(int itemNumber){
yearsFilter.get(itemNumber).click();
}
}

View File

@ -0,0 +1,58 @@
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;
public class SubsidiariesPage {
private WebDriver driver;
@FindBy(css = ".filters p *")
private List<WebElement> filtersLinks;
@FindBy(css = ".company_list ul:nth-child(2) .gazprom_part")
private List<WebElement> itemsPercent100;
@FindBy(css = ".company_list ul:nth-child(6) .gazprom_part")
private List<WebElement> itemsPercentMore50;
@FindBy(css = ".company_list ul:nth-child(8) .gazprom_part")
private List<WebElement> itemsPercentLess50;
public SubsidiariesPage(WebDriver driver) {
this.driver = driver;
}
public void clickPercentFilter(){
filtersLinks.get(1).click();
}
public int getItemsPercent100Count(){
return itemsPercent100.size();
}
public int getItemsPercentMore50Count(){
return itemsPercentMore50.size();
}
public int getItemsPercentLess50Count(){
return itemsPercentLess50.size();
}
public float getPartOfItemPercent100(int itemNumber){
String per = itemsPercent100.get(itemNumber).getText().split("%")[0];
return Float.parseFloat(per.substring(per.lastIndexOf(" ")+1).replace(",","."));
}
public float getPartOfItemPercentMore50(int itemNumber){
String per = itemsPercentMore50.get(itemNumber).getText().split("%")[0];
return Float.parseFloat(per.substring(per.lastIndexOf(" ")+1).replace(",","."));
}
public float getPartOfItemPercentLess50(int itemNumber){
String per = itemsPercentLess50.get(itemNumber).getText().split("%")[0];
return Float.parseFloat(per.substring(per.lastIndexOf(" ")+1).replace(",","."));
}
}

View File

@ -0,0 +1,38 @@
package Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
public class TwitterSharingPopup {
private WebDriver driver;
@FindBy(id = "username_or_email")
private WebElement usernameInput;
@FindBy(id = "password")
private WebElement passInput;
@FindBy(css = ".submit")
private WebElement submitBtn;
public TwitterSharingPopup(WebDriver driver) {
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(){
return submitBtn.isDisplayed();
}
}

View File

@ -0,0 +1,33 @@
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;
public class VideoPage {
private WebDriver driver;
@FindBy(css = ".media__list .media__item img")
private List<WebElement> albumImages;
@FindBy(css = ".media__popup__thumbs .media__popup__thumb")
private List<WebElement> photosPopup;
@FindBy(css = ".media_filter h1")
private WebElement videoTitle;
public VideoPage(WebDriver driver) {
this.driver = driver;
}
public String getTitle(){
return driver.getTitle();
}
public String getVideoTitle(){
return videoTitle.getText();
}
}

View File

@ -0,0 +1,40 @@
package context;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.util.HashMap;
import java.util.Map;
public class ChromeContext extends Context {
private final static String WINDOWS_DRIVER = "chromedriver.exe";
private final static String LINUX_DRIVER = "chromedriver";
private final static String DRIVER_TYPE = "webdriver.chrome.driver";
@Override
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);
options.setExperimentalOption("prefs",prefs);
driver = new ChromeDriver(options);
}
@Override
protected String getDriverExecutable(boolean isWindows) {
return isWindows ? WINDOWS_DRIVER : LINUX_DRIVER;
}
@Override
protected String getDriverType() {
return DRIVER_TYPE;
}
}

View File

@ -0,0 +1,50 @@
package context;
import org.openqa.selenium.WebDriver;
import java.util.concurrent.TimeUnit;
public abstract class Context {
private final static String DRIVER_LOCATION = "drivers/%s";
protected WebDriver driver;
protected String tmpPath;
public WebDriver getDriver() {
if (driver != null) {
return driver;
}
throw new IllegalStateException("WebDriver is not initialized");
}
public void start() {
System.setProperty(getDriverType(), getDriverExecutablePath());
createDriver();
// это плохая инструкция для автотестов, т.к. лучше задавать для конкретного элемента или кейса
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
public void close() {
driver.quit();
}
protected abstract void createDriver();
protected abstract String getDriverType();
protected abstract String getDriverExecutable(boolean windows);
private String getDriverExecutablePath() {
return Context.class.getClassLoader().getResource(
String.format(DRIVER_LOCATION, getDriverExecutable(isWindows()))).getFile();
}
private boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("windows");
}
public String getTmpPath(){
return tmpPath;
}
}