eskoba
eskoba

Reputation: 566

can't pass value to the input fied in test case

I would like to pass a value to the input fied, in the test case. however this is not working. Below is my code.

   class Mypage extends Page {
    static content = { 

       inputfield { withFrame ("myFrame") {$('input',name:'myInputField') } 

    }
   }
 }

Then tested it this way:

given:
    String thevalue = "hello"
then:
    to Mypage
and:
    inputfield >> thevalue

With this code I get the

StaleElementReference error and the chrome driver information

I then tried the following by putting the thevalue variable in Mypage class:

class Mypage extends Page {

      public  String thevalue = "hello"

      static content = { 

           inputfield { withFrame ("myFrame") 
{$('input',name:'myInputField') } 


    }
   }
 }

Then tested it the same way with no given:

then:
    to Mypage
and:
    inputfield >> thevalue

I Still get the same error.

I then tried a third form:

class Mypage extends Page {

      //public  String thevalue = "hello"

      static content = { 

           inputfield { withFrame ("myFrame") 
{ thevalue -> $('input',name:'myInputField').value(thevalue ) } 


    }
   }
 }

Then tested it in 2 ways:

then:
    to Mypage
and:
    inputfield("hello")

and this way:

then:
    to Mypage
and:
    inputfield >> "hello"

The only way which is working is when I pass the value directly in the class

         inputfield { withFrame ("myFrame") 
{  $('input',name:'myInputField').value("hello") } 

But the goal is to the pass the value in the test. How do I do that

Upvotes: 0

Views: 64

Answers (2)

erdi
erdi

Reputation: 6954

If you really don't want to follow Rushby's suggestion and stick to the path you shown in your question then the following will work:

class Mypage extends Page {
    static content = { 
        inputfield { thevalue ->
            withFrame ("myFrame") { 
                $('input',name:'myInputField').value(thevalue) 
            } 
        }
    }
}

and

then:
    to Mypage
and:
    inputfield("hello")

Upvotes: 1

Rushby
Rushby

Reputation: 889

If you follow the Geb example from The Book of Geb you have your page and it contains an iframe. The iframe in the example has its own page object:

class PageWithFrame extends Page {
    static content = {
        myFrame(page: FrameDescribingPage) { $('#frame-id') }
    }
}

//This is your iframe page object
class FrameDescribingPage extends Page {
    static content = {
        myTextField { $('input',name:'myInputField') }
    }
}

Now to interact with it, you do this within your test method:

def "my test method"() {
when: 
   to PageWithFrame
   withFrame(myFrame) {
       myTextField.value("whatever")
   }
   //etc
 }

Upvotes: 1

Related Questions