AssertTrue缺少1个必需的位置参数

时间:2017-11-29 09:25:30

标签: python google-chrome selenium-webdriver typeerror assert

我试图断言元素的存在,我可以使它工作,但现在按照我想要的方式。

我有一个常见的函数文件: -

from selenium.common.exceptions import NoSuchElementException


def is_element_present_common(self, how, what):
    try:
        self.driver.find_element(by=how, value=what)
    except NoSuchElementException as e:
        return False
    return True

...和我的主文件: -

import unittest
from Common import common_functions, initialisation, login
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.common.exceptions import NoSuchElementException


class QuickTestPlanLogin(unittest.TestCase):
    def setUp(self):
        self.driver = initialisation.start_webdriver()
        self.driver = initialisation.start_sap(self.driver)

    def tearDown(self):
        self.driver.close()

    def is_element_present(self, how, what):
        try:
            self.driver.find_element(by=how, value=what)
        except NoSuchElementException as e:
            return False
        return True

    def test_login(self):
        wait = initialisation.wait_for(self.driver)
        self.driver = login.default_login(self.driver, "username", "password")

        # self.assertTrue(self.is_element_present(By.ID, "my-projects-table_info"))
        # self.assertTrue(common_functions.is_element_present_common(By.ID, "my-projects-table_info"))

有两个断言陈述。如果我运行第一个它工作正常,但它调用我不想要的is_element_present函数。我想从common_functions文件中调用is_element_present_common函数。每次运行第二个断言语句时,我都会收到以下错误: -

TypeError: is_element_present() missing 1 required positional argument: 'what'

我知道我错过了很简单的事情......

1 个答案:

答案 0 :(得分:0)

将功能定义更改为:

def is_element_present_common(how, what):

将呼叫更改为is_element_present_common功能:

self.assertTrue(common_functions.is_element_present_common(By.ID, "my-projects-table_info"))