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!
相关文章