[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Watir and regexp

asmir.biscevic

11/2/2006 10:22:00 AM

We want to test a value given in a text field with a regular
expression. We are trying to do it this way:

@browser.text_field(:name,"vareeier").set("123456789")
@browser.text_field(:name,"vareeier").value.should_equal(/[0-9]{9}/)

This is not working for us. We also tried using
@browser.text_field(:name,"vareeier").value.matches(/[0-9]{9}/)
@browser.text_field(:name,"vareeier").verify_contains(/[0-9]{9}/)

None of these work.
Help....

1 Answer

Paul Lutus

11/2/2006 12:32:00 PM

0

asmir.biscevic@gmail.com wrote:

> We want to test a value given in a text field with a regular
> expression. We are trying to do it this way:
>
> @browser.text_field(:name,"vareeier").set("123456789")
> @browser.text_field(:name,"vareeier").value.should_equal(/[0-9]{9}/)
>
> This is not working for us. We also tried using
> @browser.text_field(:name,"vareeier").value.matches(/[0-9]{9}/)
> @browser.text_field(:name,"vareeier").verify_contains(/[0-9]{9}/)
>
> None of these work.

Define "work". Have you take the step of creating a test regex that must
succeed, in order to eliminate syntax errors other than regex ones?

> Help....

I can't help you with any Watir syntax issues that may be present, but the
regex would be better written as:

/^\d{9}$/

This assures that nine consecutive digits are all that is present in the
field. Your original regex only assured that nine consecutive digits were
present somewhere in a field that could contain an arbitrary amount of
other data.

--
Paul Lutus
http://www.ara...