Python - 如何从类调用外部函数然后返回到类

标签 python class selenium automated-tests

好吧,澄清一下,我正在尝试使用 selenium 在网站上进行数据驱动测试: 主要类代码为:

from  a_folder.abc_file import userJourney
from  a_folder.a1_file import contact

@ddt
class testScenario(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Chrome(path)

    def test_main_page(arg1, arg2):
         if arg1 == 'yes':
             return userJourney(arg1, arg2)

         if arg 2 == 'no':
             return contact(arg1, arg2)


    @classmethod
    def tearDownClass(cls):
        cls.driver.close()

参数从 csv 文件传入

userJourney() 和 contact() 函数是从外部文件导入的

我遇到的问题是 arg1 和 arg2 可以同时为 true,因此我希望执行两个函数(userJouney 和 contact),但测试只执行一个函数,然后直接进入 TeaDownClass 函数。关于我缺少什么有什么想法吗?

abc_file.py 类似于

def userJourney(arg1, arg2):
   # Find element and click

提前致谢

最佳答案

只有一个方法会被执行,因为在这两种情况下都使用了“return”。因此,如果 arg1 == 'yes',则将执行 userJourney 函数,之后 test_main_page 将退出并将控制权返回给调用者,因为您在调用 userJourney 之前使用了 'return' 关键字。下一个案例将不会执行,因为此时方法已完成。

您可能应该从这两种情况中删除“return”关键字。我不确定你想在这里测试什么,但那是另一回事。

关于Python - 如何从类调用外部函数然后返回到类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44663593/

相关文章:

python - 在版本 56.0.2924.87 中,Selenium 在 Chrome 中设置窗口大小失败

python - MUSIC算法Spectrum Python实现

python - tkinter python 创建子窗口

Python 3.x C API : Do I have to free the memory after extracting a string from a PyObject?

java - 将 boolean 类添加到类数组中

C++:派生+基类实现单个接口(interface)?

python - 等待+刷新页面

python - 在 Chromium Selenium 和 Python3 中使用自定义过滤器加载 ublock

python - anaconda环境无法卸载包

javascript - ES6 数组扩展极端怪异。它仅使用 webpack 恢复为常规数组