Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting HTTP headers of the url page response directly in a Nightwatch test #4250

Open
MurzNN opened this issue Aug 15, 2024 · 5 comments
Open

Comments

@MurzNN
Copy link

MurzNN commented Aug 15, 2024

Description

Pretty often we need to check not only the HTML content on the page of the response, but also HTTP headers of the response.

For example, some websites provide caching information about the page (cache hit or miss, cache tags), some additional technical information like a number of SQL queries, internal calls to 3rd-party services, etc. Or simply just get the HTTP response code (200, 304, 404, etc).

Now it is possible using the .network.captureRequests(), but it's quite hard to find the original request among others.

Another way is to use API Testing but it will require making another request, in addition to the current, if we have to check also HTML elements there, together with headers.

So, would be great to have the built-in functionality to get the headers directly from the response!

Suggested solution

Would be good to have something like this:

browser.url('https://www.google.com', {captureHeaders: true});
browser.waitForElementVisible('body', 1000);
const headers = browser.getHeaders();

Alternatives / Workarounds

If this is already possible using the current API, please share how to do this.

Additional Information

No response

@sonustar
Copy link

I will love to work on it !!

@ritankarsaha
Copy link

@MurzNN Will we be using browser.network.captureRequests() to capture requests or Use a request library like axios or fetch to make a request to the page and get headers?

@garg3133 garg3133 assigned garg3133 and unassigned garg3133 Nov 14, 2024
Harshit-7373 added a commit to Harshit-7373/nightwatch that referenced this issue Nov 17, 2024
Getting HTTP headers of the url page response directly in a Nightwatch test nightwatchjs#4250

github- Harshit-7373
@Harshit-7373 Harshit-7373 mentioned this issue Nov 17, 2024
9 tasks
@MurzNN
Copy link
Author

MurzNN commented Dec 19, 2024

Will we be using browser.network.captureRequests() to capture requests or Use a request library like axios or fetch to make a request to the page and get headers?

Using browser.network.captureRequests() is not convenient because you have to enable it in advance, and then - try to find the needed request only manually, as I understood.

So, if the Browser API doesn't provide any way to get the HTTP headers directly, seems the only way is to use fetch(). Axios is an additional dependency that is not good.

@MurzNN
Copy link
Author

MurzNN commented Dec 19, 2024

I already implemented a custom Nightwatch command that does this using fetch() for the Drupal Test Helpers module in the issue https://www.drupal.org/project/test_helpers/issues/3478014 - and it works great! So, maybe let's implement the same way in Nigthwatch directly?

I created a draft PR with my implementation of this feature #4337 - please review it and your feedback about the idea and the implementation.

@ritankarsaha
Copy link

Will we be using browser.network.captureRequests() to capture requests or Use a request library like axios or fetch to make a request to the page and get headers?

Using browser.network.captureRequests() is not convenient because you have to enable it in advance, and then - try to find the needed request only manually, as I understood.

So, if the Browser API doesn't provide any way to get the HTTP headers directly, seems the only way is to use fetch(). Axios is an additional dependency that is not good.

yeahh okaayy !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants