Question
How to verify response 200 code using selenium 2.0

Answers

As webdriver does not support direct any function to verify page response code. But using "WebClient" of HtmlUnit API we can achieve this.

Html unit API is GUI less browser for java developer, using WebClent class we can send request to application server and verify response header status.

Below code, I used in my webdriver script to verify response 200 of web application

String url = "http://www.google.com/";
WebClient webClient = new WebClient();
HtmlPage htmlPage = webClient.getPage(url);

//verify response
Assert.assertEquals(200,htmlPage.getWebResponse().getStatusCode());
Assert.assertEquals("OK",htmlPage.getWebResponse().getStatusMessage());

If HTTP authentication is required in web application use below code.

String url = "Application Url";

WebClient webClient = new WebClient();
DefaultCredentialsProvider credential = new DefaultCredentialsProvider();

//Set some example credentials
credential.addCredentials("UserName", "Passeord");
webClient.setCredentialsProvider(credential);

HtmlPage htmlPage = webClient.getPage(url);

//verify response
Assert.assertEquals(200,htmlPage.getWebResponse().getStatusCode());
Assert.assertEquals("OK",htmlPage.getWebResponse().getStatusMessage());   Your Comment




More Software Questions..
What is the inputsplit in map reduce software?

What is software configuration management?

What Is Java Api For Xml-based Rpc (jax-rpc)?

How can you implement fine-grained auditing?

What is IBM’s simple explanation for Big Data’s four critical features?

What is static synchronized method in JDBC API? Give an example?

What does the NULLIF function do?

What happens if a start method is not invoked and the run method is directly invoked?

Should we override finalize method

what is the difference between mysql_fetch_array and mysql_fetch_object?

How will XML affect my document links?

Why to use Style Sheets?

What are Filters in MVC?

Can you explain Application layer in OSI model?

How to define new testplan attributes?

What are the minimum system requirements to run Photoshop? Is it possible to run Photoshop over linux?

Which oracle package is used to manage the oracle lock management services?

What is Latch Up? Explain Latch Up with cross section of a CMOS Inverter. How do you avoid Latch Up?

What is marker interface?

What types of partitioning are there for BW?



Search
Can you Answer!!
  • Q How to check property of specific icon is highlighted or not
  • Q What specifically do you do to set examples to your fellow employees?
  • Q How does visual foxpro 9.0 compare to sql server?
  • Q What classes of exceptions may be caught by a catch clause?
  • Q Pakistan became Islamic Republic in: a. 1947 b. 1956 c. 1962 d. None of these.
  • Q Two tables are given.In 1st table 2 columns are there.one is Employee no,second is salary.In second table 3 columns are there,one is employee no,second is date,3rd is salary. Select employee no,from table1,table 2. How many records it will contain?.
  • Q Whose autobiography is ‘Playing It My Way’?
  • Q What Symbian platform products does Nokia offer?
  • Q Is there real-time audio keyframing with audio fader?
  • Q What are the integration services in SQL Server?
  • Q What is input injection and what are different ways of doing it ?