4848import org .labkey .test .util .ext4cmp .Ext4FieldRef ;
4949import org .labkey .test .util .external .labModules .LabModuleHelper ;
5050import org .openqa .selenium .By ;
51+ import org .openqa .selenium .JavascriptExecutor ;
5152import org .openqa .selenium .Keys ;
5253import org .openqa .selenium .WebElement ;
5354import org .openqa .selenium .interactions .Actions ;
@@ -91,7 +92,7 @@ public void testSteps() throws Exception
9192 testTitleMapping ();
9293 testPredictedFunction ();
9394 testAlleleFrequencies ();
94- testGenotypeFrequencies ();
95+ // testGenotypeFrequencies();
9596
9697 testColorWidget ();
9798 testDefaultColorApplied ();
@@ -141,19 +142,19 @@ private void testColorWidget()
141142 // We expect IMPACT to be the default scheme
142143 assertElementPresent (Locator .tagWithText ("td" , "HIGH" ));
143144 assertBoxWithColorPresent ("#ff0000" ); // red
144- waitForElement ( Locator . tagWithAttribute ( "polygon" , "fill" , "red" ) );
145+ waitForCanvasColorPresent ( "#ff0000" );
145146
146147 assertElementPresent (Locator .tagWithText ("td" , "MODERATE" ));
147148 assertBoxWithColorPresent ("#DAA520" ); //"goldenrod"
148- assertElementPresent ( Locator . tagWithAttribute ( "polygon" , "fill" , "goldenrod" ) );
149+ waitForCanvasColorPresent ( "#daa520" );
149150
150151 assertElementPresent (Locator .tagWithText ("td" , "LOW" ));
151152 assertBoxWithColorPresent ("#049931" );
152- assertElementPresent ( Locator . tagWithAttribute ( "polygon" , "fill" , " #049931") );
153+ waitForCanvasColorPresent ( " #049931" );
153154
154155 assertElementPresent (Locator .tagWithText ("td" , "Other" ));
155156 assertBoxWithColorPresent ("#808080" ); //gray
156- assertElementPresent ( Locator . tagWithAttribute ( "polygon" , "fill" , "gray" ) );
157+ waitForCanvasColorPresent ( "#808080" );
157158
158159 // Now toggle to Allele Freq.:
159160 waitAndClick (Locator .tagWithText ("div" , "Predicted Impact" ));
@@ -164,7 +165,7 @@ private void testColorWidget()
164165
165166 clickDialogButton ("Apply" );
166167
167- waitForElement ( Locator . tagWithAttribute ( "polygon" , "fill" , "#2425E0" ) );
168+ waitForCanvasColorPresent ( "#2425e0" );
168169 }
169170
170171 private void assertBoxWithColorPresent (final String expectedColor )
@@ -184,6 +185,48 @@ private void clickDialogButton(String text)
184185 waitAndClick (Locator .XPathLocator .tagWithClass ("button" , "MuiButtonBase-root" ).withText (text ));
185186 }
186187
188+ private void waitForCanvasColorPresent (final String expectedColor )
189+ {
190+ final long timeoutMs = WAIT_FOR_JAVASCRIPT ;
191+ final long start = System .currentTimeMillis ();
192+
193+ while (System .currentTimeMillis () - start < timeoutMs )
194+ {
195+ if (isCanvasColorPresent (expectedColor ))
196+ return ;
197+
198+ sleep (250 );
199+ }
200+
201+ Assert .fail ("Unable to find color in any canvas: " + expectedColor );
202+ }
203+
204+ private boolean isCanvasColorPresent (final String expectedColor )
205+ {
206+ final String script = "const expected = (arguments[0] || '').toLowerCase();\n "
207+ + "const toHex = (v) => v.toString(16).padStart(2, '0');\n "
208+ + "const canvases = Array.from(document.querySelectorAll('canvas'));\n "
209+ + "for (const canvas of canvases) {\n "
210+ + " try {\n "
211+ + " const ctx = canvas.getContext('2d');\n "
212+ + " if (!ctx || canvas.width === 0 || canvas.height === 0) continue;\n "
213+ + " const data = ctx.getImageData(0, 0, canvas.width, canvas.height).data;\n "
214+ + " for (let i = 0; i < data.length; i += 4) {\n "
215+ + " const a = data[i + 3];\n "
216+ + " if (!a) continue;\n "
217+ + " const hex = '#' + toHex(data[i]) + toHex(data[i + 1]) + toHex(data[i + 2]);\n "
218+ + " if (hex === expected) return true;\n "
219+ + " }\n "
220+ + " } catch (e) {\n "
221+ + " // Ignore canvases we cannot sample\n "
222+ + " }\n "
223+ + "}\n "
224+ + "return false;" ;
225+
226+ Object ret = ((JavascriptExecutor ) getDriver ()).executeScript (script , expectedColor );
227+ return ret instanceof Boolean && (Boolean ) ret ;
228+ }
229+
187230 private void testBrowserNavToVariantTable () throws Exception
188231 {
189232 beginAt ("/" + getProjectName () + "/jbrowse-jbrowse.view?session=mgap" );
@@ -201,7 +244,7 @@ private void testDefaultColorApplied()
201244 waitForJBrowseToLoad ();
202245
203246 // Indicates AF scheme applied:
204- waitForElement ( Locator . tagWithAttribute ( "polygon" , "fill" , "#9A1764" ) );
247+ waitForCanvasColorPresent ( "#9a1764" );
205248
206249 openTrackMenuItem ("Color Selection" );
207250 waitForElement (Locator .tagWithText ("h6" , "Color Schemes" ));
@@ -217,7 +260,7 @@ private void testDefaultColorApplied()
217260 clickDialogButton ("Apply" );
218261
219262 // Indicates the IMPACT scheme applies:
220- waitForElement ( Locator . tagWithAttribute ( "polygon" , "fill" , "gray" ) );
263+ waitForCanvasColorPresent ( "#808080" );
221264 }
222265
223266 private void testAFColor ()
@@ -237,7 +280,7 @@ private void testAFColor()
237280 assertBoxWithColorPresent ("#808080" ); //gray
238281
239282 clickDialogButton ("Apply" );
240- waitForElement ( Locator . tagWithAttribute ( "polygon" , "fill" , "#9A1764" ) );
283+ waitForCanvasColorPresent ( "#9a1764" );
241284 }
242285
243286 private void testFilterWidget ()
@@ -292,7 +335,7 @@ private void testFilterWidget()
292335 sleep (1000 );
293336
294337 // NOTE: depending on the size of the view area, this can vary. This is more a factor of the environment that actual behavior
295- Assert .assertEquals ("Incorrect number of variants" , 87 .0 , getTotalVariantFeatures (), 1.0 );
338+ Assert .assertEquals ("Incorrect number of variants" , 96 .0 , getTotalVariantFeatures (), 1.0 );
296339
297340 // bottom filter UI
298341 waitForElement (Locator .tagContainingText ("button" , "mGAP: Showing sites where" ).containing ("AF < 0.02" ));
@@ -311,7 +354,7 @@ private void testLoadingConfigFilters(){
311354 getDriver ().findElements (getVariantWithinTrack ("mgap_hg38" , "SNV T -> G" ));
312355 getDriver ().findElements (getVariantWithinTrack ("mgap_hg38" , "SNV A -> T" ));
313356
314- Assert .assertEquals ("Incorrect number of variants" , 7 , getTotalVariantFeatures ());
357+ Assert .assertEquals ("Incorrect number of variants" , 9 , getTotalVariantFeatures ());
315358
316359 // bottom filter UI
317360 waitForElement (Locator .tagContainingText ("button" , "mGAP: Showing sites with a variant in any of:" ).containing ("m00004,m00005" ));
@@ -339,7 +382,7 @@ private void testSampleFilters()
339382 getDriver ().findElements (getVariantWithinTrack ("mgap_hg38" , "SNV A -> T" ));
340383
341384 // NOTE: depending on the size of the view area, this can vary. This is more a factor of the environment that actual behavior
342- Assert .assertEquals ("Incorrect number of variants" , 37 .0 , getTotalVariantFeatures (), 1 );
385+ Assert .assertEquals ("Incorrect number of variants" , 42 .0 , getTotalVariantFeatures (), 1 );
343386
344387 openTrackMenuItem ("Filter By Sample" );
345388 waitForElement (Locator .tagWithText ("h6" , "Filter By Sample" ));
@@ -348,7 +391,7 @@ private void testSampleFilters()
348391 Locator .findElements (getDriver (), textArea ).get (0 ).sendKeys ("m00010" );
349392 clickDialogButton ("Apply" );
350393
351- Assert .assertEquals ("Incorrect number of variants" , 3 , getTotalVariantFeatures ());
394+ Assert .assertEquals ("Incorrect number of variants" , 4 , getTotalVariantFeatures ());
352395 }
353396
354397 private void testInferredDetails ()
0 commit comments