1515 */
1616package org .labkey .test .selenium ;
1717
18- import org .apache .commons .lang3 .mutable .Mutable ;
19- import org .apache .commons .lang3 .mutable .MutableObject ;
2018import org .jetbrains .annotations .NotNull ;
2119import org .junit .Assert ;
2220import org .junit .Test ;
2321import org .labkey .test .Locator ;
2422import org .labkey .test .WebDriverWrapper ;
2523import org .labkey .test .components .core .ProjectMenu ;
24+ import org .labkey .test .util .CachingSupplier ;
2625import org .labkey .test .util .TestLogger ;
2726import org .labkey .test .util .selenium .ScrollUtils ;
2827import org .labkey .test .util .selenium .WebDriverUtils ;
4443import java .util .List ;
4544import java .util .regex .Matcher ;
4645import java .util .regex .Pattern ;
47- import java .util .stream .Collectors ;
46+
47+ import static org .apache .commons .lang3 .StringUtils .trimToEmpty ;
4848
4949public class ReclickingWebElement extends WebElementDecorator
5050{
@@ -68,7 +68,7 @@ public void click()
6868 {
6969 if (getDriver () != null )
7070 {
71- final String shortMessage = ex .getMessage ().split ("\n " )[0 ];
71+ final String shortMessage = trimToEmpty ( ex .getMessage () ).split ("\n " )[0 ];
7272 TestLogger .debug ("Retry click: " + shortMessage );
7373 revealElement (getWrappedElement (), shortMessage );
7474 super .click ();
@@ -84,7 +84,7 @@ public void click()
8484 && getDriver ().getClass ().isAssignableFrom (FirefoxDriver .class ))
8585 {
8686 String tagName = getWrappedElement ().getTagName ();
87- List <String > classes = Arrays .asList (getWrappedElement ().getAttribute ("class" ). toLowerCase (). trim ().split ("\\ s" ));
87+ List <String > classes = Arrays .asList (trimToEmpty ( getWrappedElement ().getAttribute ("class" )). toLowerCase ().split ("\\ s" ));
8888 if ("tr" .equals (tagName ))
8989 {
9090 if (!clickRowInFirefox ())
@@ -123,7 +123,7 @@ private void actionClick()
123123 */
124124 private void clickImageMapArea ()
125125 {
126- String shape = getWrappedElement ().getAttribute ("shape" );
126+ String shape = trimToEmpty ( getWrappedElement ().getAttribute ("shape" ) );
127127 if (shape .equals ("default" ))
128128 {
129129 throw new IllegalArgumentException ("Refusing to click the 'default' <area> of an image map. Can't guarantee that it won't click a different <area> instead" );
@@ -146,13 +146,13 @@ private void clickImageMapArea()
146146 /**
147147 * Calculate the center of a convex <area> in an image-map. Can handle 'rect', 'circle', and 'poly' shapes
148148 * Doc: <a href="https://www.w3schools.com/tags/tag_area.asp">tag_area</a>
149- * TODO: Implement this formula for concave polygons [https://en.wikipedia.org/wiki/Centroid#Of_a_polygon]
149+ * Does not handle concave polygons [https://en.wikipedia.org/wiki/Centroid#Of_a_polygon]
150150 * @return The center point of the area element relative to the image
151151 */
152152 @ NotNull
153153 private Point getAreaCenter ()
154154 {
155- List <Integer > coords = Arrays .stream (getWrappedElement ().getAttribute ("coords" ).split ("," )).map (Integer ::parseInt ).collect ( Collectors . toList () );
155+ List <Integer > coords = Arrays .stream (trimToEmpty ( getWrappedElement ().getAttribute ("coords" )) .split ("," )).map (Integer ::parseInt ).toList ();
156156 int minX = Integer .MAX_VALUE ;
157157 Integer maxX = 0 ;
158158 int minY = Integer .MAX_VALUE ;
@@ -223,7 +223,7 @@ private void revealElement(WebElement el, String shortMessage)
223223 if (interceptingElements .size () == 1 )
224224 {
225225 //noinspection ResultOfMethodCallIgnored
226- WebDriverWrapper .waitFor (() -> ExpectedConditions .stalenessOf (interceptingElements .get ( 0 )).apply (getDriver ()), 1_000 );
226+ WebDriverWrapper .waitFor (() -> ExpectedConditions .stalenessOf (interceptingElements .getFirst ( )).apply (getDriver ()), 1_000 );
227227 }
228228 else if (interceptingElements .size () > 1 )
229229 {
@@ -262,20 +262,17 @@ private static Locator.XPathLocator parseInterceptingElementLoc(String shortMess
262262 return interceptingElLoc ;
263263 }
264264
265- private Mutable <WebDriver > _webDriver = null ;
265+ private final CachingSupplier <WebDriver > _webDriver = new CachingSupplier <>(() -> WebDriverUtils . extractWrappedDriver ( getWrappedElement ())) ;
266266 private WebDriver getDriver ()
267267 {
268- if (_webDriver == null )
269- {
270- _webDriver = new MutableObject <>(WebDriverUtils .extractWrappedDriver (getWrappedElement ()));
271- }
272- return _webDriver .getValue ();
268+ return _webDriver .get ();
273269 }
274270
275- public static class TempEceptionParser
271+ // Run manually to test parsing of exception message
272+ public static class TempExceptionParserTest
276273 {
277274 @ Test
278- public void testInterceptinElLoc ()
275+ public void testInterceptingElLoc ()
279276 {
280277 final Locator .XPathLocator xPathLocator = parseInterceptingElementLoc ("Element <a href=\" something\" > is not clickable at point (732,301) because another element " +
281278 "<div id=\" elId\" class=\" cls1 cls2\" > obscures it" );
0 commit comments