Question

Hi I am currently new to being a Automated QA (in Splinter) tester using Python, What I want to do is to test a payment page to see if there are prompts if the required fields are empty and log it into the notepad.

My problem is that when I use alert.accept() twice it does not run the second time around.

For example: The first prompt is expected to say "Transaction Type input is trapped" and then I use alert.accept() to close the prompt. But the second time around it does not work the prompt just stays where it is and does not automatically click the ok button when I use alert.accept(). Why is this? Is there a rule i'm missing when i'm using two alerts at the same time?

def checkTrappings():   
    logUtb(f, 'Checking if Transaction type is trapped, making payment with Transaction type as empty')
    browser.find_by_id('submitBtn').first.click()
    alert = browser.get_alert()
    x = str(alert.text) 
    if x == 'Transaction Type is required.':
        logUtb(f, 'Transaction Type input is trapped')
    alert.accept()  
    logUtb(f, "")

    logUtb(f, 'Checking if email is a valid email')
    browser.select('tranType','A')
    browser.find_by_id('submitBtn').first.click()
    alert = browser.get_alert()
    x = str(alert.text)
    if x == 'Please enter a valid email address.':
        logUtb(f, 'Proper email format is trapped')

    alert.accept()  
    logUtb(f, "")

    browser.find_by_id('submitBtn').first.click()
    alert = browser.get_alert()
    x = str(alert.text) 

logUtb by the way is my function where I log the report to the notepad

    def logUtb(fl, strx):
  now = datetime.datetime.now()
  fl.write(now.strftime('%Y-%m-%d %H:%M') + " - " + strx + "\n");
  return;

The library i'm using is splinter

Was it helpful?

Solution

I solved it by making two functions to check different fields but I i'm not sure why it worked and I also don't like it , why make two functions when you can create one with the same functionality.

def checkTrapTransaction(): 
    try:
        logUtb(f, 'Checking if Transaction type is trapped, making payment with Transaction type as empty')
        browser.find_by_id('submitBtn').first.click()
        alert = browser.get_alert()
        x = str(alert.text) 
        if x == 'Transaction Type is required.':
            logUtb(f, 'Transaction Type input is trapped')
        alert.accept()  
        logUtb(f, "")

    except:
        logUtbE(f, "Exception: Please recheck your code")

def checkTrapEmail():
    try:
        logUtb(f, 'Checking if email is a valid email')
        browser.select('tranType','A')
        browser.find_by_id('submitBtn').first.click()
        alert = browser.get_alert()
        x = str(alert.text)
        if x == 'Please enter a valid email address.':
            logUtb(f, 'Proper email format is trapped')

        alert.accept()  
        logUtb(f, "")

    except:
        logUtbE(f, "Exception: Please recheck your code")

If you guys have other solutions to this problem, i'm open to suggestions as I don't like the fix I just made. Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top