Don't stop on HTTP error 403 - error-handling

In one of my Selenium test cases, I try to ensure that certain pages can't be accessed. Instead, HTTP return code 403 should be given.
However, here Selenium terminates test execution with the following exception:
com.thoughtworks.selenium.SeleniumException: XHR ERROR: URL = http://user:password#www.example.com/admin Response_Code = 403 Error_Message = Forbidden
Any way to work around that?

Seems like I have to answer the question myself...
I now surround the "open" call with a try...catch block. There, I parse the exception message if it contains the 403 code and XHR ERROR. Seems to me not very clean, but it works.

I was trying to test for HTTP 403 errors using PHPUnit. I examined the PHPUnit Selenium Extension code and found that the driver ends the session as soon as it receives a bad response, and there does not appear to be a way to bypass this functionality.
I ended up using a try-catch solution and restarting the Selenium session:
try {
$this->open('restricted_url');
$this->assertTitle('The page cannot be displayed');
} catch (PHPUnit_Framework_Exception $e) {
$this->start();
}
When the Selenium session is restarted, all the session information is lost, as is to be expected, so you will need to build your session again in order to run more tests:
$this->loginAsGuest();
try {
$this->open('admin_url');
$this->assertTitle('The page cannot be displayed');
} catch (PHPUnit_Framework_Exception $e) {
$this->start();
$this->loginAsGuest();
}

I don't know what language you're using, but I think you can get around this by instructing Selenium to ignore the status code when opening a page.
In Ruby:
#browser.remote_control_command('open', [url, 'true'])
In C#:
((DefaultSelenium)selenium).Processor.DoCommand("open", new string[]{url, "true"}))
I believe the behavior in Selenium trunk is to now ignore the status code by default. So, you could try building that and see if it works out for you.

Related

Enter Key throws error when running WDIO on Browserstack

I'm trying to run some WDIO tests on Browserstack (#wdio/browserstack-service#7.24.0). Using chrome browser and Samsung Galaxy S20 capabilities. There is a point where I need to send Enter key, I'm using .keys('\uE007') and the action is performed on the device as expected, but there is an error coming from BS. ERROR webdriver: Request failed with status 404 due to Error: The URL '/wd/hub/session/0296501ef9a8127fa1f5663921d3b1e52463eaf1/actions' did not map to a valid resource
I tried to use try/catch to prevent that error marking my execution as failed, but try/catch does not stop it. My guess, it is because of async logic during they send key.
so, I need help to prevent that error or find a way to catch it properly.
any suggestion?

My jmeter Script is executing successfully even after the server is down. It is not throwing any errors and giving the response code as 200

i am doing a load test on one of our website.
My jmeter Script is executing successfully even after the server is down. It is not throwing any errors and also giving the response code as 200.
I have tried all other solutions like Response assertions but that is not helping me.
Can you guys help me with this? I am not sure of what i am missing here.
Server status
jmeter response
JMeter automatically treats HTTP Status Codes below 400 as successful, it doesn't do any extra checks of content so if your server responds with an OOM error but having non-error HTTP Status code - JMeter will consider it as OK.
Ideally in case of error your server should respond with HTTP Status Code 5xx so I would recommend raising an issue to correct the behaviour.
In the meantime consider adding a Response Assertion to explicitly check whether the response contains what it is supposed to be containing (or alternatively that it does not contain error word)
What is the response you get when you hit API from POSTMAN tool?
If you are getting 200 then please consult your developer to handle error code properly.
If you are getting 400 or 500, then there is something missing from your Response Assertion.

Client-side error monitoring that catches 404s and other script / resource errors?

I've been looking into New Relic, BugSnag, and a few others, but no one seems to be catching 404 errors in their client-side monitoring. For example, say I have the following script tag in a given page:
<script src="//cdn.example.com/app.js1445291270"></script>
with the minor but critical typo of missing a ? after .js.
This of course returns a 404 and the script never loads.
Are there any services that would catch client-side errors like this?
You should be able to do this with Bugsnag. You can detect whether the status= 404, and use Bugsnag.notifyException() to send the error in. Hope this helps!
TrackJS error monitoring supports this use case. Here is how to add monitoring for resource loading failures.

WP7 error: "The remote server returned an error: NotFound."

I have this code that it used to work, but at some specific time it stopped to work and returned the error "The remote server returned an error: NotFound."
WebClient deliciousWebClient = new WebClient();
deliciousWebClient.Credentials = Credentials;
deliciousWebClient.DownloadStringAsync(new Uri("https://api.del.icio.us/v1/tags/get"));
deliciousWebClient.DownloadStringCompleted += (s, ee) =>
{
if (ee.Error == null)
{
…
Any suggestion on this error?
In this code, the error is pointing to delicious endpoit, but the same error is happening with some other services...
The NotFound error is a classic 404 error, so it's possible that the API endpoint is down or that it changed on you.
I'd start by using Fiddler2 to make the requests manually. That'll help you figure out whether the issue is in your code somewhere or on the API side.
It's hard to get Fiddler working with the WP7 emulator, as you noted below. One trick I've used in the past when I got really desperate was to write a quick console app that used the same code that my Windows Phone app was executing. Then I was able to successfully intercept the traffic. It turned out that my request being properly formatted.

403 : Access forbidden selenium

I want to run my testcases with the help of parameters mentioned in the testSuite.xml file and use them in my test cases by mentioning
#Parameters({ "selenium.host", "selenium.port", "selenium.browser", "selenium.url" }) in my code.
Though, I started a standalone server with -trustAllSSLcertificates, the system is giving "403 access forbidden error". However, if I run the test cases individually, by hardcoding the port, URL, Host & browsername, it works fine.
Where am i going wrong?.....
BTW, I run my test cases using build.xml file. Here also i added the -trustAllSSLcertificates when starting the server. But still it does not work.
Please help.
When running Selenium WebDriver using selenium-server-standalone I kept getting this error.
HTTP ERROR: 403
Forbidden for Proxy
RequestURI=/session
Turns out that it was because I needed to use the url http://localhost:4444/wd/hub as the url for the RemoteWebDriver client to connect to.
I'm sure there are a number of things that could cause the HTTP ERROR: 403, but you may want to double-check that it's resolving to the correct base url.