顯示具有 robotframework 標籤的文章。 顯示所有文章
顯示具有 robotframework 標籤的文章。 顯示所有文章

2015年10月5日 星期一

selenium

selenium get url of webpage
selenium2library 可以使用 keyword "Get Location"

另外Get Element Attribute 需要使用id name@class而非一般XPATH格式否則會有錯誤

The expression is not a legal expression

而使用Get Value獲取@href不行因為結果會是attribute而非element,會有錯誤

[object XrayWrapper [object Attr]]

當需要驗證popup windows兩者標題又相同無法switch window時,後來採取抓取button href資訊並直接go to就可以不被popup限制

參考資料
自己
http://stackoverflow.com/questions/15985339/how-do-i-get-current-url-in-selenium-webdriver-2-python

rebot

robotframework 可以使用 rebot <file1>.xml <file2>.xml來合併xml,並且合併之後log.html與report.html也會跟著update

可使用參數--name <name>來變更suite name

如用Windows寫sh script時要注意檔案格式需為UNIX,否則可能有執行上問題,錯誤訊息
' failed: Data source does not exist.Appengine/X3000001.robot

Try --help for usage information.
: not found3: script.sh:
參考資料
https://twiki.cern.ch/twiki/bin/view/EMI/RobotFrameworkAdvancedGuide#Using_the_rebot_Tool
http://stackoverflow.com/questions/25988071/combining-robot-framework-test-reports

2015年2月3日 星期二

Robot Framework

Regular Expression
在使用 Read Until Regexp 時,卡在$及 . 很久,研究的結果是,由於使用或 ( | ) 所以要轉義兩次,第一次轉義後由於仍在 ( | ) 內所以仍被當成regular expression看,故要再轉義一次。

所以最後結果是 (\\$|\\.txt)

在使用SSHLibrary抓取terminal內字串時遇到換行符號,本來以為是\n,結果試了不是,又試了轉義以及\r都不是,最後靈機一動,居然是\r\n,記錄在這邊,希望能夠幫到人。

SSHLibrary Open Connection
與Telnet不同,ssh open connection 必須同時使用open connection及login兩個keyword,原因應該是因為ssh連接時是使用username@ip。robot因考慮Telnet使用同一組Keyword所以造成此限制。另外AttributeError: 'NoneType'錯誤則是因為沒有輸入帳號密碼,也就是上面所說沒有配合使用login造成。

unbalanced parenthesis則是括號沒有配合到,我遇到的狀況是空了兩格造成robot將右括號視作另一個argument了

SSHLibrary.Read until regexp 我有遇到狀況是會卡住,即使timeout時間到也不會FAIL。後來使用Read交叉測試的結果是因為output內有不同的編碼所以decode時卡住。Read結果的錯誤訊息為
UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 318: invalid start byte
解決方法是close connection等到該段output被跳過之後再重新建立連線,換言之就是跳過該段output。另外也有一可能是整個編碼錯誤,如開始英文後轉為中文。此時可於open connection指定編碼encoding=

參考資料
自己測試結果
Read until regexp卡住
http://stackoverflow.com/questions/6180521/unicodedecodeerror-utf8-codec-cant-decode-bytes-in-position-3-6-invalid-dat
http://www.robotframework.net/question/68

2014年11月26日 星期三

robotframework selenium2library

使用robotframework selenium時遇到兩個問題,第一個是使用cron設定排程時pybot無法啟動,後來看了一下應該是PATH的問題,後來使用原始執行緒python -m robot.run取代pybot後解決。第二個問題是browser無法啟動,會顯示Chrome failed to start: exited abnormally。後來找到解決方法是在shell script前面加一行export DISPLAY=:0即可正常執行。

參考資料
setup chromedriver
http://installselenium.blogspot.tw/2013/06/how-to-setupinstall-selenium.html
export DISPLAY=:0
http://stackoverflow.com/questions/6971595/how-to-set-a-cron-job-to-open-a-web-page-in-the-browser-using-crontab
http://stackoverflow.com/questions/23908319/run-selenium-with-crontab-python
python -m robot.run
自己