66
77
88import java .io .InputStream ;
9+ import java .net .MalformedURLException ;
910import java .net .URL ;
1011import java .util .LinkedList ;
1112import java .util .List ;
@@ -302,15 +303,21 @@ public boolean hasSelectOption(String selectName, String optionLabel) {
302303
303304 public boolean hasSelectOptionValue (String selectName , String optionValue ) {
304305 try {
305- getSelectOptionLabelForValue (selectName , optionValue );
306- return true ;
306+ return getSelectOptionLabelForValue (selectName , optionValue ) != null ;
307307 } catch (SeleniumException e ) {
308308 return false ;
309309 }
310310 }
311311
312312 public boolean hasSelectOption (String selectName , int index , String optionLabel ) {
313- return false ;
313+ boolean equals ;
314+ try {
315+ equals = getSelectedOptions (selectName )[index ].equals (optionLabel );
316+ } catch (RuntimeException e ) {
317+ logger .error ("" , e );
318+ equals = false ;
319+ }
320+ return equals ;
314321 }
315322
316323 public boolean hasSelectOptionValue (String selectName , int index , String optionValue ) {
@@ -388,13 +395,31 @@ public boolean isCheckboxSelected(String checkBoxName, String checkBoxValue) {
388395
389396
390397 public boolean isMatchInElement (String elementID , String regexp ) {
391- //TODO Implement isMatchInElement in SeleniumDialog
392- throw new UnsupportedOperationException ("isMatchInElement" );
398+ boolean match ;
399+ try {
400+ String locator = "id=" + elementID ;
401+ String elementText = selenium .getText (locator );
402+ if (elementText == null || elementText .equals ("" )) elementText = selenium .getValue (locator );
403+ match = (elementText != null ? elementText .matches (regexp ) : false );
404+ } catch (RuntimeException e ) {
405+ logger .error ("" , e );
406+ match = false ;
407+ }
408+ return match ;
393409 }
394410
395411 public boolean isTextInElement (String elementID , String text ) {
396- // TODO Implement isTextInElement in SeleniumDialog
397- throw new UnsupportedOperationException ("isTextInElement" );
412+ boolean contains ;
413+ try {
414+ String locator = "id=" + elementID ;
415+ String elementText = selenium .getText (locator );
416+ if (elementText == null || elementText .equals ("" )) elementText = selenium .getValue (locator );
417+ contains = (elementText != null ? elementText .contains (text ) : false );
418+ } catch (RuntimeException e ) {
419+ logger .error ("" , e );
420+ contains = false ;
421+ }
422+ return contains ;
398423 }
399424
400425 public void refresh () {
@@ -408,11 +433,17 @@ public void reset() {
408433 }
409434
410435 public void selectOptions (String selectName , String [] optionsValue ) {
411- for (int i =0 ; i <optionsValue .length ; i ++) {
412- selenium .addSelection ("xpath=" + formSelector () + "//select[@name='" +selectName +"']" ,"value=" +optionsValue [i ]);
436+ if (optionsValue .length == 1 ) {
437+ selenium .select ("xpath=" + formSelector () + "//select[@name='" + selectName + "']" ,
438+ optionsValue [0 ]);
439+ } else {
440+ for (int i = 0 ; i < optionsValue .length ; i ++) {
441+ selenium .addSelection ("xpath=" + formSelector () + "//select[@name='" + selectName + "']" ,
442+ "value=" + optionsValue [i ]);
443+ }
413444 }
414445 }
415-
446+
416447 public void selectOptions (String selectName , int index , String [] optionsValue ) {
417448 }
418449
@@ -569,12 +600,15 @@ public InputStream getInputStream(URL url) throws TestingEngineResponseException
569600 throw new UnsupportedOperationException ("getInputStream" );
570601 }
571602
572- /* (non-Javadoc)
573- * @see net.sourceforge.jwebunit.api.ITestingEngine#getPageURL()
574- */
575603 public URL getPageURL () {
576- // TODO Auto-generated method stub
577- throw new UnsupportedOperationException ("getPageURL" );
604+ URL url ;
605+ try {
606+ url = new URL (selenium .getLocation ());
607+ } catch (MalformedURLException e ) {
608+ logger .error ("" , e );
609+ url = null ;
610+ }
611+ return url ;
578612 }
579613
580614 /* (non-Javadoc)
0 commit comments