1- import { AppiumDriver , IRectangle , logInfo , logWarn , Point } from "nativescript-dev-appium" ;
1+ import {
2+ AppiumDriver ,
3+ IRectangle ,
4+ logInfo ,
5+ logWarn ,
6+ Point
7+ } from "nativescript-dev-appium" ;
28
39export enum ElementCacheStrategy {
410 allAtOnce ,
@@ -18,20 +24,23 @@ export class NavigationHelper {
1824 private _cachedElements : ICachedElement ;
1925 private _currentSuite : ICachedElement ;
2026
21- constructor ( protected _driver : AppiumDriver , protected _suitMainPageNavigationLinks : Array < string > , private _elemtsCacheStrategy : ElementCacheStrategy = ElementCacheStrategy . onload ) {
22- }
27+ constructor (
28+ protected _driver : AppiumDriver ,
29+ protected _suitMainPageNavigationLinks : Array < string > ,
30+ private _elementsCacheStrategy : ElementCacheStrategy = ElementCacheStrategy . onload
31+ ) { }
2332
24- async initSuite ( ) {
25- if ( this . _elemtsCacheStrategy === ElementCacheStrategy . allAtOnce
26- || this . _elemtsCacheStrategy === ElementCacheStrategy . onload ) {
33+ async initSuite ( ) : Promise < void > {
34+ if ( this . _elementsCacheStrategy === ElementCacheStrategy . allAtOnce
35+ || this . _elementsCacheStrategy === ElementCacheStrategy . onload ) {
2736 if ( this . _currentSuite ) {
2837 while ( this . _currentSuite . parent ) {
2938 this . _currentSuite = this . _currentSuite . parent ;
3039 }
3140 } else {
3241 if ( ! this . _cachedElements || this . _cachedElements . children . size === 0 ) {
3342 this . _cachedElements = { name : "initSuite" , children : new Map < string , ICachedElement > ( ) } ;
34- if ( this . _elemtsCacheStrategy === ElementCacheStrategy . allAtOnce ) {
43+ if ( this . _elementsCacheStrategy === ElementCacheStrategy . allAtOnce ) {
3544 await this . cacheAllElements ( this . _cachedElements ) ;
3645 }
3746 }
@@ -43,12 +52,12 @@ export class NavigationHelper {
4352 await this . navigateToSuitMainPage ( ) ;
4453 }
4554
46- async endSuite ( ) {
47- logInfo ( " End of suit 'button' tests!" ) ;
55+ async endSuite ( ) : Promise < void > {
56+ logInfo ( ` End of suit 'button' tests!` ) ;
4857 await this . _driver . takeScreenshot ( "end_button_suit" ) ;
4958 }
5059
51- async navigateToSuitMainPage ( ) {
60+ async navigateToSuitMainPage ( ) : Promise < void > {
5261 for ( let index = 0 ; index < this . _suitMainPageNavigationLinks . length ; index ++ ) {
5362 const mainPage = this . _suitMainPageNavigationLinks [ index ] ;
5463 await this . navigateToSample ( mainPage ) ;
@@ -59,7 +68,7 @@ export class NavigationHelper {
5968 logInfo ( `Navigate to ${ sample } ` ) ;
6069 const sampleName = sample . toLowerCase ( ) ;
6170
62- if ( this . _elemtsCacheStrategy === ElementCacheStrategy . allAtOnce ) {
71+ if ( this . _elementsCacheStrategy === ElementCacheStrategy . allAtOnce ) {
6372 if ( ! this . _currentSuite . children . has ( sampleName ) ) {
6473 await this . cacheAllElements ( this . _currentSuite ) ;
6574 }
@@ -69,7 +78,7 @@ export class NavigationHelper {
6978 const sampleElement = this . _currentSuite . children . get ( sampleName ) . rect ;
7079 await this . _driver . clickPoint ( sampleElement . x + ( sampleElement . width / 2 ) , sampleElement . y + ( sampleElement . height / 2 ) ) ;
7180 this . _currentSuite = this . _currentSuite . children . get ( sampleName ) ;
72- } else if ( this . _elemtsCacheStrategy === ElementCacheStrategy . onload ) {
81+ } else if ( this . _elementsCacheStrategy === ElementCacheStrategy . onload ) {
7382 if ( this . _currentSuite . children . has ( sampleName ) ) {
7483 const sampleElement = this . _currentSuite . children . get ( sampleName ) . rect ;
7584 await this . _driver . clickPoint ( sampleElement . x + ( sampleElement . width / 2 ) , sampleElement . y + ( sampleElement . height / 2 ) ) ;
@@ -94,14 +103,14 @@ export class NavigationHelper {
94103
95104 async navigateBackToSuitMainPage ( ) {
96105 logInfo ( `Navigate to back` ) ;
97- if ( this . _elemtsCacheStrategy === ElementCacheStrategy . allAtOnce
98- || this . _elemtsCacheStrategy === ElementCacheStrategy . onload ) {
106+ if ( this . _elementsCacheStrategy === ElementCacheStrategy . allAtOnce
107+ || this . _elementsCacheStrategy === ElementCacheStrategy . onload ) {
99108 this . _currentSuite = this . _currentSuite && this . _currentSuite . parent ;
100109 }
101110 await this . _driver . navBack ( ) ;
102111 }
103112
104- async swipeBackToSuitMainPage ( ) {
113+ async swipeBackToSuitMainPage ( ) : Promise < void > {
105114 logInfo ( `Swipe to back` ) ;
106115 const startPoint = < Point > { } ;
107116 const endPoint = < Point > { } ;
@@ -115,20 +124,29 @@ export class NavigationHelper {
115124
116125 await this . _driver . swipe ( startPoint , endPoint ) ;
117126 } else {
118- logWarn ( " Swipe back is not supported from android!" ) ;
127+ logWarn ( ` Swipe back is not supported from android!` ) ;
119128 }
120129 }
121130
122- private async cacheAllElements ( cachedElements : ICachedElement ) {
123- const allSamples = await this . _driver . findElementsByClassName ( this . _driver . locators . button ) ;
131+ private async cacheAllElements ( cachedElements : ICachedElement ) : Promise < void > {
132+ const allSamples = await this . _driver . findElementsByClassName ( this . _driver . locators . button ) ;
124133 for ( let index = 0 ; index < allSamples . length ; index ++ ) {
125134 const element = allSamples [ index ] ;
126135 const rect = await element . getRectangle ( ) ;
127- const text = ( await element . text ( ) ) . toLowerCase ( ) ;
128- if ( ! cachedElements . children . has ( text ) ) {
129- console . log ( text ) ;
130- cachedElements . children . set ( text , { parent : cachedElements , name : text , rect : rect , children : new Map ( ) } ) ;
131- }
136+ const text = ( await element . text ( ) ) . toLowerCase ( ) ;
137+
138+ if ( cachedElements . children . has ( text ) ) continue
139+
140+ logInfo ( text ) ;
141+ cachedElements . children . set (
142+ text ,
143+ {
144+ parent : cachedElements ,
145+ name : text ,
146+ rect : rect ,
147+ children : new Map ( )
148+ }
149+ ) ;
132150 }
133151 }
134152}
0 commit comments