1¡¢ÎªÄ£Äâ²âÊÔÊý¾Ý¶ø¿ªÕ¹µÄ½Ó¿Ú×Ô¶¯»¯
ÕâÖÖ½Ó¿Ú×Ô¶¯»¯´ó¶àÊǵ¥´ÎÖ´ÐУ¬Ä¿µÄºÜÃ÷È·ÊÇΪÁ˹¦ÄܲâÊÔ´´Ôì²âÊÔÊý¾Ý£¬½ÚÔ¼È˹¤ÔìÊý¾ÝµÄʱ¼äºÍÈ˹¤³É±¾£¬Ìá¸ß¹¦ÄܲâÊÔÈËÔ±µÄ²âÊÔЧÂÊ¡£
2¡¢ÔÚ¹¦ÄܲâÊÔ֮ǰÌáÇ°·¢ÏÖ´íÎó¶ø¿ªÕ¹µÄ½Ó¿Ú×Ô¶¯»¯
ÕâÖÖ½Ó¿Ú×Ô¶¯»¯µÄ¹¤×÷Á÷³Ì¸ú¹¦ÄܲâÊÔÒ»Ñù£¬ÐèÒªÉè¼Æ½Ó¿Ú²âÊÔÓÃÀý£¬È»ºóÖ´ÐнӿڲâÊÔÓÃÀý¡£
˵°×Á˾ÍÊǶԵ¥½Ó¿Ú½øÐй¦ÄÜУÑ飬°üÀ¨½Ó¿Ú²ÎÊýµÄ±ØÌîÐÔ¡¢³¤¶È×Ö·ûÀàÐÍÏÞÖÆ¡¢Èë²Îö¾ÙÖµµÈÊÇ·ñÕýÈ·¡¢ÏìÓ¦Êý¾ÝÊÇ·ñÕýÈ·µÈ½øÐÐУÑé¡£
±¾ÎÄÖ÷Òª½²½âµÚ¶þÖֵĽӿÚ×Ô¶¯»¯²âÊÔ¡£Å¨ËõÁ˽ӿÚ×Ô¶¯»¯µÄºËÐĵã½øÐÐʵս£¬¸Ãʵս»òÐíÄܳÉΪÃæÊԵļӷֵ㡣
½Ó¿Ú²âÊÔÓÃÀýÉè¼Æ
´úÂë¶ÁÈ¡½Ó¿Ú²âÊÔÓÃÀý
ÀûÓÃpytest¿ò¼ÜʵÏÖ½Ó¿Ú×Ô¶¯»¯
ÀûÓÃpython-requestsÍê³É½Ó¿ÚÇëÇó
ÀûÓÃjenkins+allureʵÏÖ³ÖÐø¹¹½¨ºÍÊä³ö²âÊÔ±¨¸æ
Excel¹ÜÀí½Ó¿Ú²âÊÔÓÃÀý
Pytest¿ò¼ÜÔËÐвâÊÔÓÃÀý
Jenkins¼¯³É¹¹½¨
Allureչʾ²âÊÔ±¨¸æ
Êý¾Ý×¼±¸
Á˽â½Ó¿Ú
1.½Ó¿ÚÇëÇó·½Ê½£ºget
2.½Ó¿ÚÇëÇóÍ·£º{"Content-Type": "text/html;charset=utf-8"}
3.½Ó¿ÚÇëÇóÌ壺{"key": "*****************,"type": ""}
4.²ÎÊýÖµ£ºtype=guoji¡¢keji¡¢yule£¬Ä¬ÈÏtop
5.ÐÂÎÅÇëÇó£ºhttp://v.juhe.cn/toutiao/index
±¸×¢£º½Ó¿ÚÇëÇóµÄkeyÐèÒª×ÔÐÐÈ¥¾ÛºÏÊý¾Ýƽ̨ÉêÇë¡£
Éè¼Æ½Ó¿Ú²âÊÔÓÃÀý
½Ó¿Ú²âÊÔÓÃÀýÉè¼Æ˼·¸ú¹¦ÄܲâÊÔÓÃÀýÉè¼ÆÒ»Ö£¬»ù±¾ÊÇÊÇУÑ飺±ØÌîÏî¡¢×Ö·ûÀàÐͳ¤¶ÈÏÞÖÆ¡¢Èë²ÎÄÚÈݵȡ£
½Ó¿Ú²¿·ÖÓÃÀýÉè¼ÆÈçÏ£º£¨½ö¹©²Î¿¼£©
½Å±¾Ä¿Â¼Éè¼Æ
ÍêÕûµÄ½Ó¿Ú×Ô¶¯»¯²âÊÔ£¬Ò»°ã·ÖΪ£ºÊý¾Ý¡¢¹«¹²ÅäÖᢽӿڽű¾¡¢±¨¸æËÄ´ó»ù´¡Îļþ¼Ð¡£
Êý¾Ý£ºDataÎļþ¼ÐÓÃÓÚ´æ·ÅÊý¾Ý£¬ÀýÈç²âÊÔÓÃÀýÎĵµ
¹«¹²½Å±¾£ºCommonÎļþ¼ÐÓÃÓÚ´æ·Å¹«¹²·½·¨µÄ´úÂëÎļþ£¬ÀýÈ磺¶ÁÈ¡²âÊÔÓÃÀý´úÂëÎļþµÈ
½Ó¿Ú½Å±¾£ºRequestÎļþ¼ÐÓÃÓÚ´æ·Å¸÷¸ö²»Í¬ÒµÎñ½Ó¿ÚµÄ´úÂëÎļþ£¬ÀýÈ磺»ñÈ¡ÐÂÎÅÍ·Ìõ½Ó¿Ú´úÂëÎļþµÈ
±¨¸æ£ºReportÎļþ¼Ð£¬ÓÃÓÚ´æ·Å²âÊÔ½á¹û±¨¸æ
½Å±¾Éè¼ÆÏà¹Ø֪ʶµã
¶ÁÈ¡²âÊÔÓÃÀý
֪ʶµã1£ºxlrd¶ÁÈ¡excelµÄ»ù´¡·½·¨
1.´ò¿ªÎļþ¶ÔÏó£ºfb=xlrd.open_workbook(¡®xls²âÊÔÓÃÀýÎļþ·¾¶¡¯)
2.»ñÈ¡¹¤×÷±íÃû³Æ£ºsheetnames=fb.sheet_names ()
3.´ò¿ª²âÊÔÓÃÀýËùÔÚ¹¤×÷±í:casesheet=fb.get_by_name(¡®¡¯ÓÃÀýËùÔÚ¹¤×÷±íÃû³Æ)
4.»ñÈ¡²âÊÔÓÃÀýÌõÊý£¨±í¸ñÐÐÊý£©£ºrows=casesheet.nrows
5.»ñÈ¡¹¤×÷±íÄÚµ¥Ôª¸ñÖµ£ºcell_value=casesheet.cell_values(x,y)£¬ÆäÖÐx ºÍyΪµ¥Ôª¸ñµÄºá×ø±êºÍ×Ý×ø±ê
6.ÓÉÓÚÐèҪͨ¹ýpytestµÄ×°ÊÎÆ÷½øÐвÎÊý»¯£¬ËùÒÔ¶ÁÈ¡µ½µÄµ¥Ôª¸ñÐèÒª×éºÏ³ÉÁбíµÄÄ£°å
ÀýÈ磺
case1=[¡®url_01¡¯,¡¯method_01¡¯,{body_01 },¡¯expect_01¡¯] case2=[¡®url_02¡¯,¡¯method_02¡¯,{body_02 },¡¯expect_02¡¯]
×îºóÌṩ¸øpytest¶ÁÈ¡µÄÊý¾ÝÓ¦¸ÃÊÇ£º
[[¡®url_01¡¯,¡¯method_01¡¯,{body_01 },¡¯expect_01¡¯], [¡®url_02¡¯,¡¯method_02¡¯,{body_02 },¡¯expect_02¡¯]]
´úÂëƬ¶Î£º
ʹÓÃÁбí×·¼ÓµÄ·½·¨append£¨£©¡£
±¸×¢£ºÍ¨¹ýcell_values£¨£©¶ÁÈ¡µ½µÄµ¥Ôª¸ñÊý¾Ý£¬Ä¬ÈÏÊÇ×Ö·û´®strÀàÐÍ¡£
֪ʶµã2£ºÊý¾Ýת»¯
1.url¡¢methodÊÇ×Ö·û´®ÀàÐÍ£¬ËùÒÔÎÞÐèת»¯
2.headerºÍbodyÐèҪͨ¹ýjson.loads()תΪjson¸ñʽ
½Ó¿ÚÇëÇó
֪ʶµã1£ºrequests½Ó¿ÚÇëÇó»ù´¡
1.·¢Æð½Ó¿ÚÇëÇó£º
resq=request.get() resq =request.post()
2.»ñÈ¡ÏìÓ¦Êý¾Ý²¢×ªÎªjson¸ñʽ£ºresq.json()
3.¶ÏÑÔ£ºassert
4.ÌáÈ¡ÏìÓ¦ÄÚÈÝ£ºjsonpathÓï·¨
response[¡®msg¡¯] response[¡®data¡¯][¡®name¡¯]
֪ʶµã2£ºpytest¿ò¼Ü
»·¾³°²×°£º
pip install pytest
1.PytestʹÓùæÔò£ºÓÃÀýºÍ½Å±¾Îļþ±ØÐëÒÔtest¿ªÍ·
2.²ÎÊý»¯Ö´ÐÐÓÃÀý£ºPytest×°ÊÎÆ÷@pytest.mark.aprametrize()
a)µ¥¸ö²ÎÊýд·¨£º@pytest.mark.parametrize(¡±inData¡±,[10,20])£¬µÚÒ»¸ö²ÎÊýΪ±äÁ¿Ãû³Æ£¬µÚ¶þ¸öΪ²ÎÊýÖµ¡£²»ÐèÒªÉèÖÃÑ»·¶ÁÈ¡²ÎÊýÖµ£¬ÒòΪpytestµÄ×°ÊÎÆ÷»á×Ô¶¯Ñ»·¶ÁÈ¡¡£
b)¶à¸ö²ÎÊýд·¨£º£¨²ÎÊýÖµÒÔÔª×éÐÎʽд£©@pytest.mark.parametrize(¡±µÚÒ»¸ö²ÎÊýÃû³Æ£¬µÚ¶þ¸ö²ÎÊýÃû³Æ¡±)£¬[(µÚÒ»¸ö²ÎÊýµÄµÚÒ»¸öÖµ£¬µÚÒ»¸ö²ÎÊýµÄµÚ¶þ¸öÖµ)£¬(µÚ¶þ¸ö²ÎÊýµÄµÚÒ»¸öÖµ£¬µÚ¶þ¸ö²ÎÊýµÄµÚ¶þ¸öÖµ)]¡£
c)²»ÐèÒªÉèÖÃÑ»·¶ÁÈ¡²ÎÊýÖµ£¬ÒòΪpytestµÄ×°ÊÎÆ÷»á×Ô¶¯Ñ»·¶ÁÈ¡¡£
3.±¾µØµ÷ÊÔÔËÐнű¾£º
½Ó¿Ú×Ô¶¯»¯ÔËÐнű¾µ½Éú³Éallure-html±¨¸æ£¬·ÖΪ2²½Ö裺
µÚ1²½£ºalluredirÉú³É²âÊÔ±¨¸æÊý¾ÝÔ´Îļþjson£¬´æÈëreportÎļþ¼ÐÄÚ
pytest.main([¡±½Ó¿ÚÇëÇó½Å±¾Îļþ.py¡±,¡±-s¡±,¡±--alluredir=../report/¡±])
µÚ2²½£º´ÓreportÎļþ¼ÐÄÚ½«²âÊÔ±¨¸æÊý¾ÝÔ´ÎļþjsonתΪhtml±¨¸æ
os.system(¡±allure generate ../report/ -o ../report_html/¡±)
³ÖÐø¹¹½¨
֪ʶµã£ºjenkins¹¹½¨+allure²âÊÔ±¨¸æ
1.Jenkins»·¾³´î½¨
2.ÏÂÔØallure±¨¸æ²å¼þ
3.¹¹½¨
a)¹¹½¨£ºÀûÓÃpytestÃüÁîÖ´Ðнű¾£¬²¢Éú³ÉallureÔ´Êý¾Ý
b)¹¹½¨ºó²Ù×÷£ºÌí¼Óallure report£¨jenkins»á×Ô¶¯½«allureÔ´Êý¾Ý×éºÏ³Éhtml±¨¸æ£©
½á¹û