11package uk .co .evoco .webdriver .utils ;
22
33import com .codahale .metrics .Timer ;
4+ import org .openqa .selenium .By ;
5+ import org .openqa .selenium .WebDriver ;
46import org .openqa .selenium .WebElement ;
57import org .openqa .selenium .support .ui .Select ;
68import uk .co .evoco .metrics .MetricRegistryHelper ;
@@ -24,6 +26,10 @@ public final class SelectBoxUtils extends TolerantInteraction {
2426 private static final Timer tolerantItemByVisibleTextAction = MetricRegistryHelper .get ().timer (name ("SelectBoxUtils.tolerantItemByVisibleText" ));
2527 private static final Timer tolerantItemByIndexAction = MetricRegistryHelper .get ().timer (name ("SelectBoxUtils.tolerantItemByIndex" ));
2628
29+ public SelectBoxUtils (WebDriver webDriver ) {
30+ super (webDriver );
31+ }
32+
2733 /**
2834 * Selects an option that has a matching value attribute in the Options tag markup
2935 * @param selectBox active WebElement, already located
@@ -65,85 +71,106 @@ public static void itemByVisibleText(WebElement selectBox, String visibleText) {
6571 }
6672
6773 /**
74+ * @param webDriver
6875 * @param webElement active WebElement, already located
6976 * @param htmlValue HTML value attribute
7077 * @param timeout time in seconds to keep trying
7178 * @throws Throwable any unhandled or un-tolerated exception
7279 */
73- public static void tolerantItemByHtmlValueAttribute (WebElement webElement , String htmlValue , int timeout )
80+ public static void tolerantItemByHtmlValueAttribute (WebDriver webDriver , WebElement webElement , String htmlValue , int timeout )
7481 throws Throwable {
7582 try (final Timer .Context ignored = tolerantItemByHtmlValueAttributeAction .time ()) {
76- new SelectBoxUtils ().tolerantInteraction (
83+ new SelectBoxUtils (webDriver ).tolerantInteraction (
7784 webElement , SelectBoxInteractionType .BY_VALUE , Optional .of (htmlValue ), Optional .empty (), timeout );
7885 }
7986 }
8087
8188 /**
89+ * @param webDriver
8290 * @param webElement active WebElement, already located
8391 * @param htmlValue HTML value attribute
8492 * @throws Throwable any unhandled or un-tolerated exception
8593 */
86- public static void tolerantItemByHtmlValueAttribute (WebElement webElement , String htmlValue )
94+ public static void tolerantItemByHtmlValueAttribute (WebDriver webDriver , WebElement webElement , String htmlValue )
8795 throws Throwable {
8896 try (final Timer .Context ignored = tolerantItemByHtmlValueAttributeAction .time ()) {
89- new SelectBoxUtils ().tolerantInteraction (
97+ new SelectBoxUtils (webDriver ).tolerantInteraction (
9098 webElement , SelectBoxInteractionType .BY_VALUE , Optional .of (htmlValue ), Optional .empty (),
9199 TestConfigHelper .get ().getTolerantActionWaitTimeoutInSeconds ());
92100 }
93101 }
94102
95103 /**
104+ * @param webDriver
96105 * @param webElement active WebElement, already located
97106 * @param visibleText visible text in the select box (NOT the HTML value attribute)
98107 * @param timeout time in seconds to keep trying
99108 * @throws Throwable any unhandled or un-tolerated exception
100109 */
101- public static void tolerantItemByVisibleText (WebElement webElement , String visibleText , int timeout )
110+ public static void tolerantItemByVisibleText (WebDriver webDriver , WebElement webElement , String visibleText , int timeout )
102111 throws Throwable {
103112 try (final Timer .Context ignored = tolerantItemByVisibleTextAction .time ()) {
104- new SelectBoxUtils ().tolerantInteraction (
113+ new SelectBoxUtils (webDriver ).tolerantInteraction (
105114 webElement , SelectBoxInteractionType .BY_VISIBLE_TEXT ,
106115 Optional .of (visibleText ), Optional .empty (), timeout );
107116 }
108117 }
109118
110119 /**
111- *
120+ * @param webDriver
112121 * @param webElement active WebElement, already located
113122 * @param visibleText visible text in the select box (NOT the HTML value attribute)
114123 * @throws Throwable any unhandled or un-tolerated exception
115124 */
116- public static void tolerantItemByVisibleText (WebElement webElement , String visibleText )
125+ public static void tolerantItemByVisibleText (WebDriver webDriver , WebElement webElement , String visibleText )
117126 throws Throwable {
118127 try (final Timer .Context ignored = tolerantItemByVisibleTextAction .time ()) {
119- new SelectBoxUtils ().tolerantInteraction (
128+ new SelectBoxUtils (webDriver ).tolerantInteraction (
120129 webElement , SelectBoxInteractionType .BY_VISIBLE_TEXT ,
121130 Optional .of (visibleText ), Optional .empty (),
122131 TestConfigHelper .get ().getTolerantActionWaitTimeoutInSeconds ());
123132 }
124133 }
125134
126135 /**
136+ * @param webDriver
137+ * @param locator
138+ * @param visibleText
139+ * @throws Throwable
140+ */
141+ public static void tolerantItemByVisibleText (WebDriver webDriver , By locator , String visibleText )
142+ throws Throwable {
143+ try (final Timer .Context ignored = tolerantItemByVisibleTextAction .time ()) {
144+ new SelectBoxUtils (webDriver ).tolerantInteraction (
145+ locator , SelectBoxInteractionType .BY_VISIBLE_TEXT ,
146+ Optional .of (visibleText ), Optional .empty (),
147+ TestConfigHelper .get ().getTolerantActionWaitTimeoutInSeconds ());
148+ }
149+ }
150+
151+ /**
152+ * @param webDriver
127153 * @param webElement active WebElement, already located
128154 * @param index index in order of display
129155 * @param timeout time in seconds to keep trying
130156 * @throws Throwable any unhandled or un-tolerated exception
131157 */
132- public static void tolerantItemByIndex (WebElement webElement , int index , int timeout ) throws Throwable {
158+ public static void tolerantItemByIndex (WebDriver webDriver , WebElement webElement , int index , int timeout ) throws Throwable {
133159 try (final Timer .Context ignored = tolerantItemByIndexAction .time ()) {
134- new SelectBoxUtils ().tolerantInteraction (
160+ new SelectBoxUtils (webDriver ).tolerantInteraction (
135161 webElement , SelectBoxInteractionType .BY_INDEX , Optional .empty (), Optional .of (index ), timeout );
136162 }
137163 }
138164
139165 /**
166+ * @param webDriver
140167 * @param webElement active WebElement, already located
141168 * @param index index in order of display
142169 * @throws Throwable any unhandled or un-tolerated exception
143170 */
144- public static void tolerantItemByIndex (WebElement webElement , int index ) throws Throwable {
171+ public static void tolerantItemByIndex (WebDriver webDriver , WebElement webElement , int index ) throws Throwable {
145172 try (final Timer .Context ignored = tolerantItemByIndexAction .time ()) {
146- new SelectBoxUtils ().tolerantInteraction (
173+ new SelectBoxUtils (webDriver ).tolerantInteraction (
147174 webElement , SelectBoxInteractionType .BY_INDEX , Optional .empty (), Optional .of (index ),
148175 TestConfigHelper .get ().getTolerantActionWaitTimeoutInSeconds ());
149176 }
0 commit comments