script to check entire website to figure out if there are any pages which are taking more time to load - selenium

Can we have a script which will crawl through the entire website to figure out if there are any pages which are taking more time to load (some pages under a particular category were taking more time to load) in selenium Webdriver or jmeter

For JMeter you can use HTML Link Parser configuration element for this purposes. From the documentation:
Spidering Example
Consider a simple example: let's say you wanted JMeter to "spider" through your site, hitting link after link parsed from the HTML returned from your server (this is not actually the most useful thing to do, but it serves as a good example). You would create a Simple Controller, and add the "HTML Link Parser" to it. Then, create an HTTP Request, and set the domain to ".*", and the path likewise. This will cause your test sample to match with any link found on the returned pages. If you wanted to restrict the spidering to a particular domain, then change the domain value to the one you want. Then, only links to that domain will be followed.
More information on above approach and a couple more options: How to Spider a Site with JMeter - A Tutorial
Remember that JMeter is not a browser hence it doesn't execute JavaScript so your results may not be precise enough as JMeter doesn't measure the time required to actually render the page.

Related

Client-side automation using PageSpeed Insights - how to transmit results like <URL>_<metric> into Summary(/Aggregate) Report in JMeter?

I'm thinking on solution to automate client-side using Lighthouse or PageSpeed Insights in JMeter.
With PageSpeed Insights, using requests like
https://pagespeed.web.dev/report?url=%2F&form_factor=mobile
https://pagespeed.web.dev/report?url=%2F&form_factor=desktop
it is possible to get web-page which contains client-side metrics and parse out their values to variables:
URL_First Contentful Paint (FCP)
URL_First Input Delay (FID)
URL_Largest Contentful Paint (LCP)
URL_Cumulative Layout Shift (CLS)
URL_Speed Index
URL_Time to Interactive
URL_Total Blocking Time
...
i.e. URL_metric - as variable name, where both URL and metric could change.
The question is, if I want to see the results statistics in JMeter "Summary Report" or "Aggregate Report" view for each combination of URL and metric, what is the best way to pass these variables names (URL_metric) as Label in JMeter?
You could dump the saved values to a file in usual JMeter output format (JTL):
{timestamp},{duration},{sample_name},200,OK,thread_group_name 1-1,text,true,,0,0,20,65,null,0,0,0\n
Curly brackets denote placeholders.
You already have durations and sample names, timestamps do not matter in your case since you only wish to have aggregated results.
After saving the data to a file you could open it with Summary Report or Aggregate Report.
In order to get client-side metrics you will need a real browser, as per JMeter project main page:
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
So in order to get client-side metrics from JMeter you need to kick off a real browser, for example take a look at WebDriver Sampler which provides JMeter integration with Selenium browser automation framework, check out Mixing Selenium Into Your Load Scenario for more details.
Once you have the metrics you can store them into JMeter's Sample Variables and plot them in custom charts of the HTML Reporting Dashboard

fetching intermediate redirect URL

