硒Python中的单元测试是什么? [英] What is unittest in selenium Python?
问题描述
第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 )的类. 类用于在
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()
功能中的
.
in the test_Iframe()
function.
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!
这篇关于硒Python中的单元测试是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!