def test_login_data(self): '''读入数据进行测试''' po = Loginpage(self.driver) global BASE_Dir login_data_filename = BASE_Dir + "/data/login.txt" login_file = open(login_data_filename, 'r') login_data = login_file.readlines() login_data_result_filename = BASE_Dir + "/data/login_result.txt" login_result = open(login_data_result_filename, 'w') login_result.write("用户名 密码\n") for login_data_split in login_data: i = login_data_split.split(",", 1) po.open() po.login_username(i[0]) po.login_password(i[1]) time.sleep(1) #登陆失败则刷新掉弹出框再继续测试 if self.driver.current_url == "http://192.168.0.69/HGMap/example/": login_result.write(i[0] + " " + i[1] + "登陆失败" + "\n") self.driver.refresh() #登陆成功则回退到登陆界面 elif self.driver.current_url == "http://192.168.0.69/HGMap/example/realTime2D.html": login_result.write(i[0] + " " + i[1] + "登陆成功" + "\n") self.driver.back() #time.sleep(2) try: assert self.driver.current_url == "http://192.168.0.69/HGMap/example/realTime2D.html" or "http://192.168.0.69/HGMap/example/" except: save_screenshot(self.driver, "login_data.png") login_result.close() login_file.close()
def test_login_url(self): '''防止直接输入url跳过登陆界面测试''' self.driver.get("http://192.168.0.69/HGMap/example/realTime2D.html") time.sleep(2) try: assert self.driver.current_url == "http://192.168.0.69/HGMap/example/index.html" except: save_screenshot(self.driver, "url.png")
def test_loginEidEpwd(self): '''空id空密码''' po = Loginpage(self.driver) po.user_login(username='', password='') try: po.assert_login_error() except: save_screenshot(self.driver, "loginEidEpwd.png") time.sleep(2)
def test_loginWidRpwd(self): '''错误用户名正确密码''' po = Loginpage(self.driver) po.user_login(username='******', password='******') try: po.assert_login_error() except: save_screenshot(self.driver, "WidRpwd.png") time.sleep(2)
def test_loginRidWpwd(self): '''正确用户名错误密码''' po = Loginpage(self.driver) po.user_login(username='******', password='******') try: po.assert_login_error() except: save_screenshot(self.driver, "RidWpwd.png") time.sleep(2)
def test_loginRidRname(self): '''正确用户名正确密码''' po = Loginpage(self.driver) po.user_login(username='******', password='******') self.driver.implicitly_wait(5) try: po.assert_login_successful() except: save_screenshot(self.driver, "loginRidRname.png") time.sleep(2)