UI自動化框架遇到的一些question(持續更新)
阿新 • • 發佈:2021-09-01
框架:pytest + selenium + poium (基於python語言)
1、多條測試用例基於登入之後才能做後續操作
解決思路:建立登入函式(or登入類)供其他測試用例統一呼叫;
遇到問題:登入函式or登入類引數自定義為brower、base_url;測試用例呼叫一直報錯,錯誤棧資訊如下:
INTERNALERROR> File "C:\Users\rwxwin10\AppData\Local\Programs\Python\Python38\lib\site-packages\pluggy\callers.py", line 203, in _multicall INTERNALERROR> gen.send(outcome) INTERNALERROR> File "f:\testproject\graspAutoTest\conftest.py", line 76, in capture_screenshots INTERNALERROR> raise NameError('沒有初始化測試報告目錄') INTERNALERROR> NameError: 沒有初始化測試報告目錄
INTERNALERROR> return outcome.get_result() INTERNALERROR> File "C:\Users\rwxwin10\AppData\Local\Programs\Python\Python38\lib\site-packages\pluggy\callers.py", line 80, in get_result INTERNALERROR> raise ex[1].with_traceback(ex[2]) INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "f:\testproject\graspAutoTest\conftest.py", line 34, in pytest_html_results_table_row INTERNALERROR> cells.insert(1, html.td(report.description)) INTERNALERROR> AttributeError: 'CollectReport' object has no attribute 'description'
修復bug:登入函式和登入類的引數設定導致的bug,截圖資訊如下
應改為:
2、pytest、selenium測試用例,有彈窗的情況無法截圖
原因是alert彈框不在DOM中,是一個獨立的視窗,此時可以用robot模擬鍵盤截圖,如下:
Image=newRobot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(image, "png", new File(dirName + File.separator + fileName + ".png"));