سؤال

I am trying to utilise the global variables to store some data in my spock specs but not sure about the implementation. The reason for this is to utilise the values from the profile of the user and verify it at the time of check out. To be precise, I login and navigate to the user profile. I need to be able to store the address details and user details in Global variables. When I order something, I would like to verify the delivery details before checking out an item.

Is there way to utilise Global variables in When block.

An Edited example below:

Declared a global variable inside the Spock Specification (called "buyerNameValue")

And tried to store the value of an element inside that variable to be used later:

def "Store User details"() {

when:
    assert at(UserProfilePage)
    buyerNameValue      << buyerName.text() 
    println(buyerNameValue) // To see if the value is being captured
    buyerAddressValue   << buyerAddress.text()
    println(buyerAddressValue)
    landingPage.click()
then:
    assert at(LandingPage)  

}

هل كانت مفيدة؟

المحلول

I declared the global variables but when I tried to fetch the values from an element it was throwing an error stating the assignment operator is not allowed in when block.

Also I couldn't use the <<operator either. These are only allowed in the where block of Spock spec.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top