File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ class SeleniumHelper {
1414 'clickText' ,
1515 'clickButton' ,
1616 'clickXpath' ,
17+ 'elementIsVisible' ,
18+ 'elementIsNotVisible' ,
1719 'findByText' ,
1820 'findByXpath' ,
1921 'getDriver' ,
@@ -24,6 +26,13 @@ class SeleniumHelper {
2426 ] ) ;
2527 }
2628
29+ elementIsVisible ( element ) {
30+ return this . driver . wait ( until . elementIsVisible ( element ) ) ;
31+ }
32+ elementIsNotVisible ( element ) {
33+ return this . driver . wait ( until . elementIsNotVisible ( element ) ) ;
34+ }
35+
2736 get scope ( ) {
2837 // List of useful xpath scopes for finding elements
2938 return {
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import SeleniumHelper from '../helpers/selenium-helper';
44const {
55 clickText,
66 clickXpath,
7+ elementIsVisible,
8+ elementIsNotVisible,
79 findByText,
810 findByXpath,
911 getDriver,
@@ -124,4 +126,27 @@ describe('Working with sprites', () => {
124126 const logs = await getLogs ( ) ;
125127 await expect ( logs ) . toEqual ( [ ] ) ;
126128 } ) ;
129+
130+ test ( 'Use browser back button to close library' , async ( ) => {
131+ await driver . get ( 'https://www.google.com' ) ;
132+ await loadUri ( uri ) ;
133+ await clickXpath ( '//button[@title="Try It"]' ) ;
134+ await clickText ( 'Costumes' ) ;
135+ await clickXpath ( '//button[@aria-label="Choose a Sprite"]' ) ;
136+ const abbyElement = await findByText ( 'Abby' ) ; // Should show editor for new costume
137+ await elementIsVisible ( abbyElement ) ;
138+ await driver . navigate ( ) . back ( ) ;
139+ try {
140+ // should throw error because library is no longer visible
141+ await elementIsVisible ( abbyElement ) ;
142+ throw 'ShouldNotGetHere' ; // eslint-disable-line no-throw-literal
143+ } catch ( e ) {
144+ expect ( e . constructor . name ) . toEqual ( 'StaleElementReferenceError' ) ;
145+ }
146+ const costumesElement = await findByText ( 'Costumes' ) ; // Should show editor for new costume
147+ await elementIsVisible ( costumesElement ) ;
148+ const logs = await getLogs ( ) ;
149+ await expect ( logs ) . toEqual ( [ ] ) ;
150+ } ) ;
151+
127152} ) ;
You can’t perform that action at this time.
0 commit comments