问题
通常手工测试人员对Web系统进行测试的话需要先做登录操作,并且有些Web系统的登录页面还要输入验证码,那么对于自动化测试人员,如何绕过登录进行测试呢?
image.png
解决方案
通过cookie绕过登录,然后进行测试
案例实践
使用Python自动化脚本发帖
代码如下:
# -*- coding: utf-8 -*-
from selenium import webdriver
import time
def test():
driver.get("http://192.168.1.153:8090/phpwind/")
driver.find_element_by_class_name("header_post").click()
driver.find_element_by_xpath("//*[@id='J_forum_list']/li[1]").click()
driver.find_element_by_xpath("//*[@id='J_forum_ul']/li[1]").click()
driver.find_element_by_id("J_head_forum_sub").click()
driver.find_element_by_id("J_atc_title").send_keys("hello phpwind")
frame = driver.find_element_by_class_name("wind_editor_iframe")
driver.switch_to.default_content()
driver.switch_to.frame(frame)
driver.find_element_by_class_name("editor_content").send_keys("just test.just test.just test.just test.just test.")
driver.switch_to.default_content()
driver.find_element_by_id("J_post_sub").click()
time.sleep(3)
driver.close()
if __name__ == "__main__":
driver = webdriver.Chrome()
driver.implicitly_wait(15)
driver.maximize_window()
driver.get("http://192.168.1.3:8090/phpwind/")
driver.add_cookie({'name': 'Bzi_lastvisit', 'value': '1676%091531844535%09%2Fphpwind%2Fread.php%3Ftid%3D1%26fid%3D2'})
driver.add_cookie({'name': 'Bzi_Pw_verify_code', 'value': '8a7b3ece77c27041dc9a5db50ee43f40'})
driver.add_cookie({'name': 'Bzi_visitor', 'value': 'EJF0Nj8fvoWsjWvbZOL7y6qsaJvkVlPRQwo8ny2uykZDOJxCI1whqt1BLxLE2LzfH'
'7kNmQ6jT%2FdHGoc3MUhNeERdZYCTYsf6J%2FfNrk1B%2FkY%3D'})
driver.add_cookie({'name': 'csrf_token', 'value': 'e4233250ddbbd331'})
driver.add_cookie({'name': 'PHPSESSID', 'value': 'eaqejk6kcaqj3mtklv5pnv64b1'})
driver.add_cookie({'name': 'Bzi_winduser', 'value': 'hcUEN%2B3i2IZqpSSFne3zHlq7fDwr%2FEPnZWxN76AatVoIJ9dbCK0LFA%3D%3D'})
test()
网友评论