0

I'm using WebDriiver, lettuce and python for testing. In first scenario I verifay, that user can create anaccount. For user name I use an e-mail generaror with timestamp. the lettuce step is:

Then input text "NEW_EMAIL" to text field with ID "s-txt-email"

the python code is:

@step('input text "([^"]*)" to text field with ID "([^"]*)"')
def input_with_id(step, txt, ID):
    global new_email
    links = get_driver().find_elements_by_xpath("//input[@id='%s']" % ID)
    if links:
        links[0].click()
    else:
        raise ValueError('Link with ID %s not found' % ID)
    if not "generated_email" in txt:
        timestamp = datetime.now().strftime('%m_%d_%Y.%H_%M')
        new_email = "automation.%s@yopmail.com" % timestamp
        txts = {"NEW_EMAIL": new_email,
                "STANDARD_PSW": "xxxxx",
                "NEW_USER": new_email,
                }
        if txt in txts.keys():
            txt = txts[txt]
    else:
        txt = new_email
    links[0].send_keys(str(txt))

In other scenario I'm using the same code for verify that user can loggin. Lettuce step is:

Then input text "generated_email" to text field with ID "l-txt-email-address"

And python code is the same (see above). But it's generated new e-mail with new timestamp and user can't loggin. What I'm douing wrong? How I can use global variable from one scenario in other one?

  • How have you tried to debug this? I don't see the output from those attempts. If nothing else, you should at least print out **txt** and the result of the **in** test just before the **if not** statement that seems to fail. – Prune Mar 08 '17 at 20:32
  • Which output you want to see? The main idea of this code is generate new email address then send it to element with ID and store this address in global variable new_email to use it in other scenario. this code create new email but don't I can't use global variable in other scenario. My question is how can I store new_email to use it in other scenarios? – Alex Testor Mar 08 '17 at 21:01
  • The usual ways -- as I think you already know -- are to return it as the function result, stuff it into a global, store it in a persistent object, etc. I'm not seeing how/why your current approach doesn't work. – Prune Mar 08 '17 at 22:55

0 Answers0