I have a scenario where I need to click on a button in the Web page which will do a process. Once I click on this button "process in progress" message will appear. I am waiting for this message to disappear from the web page for the next action.
This process will take time between 30 to 150 secs which I don't have control.So I have given a wait time of 180 secs in the sampler. The issue is some time the process will complete in 30 secs and webdriver will wait for 180 secs to complete for the next action. In this case application will log out because inactive user settings.
How to handle this situation?
You can use ExpectedConditions.presenceOfElementLocated combined with WebDriverWait.
It would wait at max 150s but if element is available before it doesn't wait that much:
var wait = new pkg.WebDriverWait(WDS.browser, 150);
wait.until(pkg.ExpectedConditions.presenceOfElementLocated(
pkg.By.cssSelector('ul.suggestions')))
See full details here:
https://jmeter-plugins.org/wiki/WebDriverSampler/
You can go for ExpectedConditions.invisibilityOfElementLocated(By) function which can be used via Explicit Wait so WebDriver will poll the DOM until the element disappears with the maximum of 150 seconds, default polling interval is 500 milliseconds, however it can be adjusted as required.
Example code would be something like:
var wait = new WebDriverWait(WDS.browser, 150)
wait.pollingEvery(1, java.util.concurrent.TimeUnit.SECONDS)
org.openqa.selenium.support.ui.ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[contains(text('process in progress')]"))
More information: The WebDriver Sampler: Your Top 10 Questions Answered
Related
I am doing load testing on generating report and the requirement is like the report should get generated within 10mins.
It includes one HTTP post request for report generation, and then there is a status check call, which keeps on checking the status of the first request. Once the status of first request changes to complete then the report generation is successful.
Basically I want to start the timer at the begining of the first request and stop the timer once the status is complete and need to add assertion if the time is less than 10 mins then test is pass else fail.
I tried multiple approaches like using Transaction controller, and adding all request under it. But this doesn't give sum but the average response time of all the request under it.
Also, I tried beanshell listener, extracting the response time for every request and adding them all...
var responseTime;
props.put("responseTime", sampleResult.getTime());
log.info(" responseTime :::" + props.get("responseTime"));
log.info("time: "+ sampleResult.getTime());
props.put("responseTime", (sampleResult.getTime()+props.get("responseTime")));
log.info("new responseTime :::" + props.get("responseTime"));
However, I am not interested in adding the response time of these requests, instead I need to just know what is the time elapsed from when the report is triggered and till it gives status as complete.
All the jmeter timers are adding delays, I dnt wish to add delay instead I need it as a timer.
Any help is highly appreciated.
Thank you
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting mainly due to performance reasons so I'll provide one of possible solutions in Grovy
Add JSR223 PostProcessor as a child of the HTTP Request which kicks off the report generation and put the following code there:
vars.putObject('start', System.currentTimeMillis())
Add JSR223 Sampler after checking the status and put the following code there:
def now = System.currentTimeMillis()
def start = vars.getObject('start')
def elapsed = now - start
if (elapsed >= 600000) {
SampleResult.setSuccessful(false)
SampleResult.setResponseMessage('Report generation took: ' + (elapsed / 1000 / 60) + ' minutes instead of 10')
}
Example setup:
I am testing my app using Cypress, in my app there is a one minute timer. When the timer expires, no button should work. To put it more precisely, even though the user clicks on buttons, nothing should happen (functions connected to those buttons should not be triggered). How can I test such a thing?
cy.get('#timer-btn').click().wait(60000)
cy.get('#timer').should('have.text', 'TIME IS UP, your score is: 0')
cy.get('.btn').click()
//???
I believe you could use cy.clock() and .tick() to manipulate the time the browser thinks has passed
cy.clock();
cy.get('#timer-btn').click();
cy.tick(60000);
cy.get('#timer').should('have.text', 'TIME IS UP, your score is: 0');
cy.get('.btn').click();
Instead of using wait use timeout because wait waits for a total of 60 seconds, but with a timeout, it is terminated whenever the expected condition is met.
cy.get('#timer-btn').click()
cy.get('#timer', {timeout: 60000}).should(
'have.text',
'TIME IS UP, your score is: 0'
)
cy.get('.btn').click()
Now if the button is disabled after 60 seconds you can use:
cy.get('#timer-btn').click()
cy.get('#timer', {timeout: 60000}).should(
'have.text',
'TIME IS UP, your score is: 0'
)
cy.get('.btn').should('be.disabled')
Now, if you see on comparing the HTML of the button during and after the timer, if any attribute-value pair is added to the button after the timer is completed, you can assert that using:
cy.get('#timer-btn').click()
cy.get('#timer', {timeout: 60000}).should(
'have.text',
'TIME IS UP, your score is: 0'
)
cy.get('.btn').should('have.attr', 'attr-name', 'attr-value')
If you see just an attribute is added you can just use
cy.get('.btn').should('have.attr', 'attr-name')
My problem is that I see the load time for a web page element on a test in jMeter # 200 miliseconds and when browsing, most of the time I get 3 or 4 seconds, in the condition where the size in bytes is # 331000.
I must mention that I cleared the cache and cookies for each iteration and I inserted also the constant timer between the steps.
The searching an id is the actual case described previously.
var pkg = JavaImporter(org.openqa.selenium);
var wait_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait);
var wait = new wait_ui.WebDriverWait(WDS.browser, 5000);
WDS.sampleResult.sampleStart()
var searchBox = WDS.browser.findElement(pkg.By.id("140:0;p"));
searchBox.click();
searchBox.sendKeys("1053606032");
searchBox.sendKeys(org.openqa.selenium.Keys.ENTER);
WDS.sampleResult.sampleEnd()
I expected to see the same load time results, but maybe an option would be if I wait until some elements on the search results page are visible. But I cannot bring an argument why is this difference. I had another case where the page loads in 10 seconds in Chrome and in jMeter Test Results 300 miliseconds.
Please try with wait until for a specific element which loads as close as the page load.
Below is another try for the same. Use the below code and check if this helps:-
WDS.sampleResult.sampleStart()
WDS.browser.get('http://jmeter-plugins.org')
//(JavascriptExecutor)WDS.browser.executeScript("return document.readyState").toString().equals("complete")
WDS.browser.executeScript("return document.readyState").toString().equals("complete")
WDS.sampleResult.sampleEnd()
For me without execute script page loads in 3 sec and with executeScript it loads in 7 sec..while in browser that loads in around 7.57sec..
Hope this helps.
I want log the current time to the JMeter log from the JMeter Webdriver sampler.
I am using the below code in the Webdriver sampler which is logging the time in milliseconds but the problem is my Webdriver sampler has a waiting time of 2 minutes. The getStartTime() and getEndTime() functions are considering the sampler waiting time also.
Is it any other way to get the current time from the Webdriver sampler? I want to measure the time taken between two actions in the browser.
WDS.log.info(WDS.sampleResult.getStartTime())
WDS.log.info('WDS.sampleResult.getEndTime())
You can record start and end time using Date.prototype.getTime() function like:
var before = new Date().getTime()
// here is the code which duration you would like to measure
var after = new Date().getTime()
WDS.log.info('Time taken = ' + (after - before) + ' ms')
Demo:
See The WebDriver Sampler: Your Top 10 Questions Answered for more WebDriver sampler tips and tricks
Exclude the wait time by covering only the required code block with the start time and end time function.
Ex:-
WDS.log.info(WDS.sampleResult.getStartTime())
---some code
WDS.log.info('WDS.sampleResult.getEndTime())
Wait for two minutes..wait(2)
WDS.log.info(WDS.sampleResult.getStartTime())
--some code
WDS.log.info('WDS.sampleResult.getEndTime())
In this way, wait time is excluded from the calculation.
This is not the best solution but one which I can think of.
I have a scenario recorded in Jmeter.
Login -> Home Page -> Click on the link to open Page A -> Page A opened -> Click on the tab to open Page B -> Page B opened -> Log off
I executed above scenario with 5 users, Ramp up 20 sec, Loop Count Forever, Scheduler Duration 300 seconds.
Less User Thread
All of the samples were Pass. (Screen shot attached)
Result
I executed with 10 users, Ramp up 20 sec, Loop Count Forever, Scheduler Duration 600 seconds.
[10 Users Thread][3]
This was also successful. (Screen shot attached)
Result
I increased users to 40, Ramp up 80 and checked Loop Count Forever(Scheduler not selected)
Failed Thread
Samples started failing after some 25 users. (Screen shot attached)
Result1
Response Data is empty for the requested Target page and response code is 200(Page A). (Screen shot attached)Result1
Response code is 500 for Page B. (Screen shot attached)Result2
I have increased the heapsize, also executed script from command prompt.
What could be the issue?
JavascriptError
After some research I got to know that, i have to use Web drivers. How can i integrate to Web driver samplers to my original scripts.