コード例 #1
0
 def test_1login(cls):
     '''用户登录'''
     driver = cls.driver
     CodeText = get_code(driver)
     login(driver, 'baoyong123', 'asdf1234', CodeText)
     time.sleep(5)
     log.info("用户登录")
コード例 #2
0
ファイル: 1test_online.py プロジェクト: BaoYong-1/PyTesting1
    def test_1login(cls):
        '''用户登录'''
        driver = cls.driver
        CodeText = get_code(driver)
        login(driver, 'baoyong123', 'asdf1234', CodeText)  # 正确用户名和密码

        driver.implicitly_wait(10)  # 隐式等待
        username = driver.find_element_by_id("gps_main_username_span_w").text
        conn = cx_Oracle.connect('gpsadmin/gpsadmin_123654@ 192.168.10.110: 1521 / ora11g')  # 连接数据库
        cursor = conn.cursor()
        cursor.execute("select t.v_user_name from GPS_USER t where t.v_user_account='baoyong123'")  # 引用定义变量
        rows = cursor.fetchall()  # 得到所有数据集
        for row in rows:
            print("%s" % (row[0]))
        try:
            assert username == row[0]
            print('登录成功!')
        except AssertionError as e:
            print('登录失败!')
コード例 #3
0
ファイル: test_loginout.py プロジェクト: BaoYong-1/PyTesting1
 def test_login_out(self):
     u''' 退出登录'''
     driver = self.dr
     CodeText = get_code(driver)
     login(driver, 'baoyong123', 'asdf1234', CodeText)
     log.info("用户登录")
     driver.find_element_by_id("gps_main_quit_span_w").click()
     log.info("点击退出按钮")
     driver.implicitly_wait(2)
     driver.find_element_by_xpath(
         "//body//div//div//div//button/span[./text()='确定']").click()
     log.info("点击确定按钮")
     driver.implicitly_wait(3)
     message = self.dr.find_element_by_xpath(
         "//html//body//div[@class='middle']").text
     self.assertIn('山东广安车联科技股份有限公司', message)
     self.dr.get_screenshot_as_file(
         "F:\\PyTesting\\AutoTest\\log\\png\\login_out.png")
     log.info("退出登录")
コード例 #4
0
ファイル: test_login.py プロジェクト: BaoYong-1/PyTesting1
 def test_05login_pwd_error(self):
     '''用户名正确、密码不正确'''
     driver = self.dr
     CodeText = get_code(driver)
     self.login(user[5], pwd[5], CodeText)  # 正确用户名,错误密码
     time.sleep(2)
     error_message = self.dr.find_element_by_xpath(
         "//body//div//div[./text()='用户名或密码错误,请重新输入!']").text
     # 用assertIn(a,b)方法来断言 a in b
     try:
         self.assertIn('用户名或密码错误,请重新输入!', error_message)
         excel.write_cell_data(5, 6, 'pass')
         print("用户名、验证码正确,密码错误时点击登录测试通过!")
     except AssertionError as e:
         excel.write_cell_data(5, 6, 'fail')
         self.dr.get_screenshot_as_file(
             "F:\\PyTesting\\AutoTest\\log\\png\\login_pwd_error.png")
         print("测试失败,提示信息有误!")
         raise
コード例 #5
0
ファイル: test_login.py プロジェクト: BaoYong-1/PyTesting1
 def test_07login_success(self):
     '''用户名、密码正确、验证码正确'''
     driver = self.dr
     CodeText = get_code(driver)
     self.login(user[7], pwd[7], CodeText)  # 正确用户名和密码
     time.sleep(10)
     username = self.dr.find_element_by_id("gps_main_username_span_w").text
     conn = cx_Oracle.connect(
         'gpsadmin/gpsadmin_123654@ 192.168.10.110: 1521 / ora11g')  # 连接数据库
     cursor = conn.cursor()
     cursor.execute(
         "select t.v_user_name from GPS_USER t where t.v_user_account='%s'"
         % user[7])  # 引用定义变量
     rows = cursor.fetchall()  # 得到所有数据集
     for row in rows:
         print('用户姓名:', "%s" % (row[0]))
     try:
         assert username == row[0]
         excel.write_cell_data(7, 6, 'pass')
         print('登录成功!')
     except AssertionError as e:
         excel.write_cell_data(7, 6, 'fail')
         print('登录失败!')
         raise
コード例 #6
0
ファイル: Login_c.py プロジェクト: BaoYong-1/PyTesting1
    try:
        the_element = EC.visibility_of_element_located(element)
        assert the_element(driver)
        flag = True
    except:
        flag = False
    return flag


def login(driver, username, password, CodeText):
    driver.find_element_by_id("txt_username").clear()
    driver.find_element_by_id("txt_username").send_keys(username)
    driver.find_element_by_id("txt_password").clear()
    driver.find_element_by_id("txt_password").send_keys(password)
    driver.find_element_by_id("verifycode").clear()
    driver.find_element_by_id("verifycode").send_keys(CodeText)
    driver.find_element_by_class_name("button").click()
    time.sleep(2)


if __name__ == '__main__':
    options = webdriver.ChromeOptions()
    options.add_experimental_option("excludeSwitches",
                                    ["ignore-certificate-errors"])
    driver = webdriver.Chrome(chrome_options=options)
    driver.maximize_window()
    url = "http://192.168.10.110:8080/WebGis/login"
    driver.get(url)
    CodeText = get_code(driver)
    login(driver, 'baoyong123', 'asdf1234', CodeText)
コード例 #7
0
 def test_1login(cls):
     '''用户登录'''
     driver = cls.driver
     CodeText = get_code(driver)
     login(driver, 'baoyong123', 'asdf1234', CodeText)  # 正确用户名和密码
     time.sleep(3)