Options for Validating HTTP Codes in Selenium
Sauce AI for Test Authoring: Move from intent to execution in mo.|xBack to ResourcesBlogPosted
Sauce AI for Test Authoring: Move from intent to execution in mo.
|
x
There is no way to directly getHTTP status codesin the WebDriver API (see thelengthy discussion in issue # 141). But that doesn ’ t mean you have to leave Selenium or go without any status codes in your test scripts.
In fact, some of the supported method - proxies and tightly match headless browsers - should make you feel at home if you ’ ve transition from Selenium RC, or are comfortable with traffic sniffle placeholder.
Headless Scriptable WebKits that Play Nicely with Selenium
If you don ’ t want to invest the time configure a procurator, consider setting up WebDriver to handle headless examiner like HTMLUnitDriver, Jasmine or PhantomJS.HTMLUnitDriver is well-supported in Selenium, but its Javascript engine (Rhino) is not expend by most browsers. However, if you cognise you won ’ t be testing any pages with Javascript, then it ’ s no care. But if you are, useGhostDriverto enable PhantomJS as WebDriver & # x27; s backend.
Proxies:
This can seem like both the about straightforward and heavyweight resolution. The Selenium core devspoint outthat Fiddler and BrowserMob are supported OOTB in WebDriver, and setup is comparatively simple:
For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.
To take it a small farther, Jim Evans, maintainer of the Selenium .NET bindings, has given the .NET crowd an fantabulous three part guidebook on how tohook up Fiddler to a test page and Selenium, begin filtering for basic status codes, and customize for redirect issues and cross-browser testing.
... Or Grab the Error Text from the Actual Browser
If that ’ s more than you need, then you can remain in WebDriver and use this mutual hack: Just grab the erroneousness codification displayed by the actual browser. It is good enough for returning errors so long as you cognize the textbook to be exhibit and where it will display, and aren ’ t interested in all of the routing through a redirect path.
Here ’ s a uncomplicated example:
So What Should You Do?
Parsing answer data from the page is the easiest way to extend your current use of Selenium to grab some introductory HTTP status code data; there are no proxies to set up, and no new tryout fabric to learn.
But you will miss any error not displayed on a page, likely including all 3**redirects. Using GhostDriver to handle PhantomJS will handle status code returns, and keep everything in CI in Selenium—and it ’ s in that sense the better instrument for this job. But you may already hold some essay proxy set up, since they do let you do a little more real-world test edifice, like white/black list and assume load and lag conditions. And of course that doesn ’ t mean you can ’ t use GhostDriver to drive PhantomJS with WebDriver in a proxy, which you can of class legion and automate in Sauce and AWS.
More Resources:Issue Tracker History of WebDriver HTTP code IssueWebDriver Proxy ExamplesSO: Checking HTTP Status Codes in SeleniumHow to Get HTTP Status Codes in Selenium
Alex Entrekin served on the executive faculty of Cloudshare, where he was primarily creditworthy for innovative analytics and monitoring systems. His work extending Splunk into actionable user profiling was featured at VMworld: & quot; How a Cloud Computing Provider Reached the Holy Grail of Visibility & quot;. Alex is presently an lawyer, researcher and writer based in Santa Barbara, CA. He have a J.D. from the UCLA School of Law.
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free