1717
1818import org .apache .commons .lang3 .StringUtils ;
1919import org .jetbrains .annotations .Nullable ;
20+ import org .junit .Assert ;
2021import org .labkey .test .BaseWebDriverTest ;
2122import org .labkey .test .Locator ;
23+ import org .labkey .test .WebDriverWrapper ;
2224import org .labkey .test .util .DataRegionTable ;
2325import org .labkey .test .util .Ext4Helper ;
2426import org .labkey .test .util .UIAssayHelper ;
2527import org .labkey .test .util .ext4cmp .Ext4CmpRef ;
2628import org .labkey .test .util .ext4cmp .Ext4ComboRef ;
2729import org .labkey .test .util .ext4cmp .Ext4FieldRef ;
2830import org .labkey .test .util .ext4cmp .Ext4GridRef ;
31+ import org .openqa .selenium .TimeoutException ;
2932
3033import java .io .File ;
3134import java .text .SimpleDateFormat ;
3235import java .util .List ;
3336import java .util .Random ;
37+ import java .util .Set ;
3438
3539import static org .junit .Assert .assertEquals ;
3640import static org .junit .Assert .assertTrue ;
@@ -248,8 +252,33 @@ public void goToAssayResultImport(String assayName, boolean supportsTemplates)
248252 _test .waitForText ("Data Import" );
249253 }
250254
255+ public String clickAndGetExampleData ()
256+ {
257+ Locator btn = Locator .linkContainingText ("Download Example Data" );
258+ _test .waitForElement (btn );
259+ _test .waitAndClick (btn );
260+
261+ int iterations = 0 ;
262+ while (_test .getDriver ().getWindowHandles ().size () < 2 )
263+ {
264+ iterations ++;
265+ WebDriverWrapper .sleep (100 );
266+
267+ if (iterations > 20 )
268+ {
269+ throw new TimeoutException ("Timed out waiting for second browser window" );
270+ }
271+ }
272+
273+ return getExampleData ();
274+ }
275+
251276 public String getExampleData ()
252277 {
278+ String ret = null ;
279+
280+ Set <String > handles = _test .getDriver ().getWindowHandles ();
281+ Assert .assertTrue ("Expected more than one open window, was: " + handles .size (), handles .size () > 1 );
253282 String currentWindow = _test .getDriver ().getWindowHandle ();
254283 for (String handle : _test .getDriver ().getWindowHandles ())
255284 {
@@ -259,10 +288,13 @@ public String getExampleData()
259288 String text = getPageText ();
260289 _test .getDriver ().close ();
261290 _test .getDriver ().switchTo ().window (currentWindow );
262- return text ;
291+ ret = StringUtils . trimToNull ( text ) ;
263292 }
264293 }
265- return null ;
294+
295+ Assert .assertNotNull ("Unable to retrieve example data" , StringUtils .trimToNull (ret ));
296+
297+ return ret ;
266298 }
267299
268300 public Locator toolIcon (String name )
0 commit comments