测试文件
测试为login.py、test.py,都在login_demo文件中
1、登录模块(login.py)
# -*- coding: utf-8 -*-
import time
def login(self):
driver=self.driver
driver.get("http://weibo.com") #打开微博
time.sleep(5)
driver.find_element_by_xpath('//*[@id="pl_login_form"]/div/div[1]/div/a[1]').click() #找到微博登录界面
driver.find_element_by_xpath('//*[@id="loginname"]').send_keys("xxx@qq.com") #输入帐号
driver.find_element_by_xpath('//*[@id="pl_login_form"]/div/div[3]/div[2]/div/input').send_keys("xxx")#输入密码
driver.find_element_by_xpath('//*[@id="pl_login_form"]/div/div[3]/div[6]/a').click()#点击登录
2、测试模块(test.py)
# -*- coding: utf-8 -*-
from selenium import webdriver
import login #引入登录模块
import unittest
class test(unittest.TestCase):
def setUp(self):
# driver = webdriver.Chrome() #启动浏览器
self.driver=webdriver.Chrome()
def test(self):
self.driver=self.driver
login.login(self) #调用登录模块
if __name__ == '__main__':
unittest.main(verbosity=2)
3、执行模块(test.py)
python3 test.py