【问题标题】:Using alert.accept() multiple times does not function properly多次使用 alert.accept() 无法正常工作
【发布时间】:2013-09-26 02:40:00
【问题描述】:

您好,我目前是使用 Python 成为自动化 QA(Splinter)测试员的新手,我想做的是测试支付页面,看看是否有提示,如果必填字段为空,然后登录记事本。

我的问题是,当我使用alert.accept() 两次时,它不会在第二次运行。

例如: 第一个提示应该是“事务类型输入被困”,然后我使用alert.accept() 关闭提示。但是第二次它不起作用,提示只是停留在原处,并且在我使用alert.accept() 时不会自动单击确定按钮。为什么是这样?当我同时使用两个警报时,我是否遗漏了一条规则?

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 是我的功能,我将报告记录到记事本

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

我正在使用的库是 splinter

【问题讨论】:

  • 你用的是什么库?
  • 我使用的库是分裂的

标签: python automated-tests splinter


【解决方案1】:

我通过创建两个函数来检查不同的字段来解决这个问题,但我不确定它为什么会起作用,我也不喜欢它,当你可以创建一个具有相同功能的函数时为什么要创建两个函数。

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")

如果你们对此问题有其他解决方案,我愿意接受建议,因为我不喜欢我刚刚所做的修复。谢谢

【讨论】:

    猜你喜欢
    • 2011-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    • 1970-01-01
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多