Unified methods

This commit is contained in:
SemenovaMasha 2018-04-28 10:25:23 +04:00
parent fc913632db
commit d451c57fa6
15 changed files with 153 additions and 244 deletions

View File

@ -35,7 +35,7 @@ public class CalculatorTest {
}
@Test
public void countInvestor() throws InterruptedException {
public void countInvestor() throws InterruptedException, NoSuchMethodException {
log.logp(INFO, getClass().getName(), "countInvestor", "Investor's count test");
CalculatorPage calculatorPage = PageFactory.initElements(context.getDriver(), CalculatorPage.class);
@ -51,7 +51,6 @@ public class CalculatorTest {
Thread.sleep(1000);
Assert.assertTrue(calculatorPageHelper.isCalculationRight());
}
}

View File

@ -19,6 +19,7 @@ import static java.util.logging.Level.INFO;
public class FilterTests {
private final static String APP_URL = "http://www.gazprom.ru/";
// private final static String APP_URL = "http://www.gazprom.ru/tenders/";
private static java.util.logging.Logger log = Logger.getLogger(FilterTests.class.getName());
private static Context context;
@ -38,7 +39,7 @@ public class FilterTests {
}
@Test
public void simpleSearch() throws ParseException {
public void simpleSearch() throws ParseException, NoSuchMethodException {
log.logp(INFO, getClass().getName(), "simpleSearch", "Simple search test");
MainPage mainPage = PageFactory.initElements(context.getDriver(), MainPage.class);
@ -51,12 +52,12 @@ public class FilterTests {
SearchResultsPage searchResultsPage = PageFactory.initElements(context.getDriver(), SearchResultsPage.class);
SearchResultsPageHelper helper = new SearchResultsPageHelper(searchResultsPage);
Assert.assertTrue(helper.isSuitable(queryString));
Assert.assertTrue(helper.searchResultsMatchQueryAndInOrder(queryString));
}
@Test
public void sorting() {
public void sorting() throws Exception {
log.logp(INFO, getClass().getName(), "sorting", "Sorting test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
@ -74,7 +75,7 @@ public class FilterTests {
}
@Test
public void filteredSearch() throws ParseException, InterruptedException {
public void filteredSearch() throws ParseException, InterruptedException, NoSuchMethodException {
log.logp(INFO, getClass().getName(), "filteredSearch", "Filtered search test");
MainPage mainPage = PageFactory.initElements(context.getDriver(), MainPage.class);
@ -92,7 +93,7 @@ public class FilterTests {
int year = 2017;
Assert.assertTrue(helper.isSuitable(queryString,year));
Assert.assertTrue(helper.searchResultsMatchQueryYearAndInOrder(queryString,year));
}
@Test
@ -103,7 +104,7 @@ public class FilterTests {
page.clickMenuElementPress();
PressPage pressPage = PageFactory.initElements(context.getDriver(), PressPage.class);
pressPage.clickMenuElementEventpage();
pressPage.clickMenuElementEventPage();
EventsPage eventsPage = PageFactory.initElements(context.getDriver(), EventsPage.class);
eventsPage.selectYearByPosition(1);
@ -113,11 +114,11 @@ public class FilterTests {
EventsPageHelper helper = new EventsPageHelper(eventsPage);
Assert.assertTrue(helper.isSuitable(month));
Assert.assertTrue(helper.eventsMatchByMonth(month));
}
@Test
public void pagination() {
public void pagination() throws InterruptedException, NoSuchMethodException {
log.logp(INFO, getClass().getName(), "pagination", "Pagination test");
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);

View File

@ -46,7 +46,7 @@ public class MultimediaTests {
mediaLib.selectMonthByPosition(1);
MediaLibPageHelper helper = new MediaLibPageHelper(mediaLib);
Assert.assertTrue(helper.isOrder());
Assert.assertTrue(helper.itemsAreInOrder());
}
@Test
@ -66,7 +66,7 @@ public class MultimediaTests {
}
@Test
public void photosView() throws InterruptedException {
public void photosView() throws InterruptedException, NoSuchMethodException {
log.logp(INFO, getClass().getName(), "photosView", "View of photos test");
MediaLib mediaLib = PageFactory.initElements(context.getDriver(), MediaLib.class);
@ -91,7 +91,7 @@ public class MultimediaTests {
MediaLibPageHelper helper = new MediaLibPageHelper(mediaLib);
Assert.assertTrue(helper.isOrder());
Assert.assertTrue(helper.itemsAreInOrder());
}
@Test

View File

@ -2,13 +2,9 @@ package PageHelpers;
import Pages.AlbumPage;
import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import java.lang.reflect.Method;
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;
@ -27,42 +23,20 @@ public class AlbumPageHelper {
return containsPreview;
}
public boolean isSelectedPhoto(int elementNumber) throws InterruptedException {
public boolean isSelectedPhoto(int elementNumber) throws NoSuchMethodException {
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;
Method method = AlbumPageHelper.class.getMethod("clickAndCheckSelectedPhoto", int.class);
return WaitingForElementToLoadHelper.waitAndCheckSelection(method,this,new Object[]{elementNumber});
}
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");
public void clickPhotoLink(int elementNumber) throws NoSuchMethodException {
breakIt = false;
Method method = AlbumPage.class.getMethod("clickPhotoLink", int.class);
WaitingForElementToLoadHelper.waitAndCallMethod(method,page,new Object[]{elementNumber});
}
}
if (breakIt) {
break;
}
}
public boolean clickAndCheckSelectedPhoto(int elementNumber){
page.clickPhotoPopup();
return page.isSelectedPhoto(elementNumber);
}
}

View File

@ -3,16 +3,16 @@ package PageHelpers;
import Pages.CalculatorPage;
import org.openqa.selenium.WebElement;
import java.util.logging.Logger;
import java.lang.reflect.Method;
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){
Method insertInputMethod = CalculatorPageHelper.class.getMethod("insertInput", new Class[]{WebElement.class, String.class});
public CalculatorPageHelper(CalculatorPage page) throws NoSuchMethodException {
this.page = page;
}
@ -40,42 +40,21 @@ public class CalculatorPageHelper {
return ((double) round((reInvPrice-startPrice)/startPrice*100 *100))/100 ==changePriceRe;
}
public void waitAndInsertFromDate(String date){
waitForInputsPresent(page.getFromDateInput(),date);
public void waitAndInsertFromDate(String date) {
WaitingForElementToLoadHelper.waitAndCallMethod(insertInputMethod,this,new Object[]{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 insertInput(WebElement element,String text){
element.clear();
element.sendKeys(text);
}
public void waitAndInsertToDate(String date){
waitForInputsPresent(page.getToDateInput(),date);
WaitingForElementToLoadHelper.waitAndCallMethod(insertInputMethod,this,new Object[]{page.getToDateInput(),date});
}
public void waitAndInsertAmount(String amount){
waitForInputsPresent(page.getAmountInput(),amount);
WaitingForElementToLoadHelper.waitAndCallMethod(insertInputMethod,this,new Object[]{page.getAmountInput(),amount});
}
}

View File

@ -8,16 +8,14 @@ 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 {
public boolean eventsMatchByMonth(int month) throws ParseException {
boolean suitable = true;
DateFormat format = new SimpleDateFormat("d MMMM, hh:mm");

View File

@ -2,16 +2,13 @@ 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;
String successMessage = "Ваше сообщение отправлено.";
public FeedbackPageHelper(FeedbackPage page){
this.page = page;
}
String successMessage = "Ваше сообщение отправлено.";
public boolean isReceiveSuccess(){
String output = page.getOutput();
return output.equals(successMessage);

View File

@ -17,7 +17,7 @@ public class MediaLibPageHelper {
this.page = page;
}
public boolean isOrder() throws ParseException {
public boolean itemsAreInOrder() throws ParseException {
boolean order = true;
DateFormat format = new SimpleDateFormat("yyyy.M.d H:m");
Date datePrev = format.parse(page.getDateOfItem(0));
@ -34,17 +34,4 @@ public class MediaLibPageHelper {
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

@ -2,48 +2,22 @@ package PageHelpers;
import Pages.PurchasesPage;
import java.lang.reflect.Method;
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;
private int limit = 10;
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);
}
public boolean waitAndCheckPageSelection(int pageNumber) throws InterruptedException, NoSuchMethodException {
} catch (Exception e) {
log.logp(WARNING, getClass().getName(), "waitAndCheckPageSelection","Exception in waitAndCheckPageSelection method");
breakIt = false;
}
if (breakIt) {
break;
}
}
return turn;
Method method = PurchasesPage.class.getMethod("isSelectedPage", int.class);
return WaitingForElementToLoadHelper.waitAndCheckSelection(method,page,new Object[]{pageNumber});
}
}

View File

@ -2,6 +2,7 @@ package PageHelpers;
import Pages.SearchResultsPage;
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@ -10,7 +11,6 @@ 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 {
@ -21,12 +21,12 @@ public class SearchResultsPageHelper {
this.page = page;
}
public boolean isSuitable(String queryString) throws ParseException {
public boolean searchResultsMatchQueryAndInOrder(String queryString) throws ParseException, NoSuchMethodException {
boolean order = true;
DateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
Date datePrev = new Date();
boolean suitable = true;
boolean matched = true;
for (int i = 0; i < page.getItemsCount(); i++) {
Date dateCur = format.parse(waitAngGetItemsDate(i));
@ -37,101 +37,54 @@ public class SearchResultsPageHelper {
break;
}
if(!waitAndGetItemsText(i).toLowerCase().contains(queryString)){
log.logp(WARNING, getClass().getName(), "simpleSearch", "'" + waitAndGetItemsText(i)+"' is not suitable for '"+queryString+"'");
suitable = false;
if(!waitAngGetItemsText(i).toLowerCase().contains(queryString)){
log.logp(WARNING, getClass().getName(), "simpleSearch", "'" + waitAngGetItemsText(i)+"' is not suitable for '"+queryString+"'");
matched = false;
break;
}
datePrev= dateCur;
}
return order&&suitable;
return order&&matched;
}
public boolean isSuitable(String queryString,int year) throws InterruptedException, ParseException {
boolean order = true;
public boolean searchResultsMatchQueryYearAndInOrder(String queryString, int year) throws ParseException, NoSuchMethodException {
boolean order = searchResultsMatchQueryAndInOrder(queryString);
DateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
Calendar calendar = new GregorianCalendar();
Date datePrev = new Date();
boolean suitable = true;
boolean matched = true;
for (int i = 0; i < page.getItemsCount(); i++) {
Date dateCur = new Date();
Date dateCur = format.parse(waitAngGetItemsDate(i));
calendar.setTime(dateCur);
int timeout = 10;
boolean isSuitableElement = false;
for(int k=0;k<timeout;k++){
dateCur = format.parse(waitAngGetItemsDate(i));
calendar.setTime(dateCur);
matched = matchedByYear(calendar,year);
if(!matched){
log.logp(WARNING, getClass().getName(), "searchResultsMatchQueryYearAndInOrder",
" '"+calendar.get(Calendar.YEAR)+"' != '"+year+"'");
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;
return order&&matched;
}
private boolean matchedByYearAndQuery(String itemText, String query, Calendar calendar, int year){
return itemText.toLowerCase().contains(query)&&calendar.get(Calendar.YEAR)==year;
private boolean matchedByYear(Calendar calendar,int year){
return 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");
public String waitAngGetItemsText(int itemNumber) throws NoSuchMethodException {
breakIt = false;
}
if (breakIt) {
break;
}
Method method = SearchResultsPage.class.getMethod("getItemsText", int.class);
return (String)WaitingForElementToLoadHelper.waitAndCallMethod(method,page,new Object[]{itemNumber});
}
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;
}
public String waitAngGetItemsDate(int itemNumber) throws NoSuchMethodException {
Method method = SearchResultsPage.class.getMethod("getItemsDate", int.class);
return (String) WaitingForElementToLoadHelper.waitAndCallMethod(method, page, new Object[]{itemNumber});
}
return date;
}
}
}

View File

@ -2,10 +2,12 @@ package PageHelpers;
import Pages.SubsidiariesPage;
import java.lang.reflect.Method;
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;
@ -13,37 +15,37 @@ public class SubsidiariesPageHelper {
this.page = page;
}
public boolean isOrder() {
public boolean isOrder() throws Exception {
boolean order = true;
boolean order = checkPercents(page, "getPartOfItemPercent100","compareMethodEquals100",page.getItemsPercent100Count())
&&checkPercents(page, "getPartOfItemPercentMore50","compareMethodMore50",page.getItemsPercentMore50Count())
&&checkPercents(page, "getPartOfItemPercentLess50","compareMethodLess50",page.getItemsPercentLess50Count());
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;
}
}
private boolean checkPercents( Object object, String getPartMethodName,String compareMethodName,int numberOfElements) throws Exception {
Method getPartMethod = SubsidiariesPage.class.getMethod(getPartMethodName,int.class);
Method compareMethod = SubsidiariesPageHelper.class.getMethod(compareMethodName,float.class);
for (int i = 0; i < numberOfElements; i++) {
float percent = (Float)(getPartMethod.invoke(object, i));
if(!(Boolean)(compareMethod.invoke(this, percent))){
log.logp(WARNING, getClass().getName(), "sorting", getPartMethod.getName()+"!" +percent);
return false;
}
}
return true;
}
public boolean compareMethodEquals100(float percent){
return percent==100;
}
public boolean compareMethodMore50(float percent){
return percent>50;
}
public boolean compareMethodLess50(float percent){
return percent<=50;
}
}

View File

@ -0,0 +1,47 @@
package PageHelpers;
import java.lang.reflect.Method;
import java.util.logging.Logger;
import static java.util.logging.Level.WARNING;
public class WaitingForElementToLoadHelper {
private static java.util.logging.Logger log = Logger.getLogger(WaitingForElementToLoadHelper.class.getName());
static int tryLimit=10;
static Object waitAndCallMethod(Method methodToCall,Object object,Object[] parameters ){
Object objectToReturn=null;
boolean breakIt=false;
int attemptNumber =0;
while (!breakIt&&attemptNumber<tryLimit) {
attemptNumber++;
breakIt = true;
try {
Thread.sleep(200);
objectToReturn = methodToCall.invoke(object, parameters);
} catch (Exception e) {
log.logp(WARNING, WaitingForElementToLoadHelper.class.getName(), "waitAndCallMethod","Exception in waitAndCallMethod method");
breakIt = false;
}
}
return objectToReturn;
}
static boolean waitAndCheckSelection(Method methodToCall,Object object,Object[] parameters ) {
boolean turn=false;
int attemptNumber =0;
while (!turn&&attemptNumber<tryLimit) {
attemptNumber++;
try {
Thread.sleep(200);
turn=(Boolean)methodToCall.invoke(object, parameters);
} catch (Exception e) {
log.logp(WARNING, WaitingForElementToLoadHelper.class.getName(), "waitAndCheckSelection","Exception in waitAndCheckSelection method");
}
}
return turn;
}
}

View File

@ -31,7 +31,7 @@ public class PressPage {
wait.until(ExpectedConditions.visibilityOfAllElements(menuElements));
menuElements.get(journalPageMenuElementNumber).click();
}
public void clickMenuElementEventpage(){
public void clickMenuElementEventPage(){
wait.until(ExpectedConditions.visibilityOfAllElements(menuElements));
menuElements.get(eventPageMenuElementNumber).click();
}

View File

@ -40,7 +40,6 @@ public class SearchResultsPage {
public int getItemsCount() {
int size = searchResultsTexts.size();
System.out.println(size);
return size;
}

View File

@ -23,7 +23,6 @@ public class ChromeContext extends Context {
prefs.put("plugins.always_open_pdf_externally", true);
options.setExperimentalOption("prefs",prefs);
driver = new ChromeDriver(options);
}