https://ke.qq.com/course/263945#tuin=107a3c8a
https://testerhome.com/topics/11327
python版本:2.7.*
第一節
python開發速度快,是因為開源模塊多,我們站在了巨人的肩膀上,所以在實現某個功能的時候,先去python的倉庫里看是否已實現。
開源倉庫 http://pypi.python.org/pypi
GUI:指可視化圖形工具
如果用python做性能測試,建議用工具有:Locust
python也可對java、c\c++代碼進行單元測試
CSDN的登錄操作,需要帶‘lt’的值:
遇到的問題及解決辦法:
1. ImportError: No module named 'requests'
https://www.baidu.com/link?url=oPgkXcZT5bticBF8uBDbKNtmkw6oHD8HlJ9K349MgNU7zPFSxF7ragT4Dk6mId41FLCaiZPExomWp5aX7aRVZ_&wd=&eqid=ba2d8ab700004b10000000065a548587
pip 安裝中:
第三方庫安裝后,會在該目錄下,也可查看修改
http://blog.csdn.net/huangzhang_123/article/details/64905767 python request使用介紹
python request模塊通過模擬用戶訪問web網站,實際運用到Html的post,get的方法實現網站互動。
首先要找到post網址 打開網頁->按F12(找到網絡(火狐為例))->隨意輸入帳號密碼->點擊登錄 |
按照上面的方法,獲得CSDN登錄按鈕的form提交網址:
2.post請求似乎不成功,不知道header中User-Agent和accept是否正確,未解決???

#!/usr/bin/env python #coding=utf-8 import requests import sys login_home_url="https://passport.csdn.net/account/login?ref=toolbar" #創建一個session實例,session能記錄你的登錄賬號信息(因為http是短鏈接,無法記錄cookie) # 之前的操作都是基於同一個session進行的,保持會話的有效性 web_sessions= requests.Session() #打開登錄頁面 LoginPage = web_sessions.get(login_home_url) print("line14") # 獲取響應的內容,以文本格式 print(LoginPage.text) #獲取當前頁面上的元素:元素lt\execution的值 lt_sting = LoginPage.text[LoginPage.text.find('name="lt"'): LoginPage.text.find("/>",LoginPage.text.find('name="lt"'))] print("lt_sting: ",lt_sting) print("*"*30) lt = lt_sting[lt_sting.find("LT"):-2] print("lt: ",lt) exe_sting = LoginPage.text[LoginPage.text.find('name="execution"'): LoginPage.text.find("/>",LoginPage.text.find('name="execution"'))] print("exe_sting: ",exe_sting) execution =exe_sting[exe_sting.rfind('="')+2:-2] print("execution: ",execution) #提交的用戶信息、submit的網站 login_url = "https://passport.csdn.net/account/verify" userData ={"username":"…………@qq.com","password":"qa……","lt":lt,"execution":execution,"_eventId":"submit"} #火狐瀏覽器User-Agent設置 headerstr= {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0","Accept": "text/html, application/xhtml+xml, */*"} #提交post請求 login_response = web_sessions.post(login_url,data=userData,headers=headerstr) print(login_response.text) #該post請求后響應的結果,不滿足預期,待解決。。》》》》 # comment_url = "http://blog.csdn.net/fromsuny_smile/article/details/79014217" # comment_headers= {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0","Accept": "*/*"} # comment_payload ={"commentid":"","content":u"很好啦","replyId":""} # comment_response = web_sessions.post(comment_url,data = comment_payload, headers =comment_headers) # print(comment_response.text)
--------------用appium和selenium進行用戶操作的模擬,代碼如下,如果有基礎,很容易看懂的
appium登錄豆瓣賬號如下:

#!/usr/bin/env python #coding=utf-8 from appium import webdriver import time,sys reload(sys) sys.setdefaultencoding('utf-8') usename="xxx" passwd="xxx" sleep_time =2 desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '6.0' desired_caps['deviceName'] = 'Android Emulator' #desired_caps['app'] = r"D:\study\cy\training\ceba\code\src\appium\douban_117.apk" desired_caps['appPackage'] = 'com.douban.frodo' desired_caps['appActivity'] = '.MainActivity' driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) driver.find_element_by_android_uiautomator('new UiSelector().text("我的")').click() time.sleep(sleep_time) #driver.find_element_by_android_uiautomator('new Uiseletor().resourceId("com.douban.frodo:id/title").textContains(u"我的")').click() driver.find_element_by_id("com.douban.frodo:id/unlongin_name").click() time.sleep(sleep_time) usename_element = driver.find_element_by_id("com.douban.frodo:id/input_user_name") usename_element.clear() usename_element.send_keys(usename) password_element = driver.find_element_by_id("com.douban.frodo:id/input_password") password_element.clear() password_element.send_keys(passwd) driver.find_element_by_id("com.douban.frodo:id/sign_in_douban").click() time.sleep(sleep_time)
selenium登錄微博如下:

#!/usr/bin/env python # coding=utf-8 from selenium import webdriver import unittest, time, re class WeiboTestCase(unittest.TestCase): def setUp(self): print "2222" self.driver = webdriver.Chrome() self.driver.implicitly_wait(30) self.verificationErrors = [] self.accept_next_alert = True def test_untitled_test_case(self): driver = self.driver print "i ma here" driver.get("https://weibo.com/login.php") driver.find_element_by_id("loginname").click() driver.find_element_by_id("loginname").click() driver.find_element_by_id("loginname").clear() driver.find_element_by_id("loginname").send_keys("xxxxx") driver.find_element_by_name("password").clear() driver.find_element_by_name("password").send_keys("xxxx") driver.find_element_by_id("login_form_savestate").click() driver.find_element_by_xpath("//div[@id='pl_login_form']/div/div[3]/div[6]/a").click() driver.find_element_by_xpath("//textarea[@name='']").clear() driver.find_element_by_xpath("//textarea[@name='']").send_keys("Welcome to learn Python") driver.find_element_by_link_text(u"發布").click() def tearDown(self): self.driver.quit() self.assertEqual([], self.verificationErrors) if __name__ == "__main__": print "11111" unittest.main()
這里的入門級的代碼,用作熟悉appium的使用
但如果作為企業級的自動化工具,要采用框架,例如把公共函數、方法提煉出來。
沒有輕輕松松就能拿高工資,必須有大力的付出,
沒有寫過大量代碼的測試開發,是沒有生產力的。
提高自身代碼量。
使用bing.com搜索
用英文關鍵字搜索
盡量看原英文文檔