2018年3月31日 星期六

[.Net] HttpRuntime.Cache.Insert中absoluteExpiration與slidingExpiration可共存??

說明:
MSDN查HttpRuntime.Cache.Insert說明時,看到下面這段文字:

如果沒搞錯意思,應該是說在slidingExpiration設個參數(大於0),在absoluteExpiration設為DateTime.Now.Add(該參數),可以有如上說明的效果。

但不是說absoluteExpiration與slidingExpiration不能共存嗎???

有看沒有懂,實際測試看看(.Net framework 4.5.2 + MVC 5.2.3):


實際執行,出現ArgumentException,
看起來absoluteExpiration與slidingExpiration不能同時生效。
後來使用.Net framework4 + WebForm測試,也是一樣的Exception。


資料來源:
https://msdn.microsoft.com/en-us/library/4y13wyk9(v=vs.110).aspx

2018年3月3日 星期六

[Tool] OpenQA.Selenium.DriverServiceNotFoundException: The geckodriver.exe file does not exist...

說明:
測試專案加入Selenium Web Driver 3.9.1,使用FirefoxDriver,
第一次啟動測試後出現錯誤:
OpenQA.Selenium.DriverServiceNotFoundException: The geckodriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at https://github.com/mozilla/geckodriver/releases.


解法:
這是因為Firefox(FF) 48後的engine改為gecko driver了,
因此Selenium 3.0後,就使用gecko driver取代FF預設WebDriver的實作,
至於為何會改用gecko driver?

那要先介紹Gecko,Gecko是:
● It's a free and open source project.
● 內容是Layout engine,提供許多API讓application可以顯示web page或當使用者介面。
● 相容於W3C定義的WebDriver標準。
● 後來由Mozilla基金會與公司維護。

而Gecko有支援multi-processing(能讓UI在不同process處理)架構,
當時整個FF 47還跑在同一個process,因此48版後改用gecko driver。

所以現在啟動測試,使用FirefoxDriver需透過gecko driver來啟動FF,
正如錯誤訊息所示,到https://github.com/mozilla/geckodriver/releases下載,
目前最新版是v.0.19.1,下載後解壓縮到特定資料夾,
我直接放到FF安裝資料夾內,然後到系統:

 找到環境變數

 在Path,新增一筆gecko driver的放置路徑,放在使用者變數也行。

最重要的是,設定後要重開VS。


參考資料:
https://stackoverflow.com/questions/40657443/how-to-set-up-selenium-3-0-getting-error-the-geckodriver-exe-file-does-not-exi
http://qavalidation.com/2016/08/whats-new-in-selenium-3-0.html/
https://en.wikipedia.org/wiki/Gecko_(software)
https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox
https://blog.mozilla.org/futurereleases/2016/08/02/whats-next-for-multi-process-firefox/