How to load and render data: URL in browser using Codeception? - codeception

I need to load data:text/html, <html><body><img src=https://example.com/image.jpg></body></html> in Omnibox using Codeception, to render such web page in browser.
$I->amOnURL will fail because of Wrong URL passes, host and scheme not set
$I->ExecuteJS will fail because it is forbidden to use data: links by JS
Does anyone have any idea how it can be achieved ?

Related

Testcafe: How to ignore the failed xhr requests on the page that we are trying to test

While running testcafe, I could see an xhr request failing in the background and may be that is why I could not see the UI elements of the page getting loaded. I could see only one element loaded.
If I try to access the same webpage without testcafe, I could see the page elements loading normal although the xhr request is still failing in the background.
Could this failing xhr request be a reason for the page not showing all the UI elements when I do it through testcafe?
Is there a way to ignore some xhr requests like this in testcafe ?
To mock any request you can use RequestMock. For example:
const mock = RequestMock()
.onRequestTo('http://xhr-request/')
.respond('Mocked respond');
However, it may not resolve the problem. If it doesn't help, please, share a minimal working example with this template following this instruction.

How do I use window.location.href in codesandbox.io?

I'd like to use window.location.href in the tool codesandbox.io. This is because I want to do a test with a hard page load occurring. I'm running into an issue however.
location.href = "http://www.google.com"
I get this error:
Mixed Content: The page at 'https://codesandbox.io/s/lingering-bird-nyvfi' was loaded over HTTPS, but requested an insecure resource 'http://www.google.com/'. This request has been blocked; the content must be served over HTTPS.
Example: https://codesandbox.io/s/locationhref-usage-nyvfi (see src/index.ts and open Dev Console)
How do I accomplish this the ability to simulate a page load, in the fake virtual browser?
I think it may be possible once the security criteria are met; which is limiting.
Use HTTPS (Avoid mixed content)
Use same origin
Thus this works:
window.location.href = "https://www.codesandbox.io/docs";

URL Redirection in import.io

Hi I am working on URL http://www.goodtoknow.co.uk/recipes/healthy?page=1&cost_range=any&total_time=any&skill_level=any&tags%5B0%5D=Healthy&tags%5B1%5D=Healthy and creating extractor. But the URL gets redirected to the URL http://www.goodtoknow.co.uk/recipes/healthy automatically in import.io I want to create extractor for the first mentioned URL. Is it possible? Is it happening because of the page requires cookies which they does not support?
If you examine the network requests using chrome or any other web-debugger you can see that the website is calling a second URL for the recipie data:
http://www.goodtoknow.co.uk/recipes/search?q=&page=1&cost_range=any&total_time=any&skill_level=any&tags[0]=Healthy&tags[1]=Healthy&_=1458727079183
This url does not redirect without cookies and you can set the page number manually.
Try training using this URL and see if it avoids the redirecting.

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.