Web UI Automation Script distribution sometimes need to get information about the browser, this article gives a brief way to get the browser type, please refer to the small owners. If there is any deficiency, please ask the great God to correct me, I appreciate it!
Gossip less, on yards.
1 /**2 * Get Browser type, for execute JavaScript by Selenium3 * 4 * @authorAARON.FFP5 * @versionV1.0.0:autoseleniumdemo main.aaron.sele.core Seleniumcore.java getbrowertype, 2015-7-26 12:17:12 Exp $6 * 7 * @returnBrowser Type {chrome| Firefox| internetexplorer| Safari}8 */9 PublicString Getbrowsertype () {TenString browser = ""; One A Switch( This. webdriver.tostring (). Split (":") [0]) { - Case"Chromedriver": -Browser = "Chrome"; the Break; - Case"Firefoxdriver": -Browser = "Firefox"; - Break; + Case"Internetexplorerdriver": -Browser = "InternetExplorer"; + Break; A Case"Safaridriver": atBrowser = "Safari"; - Break; - default: -Browser = "Chrome"; - Break; - } in - returnBrowser; to}
This method is relatively simple and easy to understand. At the same time, I found that in the course of the script, if the UI Automation test pin This error message, in addition to the corresponding errors in the information, but also contains the driver version, selenium version, work machine, browser and other details, if you want to get more detailed information, To record the response information in subsequent log generation, it is possible to obtain the appropriate information from the exception by artificially making the exception. (This method of access is updated later, please expect)
Interested in the small owners, you can try the above exception to capture the information method. If the great God has a better way, please inform, thank you very much!
At this point, theWebUI automation function test Script No. 017-Get the browser type successfully completed, I hope this article can give beginners Selenium you a reference.
Finally, very grateful to the pro-stop, I hope this article can be pro helpful. Warmly welcome the kiss to discuss together and progress together. Thank you so much! ^_^
SELENIUM2 Learning -019-webui Automation Real instance -017-get browser type