Python Selenium TypeError 期望 3 个参数 (1given)

杰伊什·丹达

我无法解决以下问题:

下面是我的 python-selenium 代码。

import unittest
import time
import argparse, sys, os
import traceback
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

class SeleniumTestPack(unittest.TestCase):

    driver = webdriver.Firefox()
    timeout = 30

    def test_all(self):

        admin_base_url = args.url
        cognito_url = "test.auth.us-west-2.amazoncognito.com"
        user_full_name = "test User"
        email = "[email protected]"
        firstName = "Selenium"
        lastName = "User"

        try:

          self.test_redirect_to_congito_login_page(admin_base_url, cognito_url)

          self.delete_geckodriver_log()

        except Exception:

          self.driver.save_screenshot('exception.png')
          self.fail("Exception: %s" % (traceback.format_exc()))

    def test_redirect_to_congito_login_page(self, admin_base_url, cognito_url):
      print "Test navigating to home page redirects to cognito login page"
      self.driver.get(admin_base_url)
      self.wait_for_element_loaded(By.ID, "div-forms")
      page_url = self.driver.current_url
      assert cognito_url in page_url

    def wait_for_element_loaded(self, id_type, id_locator):
      min_timeout = 2
      tries = 0
      retry_limit = 13
      while tries <= retry_limit:
        try:
          tries = tries + 1
          element_present = EC.presence_of_element_located((id_type, id_locator))
          WebDriverWait(self.driver, min_timeout).until(element_present)
          break
        except Exception:
          if tries <= retry_limit:
            continue
          self.fail("Exception waiting for page to load %s : %s" % (id_locator,traceback.format_exc()))

    def delete_geckodriver_log(self):
      #running function at the end of all other invocation ensures all test cases have already ran successfully
      geckodriverfile="geckodriver.log"
      if os.path.isfile(geckodriverfile):
        os.remove(geckodriverfile)
      else:
        print("Error: %s file not found" % geckodriverfile)

    @classmethod
    def tearDown(self):
      # close the browser window
      self.driver.quit()

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='test')
    parser.add_argument('--url',action='store',dest='url',default=None,help='<Required> url link',required=True)
    parser.add_argument('--username',action='store',dest='username',default=None,help='<Required> username',required=True)
    parser.add_argument('--password',action='store',dest='password',default=None,help='<Required> password',required=True)
    parser.add_argument('unittest_args', nargs='*')
    args = parser.parse_args()
    sys.argv[1:] = args.unittest_args
    unittest.main()

我正在使用以下命令运行此测试。

xvfb-run --server-args="-screen 0, 1280x1024x8" python admin-ui-test.py --url 'http://localhost:8080' --username 'test' --password 'test1234'

下面是我的输出:

ERROR: test_redirect_to_congito_login_page (__main__.SeleniumTestPack)  TypeError: test_redirect_to_congito_login_page() takes exactly 3 arguments (1 given)

我做错了什么?我在其他地方也有类似的测试,很长一段时间以来都运行良好。

任何帮助将不胜感激。

杰伊什·丹达

解决方案对我来说非常新。

函数名称不应以“test_”开头(否则将被视为单独的测试用例)

我重命名了函数名,它工作正常!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

python decorator TypeError缺少1个必需的位置参数

TypeError:<lambda>()正好接受1个参数(给定3个)

TypeError:type()接受1或3个参数

Selenium TypeError:__init __()接受2个位置参数,但给出了3个

扭曲-Python3 TypeError:__init __()缺少1个必需的位置参数:“ factory”

PIL内部异常:{TypeError} getsize()恰好接受1个参数(给定3个)

TypeError:javaScriptConfirm()恰好接受1个参数(给定3个)python

TypeError:update()需要2个位置参数,但给出了3个位置:Python

Selenium + Python期望已经找到的特定元素

Python3 TypeError:接受1个位置参数,但给定2个

Python 3错误-TypeError:预期最多输入1个参数,得到3个

TypeError:<lambda>()缺少1个必需的位置参数:使用lambda对python 3字典进行排序时为'count'

TypeError:wrapper()缺少1个必需的位置参数:'num'(python)

pygame错误``战俘期望2个参数,得到1个''

SONATA MY ADMIN:TypeError:trim()期望参数1为字符串,给定对象

函数的参数太少,传递了0个参数,在Laravel中恰好期望1个参数

TypeError:在python中使用mss库为参数'mat'期望的Ptr <cv :: UMat>

这里抛出了TypeError异常:init()接受2个位置参数,但使用Selenium和Python的显式等待给出3个

assert()期望恰好1个参数,给定2个

Python上的TypeError。Missing1个必需的位置参数

PHP警告:mysqli_fetch_assoc()期望恰好1个参数,其中3个给定

Python TypeError:set()缺少1个必需的位置参数:“ value”

Python错误“ TypeError:sort()最多接受2个参数(给定3个)”

Python - 子类 TypeError:最多需要 2 个参数(给出 3 个),而应该需要 3 个

Django 和 selenium TypeError: setUpClass() 缺少 1 个必需的位置参数:'cls'

TypeError: __init__() 需要 2 个位置参数,但 Python 3 给出了 3 个?

Selenium Python 3 TypeError:rect 未定义

selenium webdriver TypeError: to_capabilities() 缺少 1 个必需的位置参数:'self'

python flask:TypeError: __call__() 正好有 3 个参数(给定 2 个)