From d451c57fa6b4ab3c0ea3697ace92e0416eba58bf Mon Sep 17 00:00:00 2001 From: SemenovaMasha Date: Sat, 28 Apr 2018 10:25:23 +0400 Subject: [PATCH] Unified methods --- Semenova/src/test/java/CalculatorTest.java | 3 +- Semenova/src/test/java/FilterTests.java | 17 +-- Semenova/src/test/java/MultimediaTests.java | 6 +- .../java/PageHelpers/AlbumPageHelper.java | 48 ++------ .../PageHelpers/CalculatorPageHelper.java | 43 ++----- .../java/PageHelpers/EventsPageHelper.java | 4 +- .../java/PageHelpers/FeedbackPageHelper.java | 5 +- .../java/PageHelpers/MediaLibPageHelper.java | 15 +-- .../java/PageHelpers/PurchasePageHelper.java | 36 +----- .../PageHelpers/SearchResultsPageHelper.java | 107 +++++------------- .../PageHelpers/SubsidiariesPageHelper.java | 62 +++++----- .../WaitingForElementToLoadHelper.java | 47 ++++++++ Semenova/src/test/java/Pages/PressPage.java | 2 +- .../test/java/Pages/SearchResultsPage.java | 1 - .../src/test/java/context/ChromeContext.java | 1 - 15 files changed, 153 insertions(+), 244 deletions(-) create mode 100644 Semenova/src/test/java/PageHelpers/WaitingForElementToLoadHelper.java diff --git a/Semenova/src/test/java/CalculatorTest.java b/Semenova/src/test/java/CalculatorTest.java index a392b91..e3a5c14 100644 --- a/Semenova/src/test/java/CalculatorTest.java +++ b/Semenova/src/test/java/CalculatorTest.java @@ -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()); } } diff --git a/Semenova/src/test/java/FilterTests.java b/Semenova/src/test/java/FilterTests.java index ed4c75c..7311c5f 100644 --- a/Semenova/src/test/java/FilterTests.java +++ b/Semenova/src/test/java/FilterTests.java @@ -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); diff --git a/Semenova/src/test/java/MultimediaTests.java b/Semenova/src/test/java/MultimediaTests.java index 1864898..8c0a6e3 100644 --- a/Semenova/src/test/java/MultimediaTests.java +++ b/Semenova/src/test/java/MultimediaTests.java @@ -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 diff --git a/Semenova/src/test/java/PageHelpers/AlbumPageHelper.java b/Semenova/src/test/java/PageHelpers/AlbumPageHelper.java index 55c1de6..e727a96 100644 --- a/Semenova/src/test/java/PageHelpers/AlbumPageHelper.java +++ b/Semenova/src/test/java/PageHelpers/AlbumPageHelper.java @@ -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 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; + } +} \ No newline at end of file diff --git a/Semenova/src/test/java/PageHelpers/WaitingForElementToLoadHelper.java b/Semenova/src/test/java/PageHelpers/WaitingForElementToLoadHelper.java new file mode 100644 index 0000000..d805bc8 --- /dev/null +++ b/Semenova/src/test/java/PageHelpers/WaitingForElementToLoadHelper.java @@ -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