登录模块变成公共模块

测试文件

测试为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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容