How to fetch query parameter from intermediate redirect URL when you land on final URL in selenium.
I need to test whether a certain query param exists in one of the intermediate redirect URLs that are hit before finally I land on a final destination URL in selenium tests. Is there any easy way to pull the redirect URLs or maybe save them as a list?Example redirects
Like Nandan suggested, your best option is to capture network logs or use a different tool.
Selenium attempts to interact with the browser the same way an end-user would. Since an end-user is unlikely to care (or even notice) an intermediate URL, Selenium doesn't really offer a reliable way to check the query params.
When transitioning between pages, in most cases Selenium waits for the page to be fully loaded before it allows your code to interact with it. This means that it's unlikely anything you do try to grab the param (like checking the page URL) will be unsuccessful.
Something you could try is using Selenium's Javascript Executor to check the referrer. This might not work; Some pages disable or edit it. But it's worth a shot.
Wait until your final page is loaded, then use the execute_script method (or it's equivalent for your Selenium bindings) to grab the referrer:
driver.execute_script "return document.referrer"
Then, use String methods to find your query param.

whats the best to test a link in site as part of e2e test

we have a page with several links and our automation clicks on a link and checks if it does not give a 404 and if the link has our company name. Is this a good way to test links in a page or is there is a better way to test links as part of e2e?
Yes, we need to click all the links one by one and verify the links should not broken. This is how we do in manual testing right? It should still implies the same in test automation.
For the verification part, you may also include some more testing on the page that you just clicked:
Validate the locator or specific web element is present there (can check it's xpath).
Validate some text should contain on that page as expected.
We can also check how many seconds it takes to completely load the page. So, you can find out if there is any web page/link is having bad response time. Every test automation framework has different way to do this.

How to check in jmeter if entered fields remain same in the first page after navigating back from nth page

I want to test a page.Where i want to fill up the fields like first name last name etc.and after going two pages further if i come back to the original page by using back navigation ,data entered for first name and last name remains the same.or it is filled up.
In jmeter i want to check the same if data entered for the fields remain same if i navigate back .
How can i achieve this.
I tried gving url directly in the path its not happening since it is not the way.
please help me since i'm new to jmeter.
You need to understand 2 things. How JMeter works and how your application works.
JMeter only captures data that is communicated to server. It does not matter how data is entered from UI. It does not check if data retains in the fields or not. It only records the request that is sent by your application to server-side.
So, if you understand above, you also need to understand how your application sends data to server. Does it sends the request as you move from first page to second. Or does it send (Submit) data on final page.
Either way, JMeter is not a tool to test if your form fields are retaining data in them as you navigate between pages. As mentioned earlier it only monitors data requests/responses.
Selenium seems a better option for your test requirement.
Please read the apache documentation carefully:
JMeter is not a browser. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever viewed at a time).
First, you have to understand how JMeter works!!! To do the Functional Testing, Selenium would be a good choice.
Thanks

jMeter simulate user's progress through site

I'm a newbie to jMeter, so please bear with me.
I've been assigned the task of testing how an e-commerce website responds under load. I've managed to set up basic tests in jMeter that basically just repeatedly visit the home page, but I'd like to simulate something a bit more realistic:
User arrives on home page
User goes to catalogue page
User views product
User adds product to cart
User returns to catalogue, selects another product, adds to cart
User removes first product from cart
User proceeds to checkout
User completes checkout process.
I'm having trouble finding adequate documentation to explain how to do this. I figured out that I need a cookie manager in my test so that the user session will be maintained, but I haven't figured out how to get the user to traverse the site in a realistic use pattern (such as the one described above). Can anyone help out with this, give me some pointers as where to look for good examples, etc?
This should be no problem, record or manually create the necessary steps as HTTP Samplers, then add them into a Runtime Controller for example to execute them iteratively.
The individual steps will be executed in the order they are in the tree and, in case Cookies are used to handle session state, you might need to add the Cookie Manager to the top of the tree which will handle cookie headers for each user.
Add some timers to simulate user's think time and scale up by increasing the number of virtual users in the thread group.
Use some listener like the Aggregate Report to view the response times for every step.
Try to read http://jmeter.apache.org/usermanual/index.html at first.
Also you'll encounter the problem that Jmeter can't process dynamic pages:
http://wiki.apache.org/jmeter/JMeterFAQ#Does_JMeter_process_dynamic_pages_.28e.g._Javascript_and_applets.29
Does JMeter process dynamic pages (e.g. Javascript and applets)?
No. JMeter does not process Javascript or applets embedded in HTML pages.
JMeter can download the relevant resources (some embedded resources are downloaded automatically if the correct options are set), but it does not process the HTML and execute any Javascript functions.
If the page uses Javascript to build up a URL or submit a form, you can use the Proxy Recording facility to create the necessary sampler. If this is not possible, then manual inspection of the code may be needed to determine what the Javascript is doing.