How to simulate a ‘block request url’ using webdriverjs - selenium

I have a test where I want to check that if a request is blocked, the appropriate error message is displayed on the page. Using chrome, this can be done via Network tab > Right click on request > Block request url. However, I'm trying to automate this url blocking process and would like to know if this is possible in a WebDriverJs setup

Related

Find the HTTP method used to open a new page in Selenium

I am using Selenium with Python and Behave to test a web application. I could not figure out what HTTP method my web application uses to open a new page in a new tab using Selenium. Our application integrates with many internal microservices and we have the UI that makes an API call upon a click event and the the api response for a given call would come back with a URL to redirect to and the HTTP method to use for the redirect.
In my test I want to assert the URL that we redirect to and the HTTP method(GET/POST) our web application used in the new tab to redirect to. I was able to switch to the new tab and assert the URL but not the HTTP method.
Has anyone run into this? Thanks in advance

Getting webdriver exception: unknown error: unhandled inspector error...cannot navigate to URL

I am using:
driver.get(“www.google.com”)
The script is not running from this line of code
And if i use:
driver.get(“https://www.google.com”)
It start working
Can anybody please help me out why it is working with https and not working without https?
It is inbuilt implementation of Method get(); and navigate().to(); which work on HTTP GET request.
This is Declaration By method itself:
Load a new web page in the current browser window. This is done using
an HTTP GET operation, and the method will block until the load is
complete. This will follow redirects issued either by the server or as
a meta-redirect from within the returned HTML. Should a meta-redirect
"rest" for any duration of time, it is best to wait until this timeout
is over, since should the underlying page change whilst your test is
executing the results of future calls against this interface will be
against the freshly loaded page.
Parameters: url The URL to load. It is best to use a fully qualified URL
However When we use same string in Browser and it works. Because Browser has it default HTTP protocol and based on that if we don't text http:// or https:// it automatically convert String in to URL.
Here transformation made via get(); method to Browser, and As declared by method it needs URL and not String. Thus it retrieve this Exception.

Capture the URL in the javascript initiated HTTP GET/POST requests using selenium

I'm using selenium for automating a procedure I frequently use on a site.
When I press on specific element on the site it runs some complex javascript code that eventually downloads a csv file using HTTP GET request.
I can see that the URL of this request looks like: www.somesite.com/somepage.php?token=RAPO09834HROLQ340HGIE309W&....
My question is: how can I get the token in this URL with selenium? (I need it for executing other HTTP GET requests for extracting more data from the site)
I am using Firefox driver on windows.
I tried to search all the html, js, cookies I get from this site, the token is not there. (its probably generated by the javascript code before it does the HTTP request)
I understand this is some kind of session id token as all the javascript generated HTTP requests are using the same token during my session.

Capture JSON response through Selenium

I'm testing a webpage using Selenium (either IDE or webdriver). The webpage has a "search" function, basically just a GET call with params. The javascript also output to console the JSON returned from the search call, i.e. something like console.log(data). And I'm able to inspect the response data in Firefox console.
My question is: is there anyway I can capture this data from Firefox console in Selenium (so that I can further inspect and doing asserts)? Writing a direct GET request (eg, from Python) does not work since the search url is protected through a login page.
Thanks.
AFAIK Selenium doesnt provide any in built API/method to play with console.
You can redirect console output file and read from file.
Link: How to redirect Firefox console output to file.
It was possible at one point using Firebug. Not sure if it still works.

Selenium testing with HTML Selenese

I am doing some testing in Selenium using the selenium maven plugin and HTML selenese scripts.
Everything works pretty well except for this scenario I have:
I am clicking on a submit button and it takes me to a redirect url. The server for that URL is not running but the web service that redirect the URL create a code query parameter and add it to the redirect URL.
I want to be able to click submit and use storeLocation selenese command to extract the redirect url and extract that code parameter. When I use clickAndWait, the redirect happens but the test fails because the page tries to load and eventually the maven build. When I use just click command, the test passes, but the page doesn't load and storeLocation doesn't contain the value of the redirect url I need with the code parameter.
Anyone know how to get selenium to click and wait but IGNORE the fact that the page will not load?
I think it needs to involve some javascript and maybe the use of waitForCondition command but I can't find any example of it being done.
basically, the redirect URL has no server running it, but my service create a token param that I need to extract from and pass it to another test case
Is the page load timing out? If so you could increase the default timeout (should be 30 seconds though) or you can use the click event, and then do a waitForLocation to match the new URL (with redirect parameter) you want. This will give you another wait for (like click and wait) of 30 seconds. But you can also add a pause command between the click and the wait for to extend your time for the page to load without touching the default time out.