What is unittest in selenium Python?(selenium Python中的unittest是什么?)
问题描述
3、16、17、18、19行用*高亮是什么意思.有人可以解释他们的工作吗?我是 python 和编程新手
What is the meaning of lines 3,16,17,18 and 19 which are highlighted with *. Can someone explain what they do? I am new to python and programming
import unittest
from selenium import webdriver
**class Iframe(unittest.TestCase):**
def setUp(self):
self.driver = webdriver.Firefox()
def test_Iframe(self):
driver = self.driver
driver.maximize_window()
driver.get('http://www.toolsqa.com/iframe-practice-page/')
iframe1 = driver.find_element_by_id('IF1')
driver.switch_to.frame(iframe1)
driver.find_element_by_name('email').send_keys('xyz')
driver.switch_to.default_content()
list = driver.find_elements_by_tag_name('iframe')
print(len(list))
**def tearDown(self):
self.driver.quit()**
**if __name__ == '__main__':
unittest.main()**
推荐答案
这段代码中只有三行用 * 突出显示,但它们的含义如下:
Only three lines in this code are highlighted with an *, but here's what they mean:
class Iframe(unittest.TestCase):
这是为随后的函数(test_Iframe 和 tearDown)声明类.class 用于在 面向对象编程.class 是数据/过程的抽象,而 object 是该类的特定实例.
This is declaring the class for the functions (test_Iframe and tearDown) that follow. A class is used to create "objects" in object oriented programming. Think of the class as the abstraction of data/procedures, while the object is the particular instance of the class.
def tearDown(self):
self.driver.quit()
本节首先用def
关键字声明一个函数,该函数退出驱动,设置为:
This section first declares a function with the def
keyword, and the function quits the driver, which was set as:
driver = self.driver
driver.maximize_window()
driver.get('http://www.toolsqa.com/iframe-practice-page/')
在 test_Iframe()
函数中.
if __name__ == '__main__':
unittest.main()
这部分只是执行程序的主要功能.可以在这里找到更多细节.
This section simply executes the main function of the program. More details on this can be found here.
如果您还有其他问题,请告诉我!
Let me know if you have any more questions!
这篇关于selenium Python中的unittest是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:selenium Python中的unittest是什么?


- YouTube API v3 返回截断的观看记录 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01