1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Drawing ;
4+ using System . Linq ;
15using Aquality . Selenium . Browsers ;
26using Aquality . Selenium . Elements ;
37using Aquality . Selenium . Tests . Integration . TestApp ;
@@ -22,7 +26,7 @@ public void Should_BePossibleTo_Click()
2226
2327 [ Test ]
2428 public void Should_BePossibleTo_ClickAndWait ( )
25- {
29+ {
2630 var welcomeForm = new WelcomeForm ( ) ;
2731 welcomeForm . Open ( ) ;
2832 welcomeForm . GetExampleLink ( AvailableExample . Dropdown ) . JsActions . ClickAndWait ( ) ;
@@ -75,7 +79,7 @@ public void Should_BePossibleTo_CheckIsElementOnScreen()
7579 hoversForm . Open ( ) ;
7680 Assert . Multiple ( ( ) =>
7781 {
78- Assert . IsFalse ( hoversForm . GetHiddenElement ( HoverExample . First , ElementState . ExistsInAnyState ) . JsActions . IsElementOnScreen ( ) ,
82+ Assert . IsFalse ( hoversForm . GetHiddenElement ( HoverExample . First , ElementState . ExistsInAnyState ) . JsActions . IsElementOnScreen ( ) ,
7983 $ "Hidden element for { HoverExample . First } should be invisible.") ;
8084 Assert . IsTrue ( hoversForm . GetExample ( HoverExample . First ) . JsActions . IsElementOnScreen ( ) ,
8185 $ "Element for { HoverExample . First } should be visible.") ;
@@ -87,7 +91,7 @@ public void Should_BePossibleTo_SetValue()
8791 {
8892 var keyPressesForm = new KeyPressesForm ( ) ;
8993 keyPressesForm . Open ( ) ;
90- var text = "text" ;
94+ const string text = "text" ;
9195 keyPressesForm . InputTextBox . JsActions . SetValue ( text ) ;
9296 var actualText = keyPressesForm . InputTextBox . Value ;
9397 Assert . AreEqual ( text , actualText , $ "Text should be '{ text } ' after setting value via JS") ;
@@ -108,7 +112,7 @@ public void Should_BePossibleTo_GetXPathLocator()
108112 var welcomeForm = new WelcomeForm ( ) ;
109113 welcomeForm . Open ( ) ;
110114 var actualLocator = welcomeForm . SubTitleLabel . JsActions . GetXPath ( ) ;
111- var expectedLocator = "/html/body/DIV[2]/DIV[1]/H2[1]" ;
115+ const string expectedLocator = "/html/body/DIV[2]/DIV[1]/H2[1]" ;
112116 Assert . AreEqual ( expectedLocator , actualLocator , $ "Locator of sub title should be { expectedLocator } ") ;
113117 }
114118
@@ -126,48 +130,59 @@ public void Should_BePossibleTo_ScrollIntoView()
126130 {
127131 var infiniteScrollForm = new InfiniteScrollForm ( ) ;
128132 infiniteScrollForm . Open ( ) ;
133+ infiniteScrollForm . WaitForPageToLoad ( ) ;
129134 var defaultCount = infiniteScrollForm . ExampleLabels . Count ;
130- infiniteScrollForm . LastExampleLabel . JsActions . ScrollIntoView ( ) ;
131135 Assert . DoesNotThrow (
132136 ( ) => ConditionalWait . WaitForTrue ( ( ) =>
133137 {
134138 infiniteScrollForm . LastExampleLabel . JsActions . ScrollIntoView ( ) ;
135139 return infiniteScrollForm . ExampleLabels . Count > defaultCount ;
136- } ) ,
137- "Some examples should be added after scroll" ) ;
140+ } ) , "Some examples should be added after scroll" ) ;
138141 }
139142
140- [ Ignore ( "Need to fix on Azure" ) ]
141143 [ Test ]
142144 public void Should_BePossibleTo_ScrollBy ( )
143145 {
144- var infiniteScrollForm = new InfiniteScrollForm ( ) ;
145- infiniteScrollForm . Open ( ) ;
146- var defaultCount = infiniteScrollForm . ExampleLabels . Count ;
147- Assert . DoesNotThrow (
148- ( ) => ConditionalWait . WaitForTrue ( ( ) =>
149- {
150- infiniteScrollForm . LastExampleLabel . JsActions . ScrollBy ( 100000 , 100000 ) ;
151- return infiniteScrollForm . ExampleLabels . Count > defaultCount ;
152- } ) ,
153- "Some examples should be added after scroll ") ;
146+ var point = new Point ( 50 , 40 ) ;
147+ var homeDemoSiteForm = new HomeDemoSiteForm ( ) ;
148+ homeDemoSiteForm . Open ( ) ;
149+ homeDemoSiteForm . FirstScrollableExample . JsActions . ScrollBy ( point . X , point . Y ) ;
150+ var currentCoordinates = BrowserManager . Browser
151+ . ExecuteScriptFromFile < IList < object > > ( "Resources.GetScrollCoordinates.js" ,
152+ homeDemoSiteForm . FirstScrollableExample . GetElement ( ) ) . Select ( item => int . Parse ( item . ToString ( ) ) )
153+ . ToList ( ) ;
154+ var actualPoint = new Point ( currentCoordinates [ 0 ] , currentCoordinates [ 1 ] ) ;
155+ Assert . AreEqual ( point , actualPoint , $ "Current coordinates should be ' { point } ' ") ;
154156 }
155157
156- [ Ignore ( "Need to fix on Azure" ) ]
157158 [ Test ]
158159 public void Should_BePossibleTo_ScrollToTheCenter ( )
160+ {
161+ const int accuracy = 1 ;
162+ var welcomeForm = new WelcomeForm ( ) ;
163+ welcomeForm . Open ( ) ;
164+ welcomeForm . GetExampleLink ( AvailableExample . Dropdown ) . JsActions . ScrollToTheCenter ( ) ;
165+
166+ var windowSize = BrowserManager . Browser . ExecuteScriptFromFile < object > ( "Resources.GetWindowSize.js" ) . ToString ( ) ;
167+ var currentY = BrowserManager . Browser . ExecuteScriptFromFile < object > ( "Resources.GetElementYCoordinate.js" ,
168+ welcomeForm . GetExampleLink ( AvailableExample . Dropdown ) . GetElement ( ) ) . ToString ( ) ;
169+ var coordinateRelatingWindowCenter = double . Parse ( windowSize ) / 2 - double . Parse ( currentY ) ;
170+ Assert . LessOrEqual ( Math . Abs ( coordinateRelatingWindowCenter ) , accuracy , "Upper bound of element should be in the center of the page" ) ;
171+ }
172+
173+ [ Test ]
174+ public void Should_BePossibleTo_ScrollToTheCenter_CheckUI ( )
159175 {
160176 var infiniteScrollForm = new InfiniteScrollForm ( ) ;
161177 infiniteScrollForm . Open ( ) ;
162- var defaultCount = infiniteScrollForm . ExampleLabels . Count ;
163-
178+ infiniteScrollForm . WaitForPageToLoad ( ) ;
179+ var defaultCount = infiniteScrollForm . ExampleLabels . Count ;
164180 Assert . DoesNotThrow (
165181 ( ) => ConditionalWait . WaitForTrue ( ( ) =>
166182 {
167- infiniteScrollForm . LastExampleLabel . JsActions . ScrollToTheCenter ( ) ;
183+ infiniteScrollForm . Footer . JsActions . ScrollToTheCenter ( ) ;
168184 return infiniteScrollForm . ExampleLabels . Count > defaultCount ;
169- } ) ,
170- "Some examples should be added after scroll" ) ;
185+ } ) , "Some examples should be added after scroll" ) ;
171186 }
172187 }
173188}
0 commit comments