test11.py

# -*- coding: UTF-8 -*-
# @Time       : 2017/9/10 19:25
# @Author     : Weiqiang.long
# @File       : test11.py
# @Software   : PyCharm
# @Description: 
# @TODO       :

import unittest

import sys

from test9 import browser
from test10 import LoginPage,login_url

class Login_test(unittest.TestCase):
    u'''登录页面的case'''
    def setUp(self):
        self.dr = browser()
        self.login = LoginPage(self.dr) #login参数是LoginPage的实例
        self.login.open(login_url)

    def login_case(self,username,psw,expect=True):
        '''登录用例的方法'''
        # 第1步:输入账号
        self.login.input_username(username)
        # 第2步: 输入密码
        self.login.input_password(psw)
        # 第3步:点登录按钮
        self.login.click_submit()
        # 第4步:测试结果,判断是否登录成功
        result = self.login.is_text_in_element(("id","lnk_current_user"),"小龙。")
        # 第5步:期望结果
        expect_result = expect
        self.assertEqual(result, expect_result)

    def test_login01(self):
        u'''输入正确账号密码'''
        self.login_case("xiaolong", "123456.", True)

    def test_login02(self):
        u'''输入错误账号密码'''
        self.login_case("xx", "xx", False)

    def tearDown(self):
        self.dr.close()


if __name__ == '__main__':
    unittest.main()


提示如下报错:

C:\Python27\python.exe "C:\Program Files\JetBrains\PyCharm 2017.2\helpers\pycharm\_jb_unittest_runner.py" --target test11.Login_test
Testing started at 21:09 ...
Launching unittests with arguments python -m unittest test11.Login_test in C:\Users\Administrator\PycharmProjects\TestDemo\WebdriverTest

Error in sys.exitfunc:

Process finished with exit code 1


↙↙↙阅读原文可查看相关链接,并与作者交流