from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest
class TestCase1(unittest.TestCase):
def test_01(self):
global driver
#webdriver实例化
driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
driver.maximize_window()
driver.find_element(by=By.ID,value='kw').send_keys('码上学院')
driver.find_element(by=By.ID,value='su').click()
if __name__ == '__main__':
print('11111111111111')
unittest.main()
代码如上
在pycharm中,如果执行的时候是选择python,并且路径为此py文件对应的路径,那么会执行main,如果是python tests,那么不会执行main,我想问下这是什么 原因,有什么资料介绍嘛?
另外第二个问题,如果是执行main,为什么这里写成unittest.main也会执行test_01?我理解的是TestCase1这个类继承了unittest.TestCase,test_01的方法应该是这个类重写的,也是他独有的,不应该影响到父类啊,为什么这里调用父类会调用到这个方法,请知道的告诉下谢谢