1313import org .labkey .test .util .ext4cmp .Ext4FieldRef ;
1414import org .labkey .test .util .ext4cmp .Ext4GridRef ;
1515import org .openqa .selenium .By ;
16+ import org .openqa .selenium .Point ;
1617import org .openqa .selenium .StaleElementReferenceException ;
1718import org .openqa .selenium .WebElement ;
1819
@@ -25,13 +26,19 @@ public class JBrowseTestHelper
2526 public static final File MGAP_TEST_VCF = new File (TestFileUtils .getLabKeyRoot (), "server/modules/DiscvrLabKeyModules/jbrowse/resources/web/jbrowse/mgap/mGap.v2.1.subset.vcf.gz" );
2627 public static final File GRCH37_GENOME = new File (TestFileUtils .getLabKeyRoot (), "server/modules/DiscvrLabKeyModules/jbrowse/resources/web/jbrowse/mgap/GRCh37_small.fasta" );
2728
28- public static < T > Collector <T , ?, T > toSingleton () {
29+ public static Collector <WebElement , ?, WebElement > toSingleton () {
2930 return Collectors .collectingAndThen (
3031 Collectors .toList (),
3132 list -> {
3233 if (list .size () != 1 ) {
33- throw new IllegalStateException ("Expected single element, found: " + list .size ());
34+ long uniqueLocations = list .stream ().map (WebElement ::getLocation ).distinct ().count ();
35+ if (uniqueLocations == 1 ) {
36+ return list .get (0 );
37+ }
38+
39+ throw new IllegalStateException ("Expected single element, found: " + list .size () + ", " + list .stream ().map (WebElement ::getLocation ).map (Point ::toString ).collect (Collectors .joining (" / " )));
3440 }
41+
3542 return list .get (0 );
3643 }
3744 );
@@ -128,10 +135,19 @@ public static Locator.XPathLocator getTrackLocator(BaseWebDriverTest test, Strin
128135 }
129136
130137 public static By getVariantWithinTrack (BaseWebDriverTest test , String trackId , String variantText )
138+ {
139+ return getVariantWithinTrack (test , trackId , variantText , true );
140+ }
141+
142+ public static By getVariantWithinTrack (BaseWebDriverTest test , String trackId , String variantText , boolean appendPolygon )
131143 {
132144 Locator .XPathLocator l = getTrackLocator (test , trackId , true );
133145 test .waitForElementToDisappear (Locator .tagWithText ("p" , "Loading" ));
134- l = l .append (Locator .xpath ("//*[name()='text' and contains(text(), '" + variantText + "')]" )).notHidden ().append ("/.." );
146+ l = l .append (Locator .xpath ("//*[name()='text' and contains(text(), '" + variantText + "')]" )).notHidden ().parent ();
147+ if (appendPolygon ){
148+ l = l .append ("/*[name()='polygon']" );
149+ }
150+
135151 test .waitForElement (l );
136152
137153 return By .xpath (l .toXpath ());
@@ -153,14 +169,16 @@ public static long getTotalVariantFeatures(BaseWebDriverTest test)
153169 Locator l = Locator .tagWithAttribute ("svg" , "data-testid" , "svgfeatures" ).append (Locator .tag ("polygon" ));
154170 try
155171 {
156- return Locator .findElements (test .getDriver (), l ).stream ().filter (WebElement ::isDisplayed ).count ();
172+ // NOTE: JBrowse renders features using multiple blocks per track, and these tracks can redundantly render identical features on top of one another.
173+ // Counting unique locations is indirect, but should result in unique features
174+ return Locator .findElements (test .getDriver (), l ).stream ().filter (WebElement ::isDisplayed ).map (WebElement ::getLocation ).distinct ().count ();
157175 }
158176 catch (StaleElementReferenceException e )
159177 {
160178 test .log ("Stale elements, retrying" );
161179 WebDriverWrapper .sleep (5000 );
162180
163- return Locator .findElements (test .getDriver (), l ).stream ().filter (WebElement ::isDisplayed ).count ();
181+ return Locator .findElements (test .getDriver (), l ).stream ().filter (WebElement ::isDisplayed ).map ( WebElement :: getLocation ). distinct (). count ();
164182 }
165183 }
166184}
0 commit comments