Like most portals out there, our portal makes calls to several services to display the requested information.
My question - is there a way to automate the capture of any 500s or 404开发者_StackOverflow中文版s that either of these (GET
) calls make? Using Selenium?
I personally wouldn't use Selenium for testing in this manner. I would do the testing in a more programmatic way.
In Python I would do it like this
import urllib2
try:
urllib2.urlopen('http://my-site')
except urllib2.HTTPError, e:
print e.getcode() #prints if its 404 or 500
Starting up browsers is a very expensive task in terms of time for the browser to load and other things along that vein.
I actually found a 'graceful' way of doing this using Selenium. Starting the server instance as -
selenium.start("captureNetworkTraffic=true");
and then using
String trafficOutput = selenium.captureNetworkTraffic("json"); // "xml" or "plain"
in the @Test
presents all the HTTP traffic stats.
The advantage in this approach is that network stats can be captured, while navigating through a portal.
Here is a sample (formatted) output from www.google.com:
--------------------------------
results for http://www.google.com/
content size: 149841 kb
http requests: 14
status 204: 1
status 200: 8
status 403: 1
status 301: 2
status 302: 2
file extensions: (count, size)
png: 2, 60.019000
js: 2, 67.443000
ico: 2, 2.394000
xml: 4, 11.254000
unknown: 4, 8.731000
http timing detail: (status, method, url, size(bytes), time(ms))
301, GET, http://google.com/, 219, 840
200, GET, http://www.google.com/, 8358, 586
403, GET, http://localhost:4444/favicon.ico, 1244, 2
200, GET, http://www.google.com/images/logos/ps_logo2.png, 26209, 573
200, GET, http://www.google.com/images/nav_logo29.png, 33810, 1155
200, GET, http://www.google.com/extern_js/f/CgJlbhICdXMrMEU4ACwrMFo4ACwrMA44ACwrMBc4ACwrMCc4ACwrMDw4ACwrMFE4ACwrMFk4ACwrMAo4AEAvmgICcHMsKzAWOAAsKzAZOAAsKzAlOM-IASwrMCo4ACwrMCs4ACwrMDU4ACwrMEA4ACwrMEE4ACwrME04ACwrME44ACwrMFM4ACwrMFQ4ACwrMF84ACwrMGM4ACwrMGk4ACwrMB04AZoCAnBzLCswXDgALCswGDgALCswJjgALIACKpACLA/rw4kSbs2oIQ.js, 61717, 1413
200, GET, https://sb-ssl.google.com:443/safebrowsing/newkey?pver=2%2E2&client=navclient%2Dauto%2Dffox&appver=3%2E6%2E13, 154, 1055
200, GET, http://www.google.com/extern_chrome/8ce0e008a607e93d.js, 5726, 159
204, GET, http://www.google.com/csi?v=3&s=webhp&action=&e=27944,28010,28186,28272&ei=a6M5TfqRHYPceYybsJYK&expi=27944,28010,28186,28272&imc=2&imn=2&imp=2&rt=xjsls.6,prt.54,xjses.1532,xjsee.1579,xjs.1581,ol.1702,iml.1200, 0, 230
200, GET, http://www.google.com/favicon.ico, 1150, 236
302, GET, http://fxfeeds.mozilla.com/en-US/firefox/headlines.xml, 232, 1465
302, GET, http://fxfeeds.mozilla.com/firefox/headlines.xml, 256, 317
301, GET, http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml, 256, 1357
200, GET, http://feeds.bbci.co.uk/news/rss.xml?edition=int, 10510, 221
I am, though, interested in knowing if anyone did authenticate these results captured by Selenium.
精彩评论