jMeter - Selenium integration
I have jMeter test case already written, it has requests for logging in and some POST requests to my table.
Now I want to measure render time of the page (response of the POSTS).
I want to use Selenium so I read:
Running Selenium scripts with JMeter
The problem is that i want Selenium to use the same session (in other words: to be already logged in) as logging in was handled by jMeter already.
How can i archive that ?
My TestPlan:
[UPDATE]
@Dmitri T
Thanks for answer! I did what you have suggested but it still don't work. Maybe I am doing something wrong but still just after Selenium opens browser it goes to login page. I put JSR223 PostProcessor under my LOGIN POST request and this is my WebDriver Sampler:
var pkg = JavaImporter(org.openqa.selenium);
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait);
var wait = new support_ui.WebDriverWait(WDS.browser, 5000);
WDS.sampleResult.sampleStart();
WDS.sampleResult.getLatency();
WDS.log.info("Sample started");
WDS.browser.get(WDS.parameters);
WDS.log.info("LOGGING INTO: " + (WDS.parameters))
var cookieManager = WDS.vars.getObject('cookieManager')
for (var i=0; i < cookieManager.getCookieCount(); i++) {
var jmeterCookie = cookieManager.getCookies().get(i)
var seleniumCookie = new org.openqa.selenium.Cookie(jmeterCookie.name, jmeterCookie.value, jmeterCookie.domain, jmeterCookie.path, java.util.Date.from(java. time.Instant.ofEpochMilli(jmeterCookie.expiresMillis)), jmeterCookie.secure)
WDS.browser.manage().addCookie(seleniumCookie)
}
java.lang.Thread.sleep(5000)
WDS.sampleResult.sampleEnd();
{UPDATE 2}
Ok, i think that htere is something wrong with Cookies in all Thread Group.
I have [no cookies] on every request:
selenium jmeter integration
add a comment |
I have jMeter test case already written, it has requests for logging in and some POST requests to my table.
Now I want to measure render time of the page (response of the POSTS).
I want to use Selenium so I read:
Running Selenium scripts with JMeter
The problem is that i want Selenium to use the same session (in other words: to be already logged in) as logging in was handled by jMeter already.
How can i archive that ?
My TestPlan:
[UPDATE]
@Dmitri T
Thanks for answer! I did what you have suggested but it still don't work. Maybe I am doing something wrong but still just after Selenium opens browser it goes to login page. I put JSR223 PostProcessor under my LOGIN POST request and this is my WebDriver Sampler:
var pkg = JavaImporter(org.openqa.selenium);
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait);
var wait = new support_ui.WebDriverWait(WDS.browser, 5000);
WDS.sampleResult.sampleStart();
WDS.sampleResult.getLatency();
WDS.log.info("Sample started");
WDS.browser.get(WDS.parameters);
WDS.log.info("LOGGING INTO: " + (WDS.parameters))
var cookieManager = WDS.vars.getObject('cookieManager')
for (var i=0; i < cookieManager.getCookieCount(); i++) {
var jmeterCookie = cookieManager.getCookies().get(i)
var seleniumCookie = new org.openqa.selenium.Cookie(jmeterCookie.name, jmeterCookie.value, jmeterCookie.domain, jmeterCookie.path, java.util.Date.from(java. time.Instant.ofEpochMilli(jmeterCookie.expiresMillis)), jmeterCookie.secure)
WDS.browser.manage().addCookie(seleniumCookie)
}
java.lang.Thread.sleep(5000)
WDS.sampleResult.sampleEnd();
{UPDATE 2}
Ok, i think that htere is something wrong with Cookies in all Thread Group.
I have [no cookies] on every request:
selenium jmeter integration
add a comment |
I have jMeter test case already written, it has requests for logging in and some POST requests to my table.
Now I want to measure render time of the page (response of the POSTS).
I want to use Selenium so I read:
Running Selenium scripts with JMeter
The problem is that i want Selenium to use the same session (in other words: to be already logged in) as logging in was handled by jMeter already.
How can i archive that ?
My TestPlan:
[UPDATE]
@Dmitri T
Thanks for answer! I did what you have suggested but it still don't work. Maybe I am doing something wrong but still just after Selenium opens browser it goes to login page. I put JSR223 PostProcessor under my LOGIN POST request and this is my WebDriver Sampler:
var pkg = JavaImporter(org.openqa.selenium);
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait);
var wait = new support_ui.WebDriverWait(WDS.browser, 5000);
WDS.sampleResult.sampleStart();
WDS.sampleResult.getLatency();
WDS.log.info("Sample started");
WDS.browser.get(WDS.parameters);
WDS.log.info("LOGGING INTO: " + (WDS.parameters))
var cookieManager = WDS.vars.getObject('cookieManager')
for (var i=0; i < cookieManager.getCookieCount(); i++) {
var jmeterCookie = cookieManager.getCookies().get(i)
var seleniumCookie = new org.openqa.selenium.Cookie(jmeterCookie.name, jmeterCookie.value, jmeterCookie.domain, jmeterCookie.path, java.util.Date.from(java. time.Instant.ofEpochMilli(jmeterCookie.expiresMillis)), jmeterCookie.secure)
WDS.browser.manage().addCookie(seleniumCookie)
}
java.lang.Thread.sleep(5000)
WDS.sampleResult.sampleEnd();
{UPDATE 2}
Ok, i think that htere is something wrong with Cookies in all Thread Group.
I have [no cookies] on every request:
selenium jmeter integration
I have jMeter test case already written, it has requests for logging in and some POST requests to my table.
Now I want to measure render time of the page (response of the POSTS).
I want to use Selenium so I read:
Running Selenium scripts with JMeter
The problem is that i want Selenium to use the same session (in other words: to be already logged in) as logging in was handled by jMeter already.
How can i archive that ?
My TestPlan:
[UPDATE]
@Dmitri T
Thanks for answer! I did what you have suggested but it still don't work. Maybe I am doing something wrong but still just after Selenium opens browser it goes to login page. I put JSR223 PostProcessor under my LOGIN POST request and this is my WebDriver Sampler:
var pkg = JavaImporter(org.openqa.selenium);
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait);
var wait = new support_ui.WebDriverWait(WDS.browser, 5000);
WDS.sampleResult.sampleStart();
WDS.sampleResult.getLatency();
WDS.log.info("Sample started");
WDS.browser.get(WDS.parameters);
WDS.log.info("LOGGING INTO: " + (WDS.parameters))
var cookieManager = WDS.vars.getObject('cookieManager')
for (var i=0; i < cookieManager.getCookieCount(); i++) {
var jmeterCookie = cookieManager.getCookies().get(i)
var seleniumCookie = new org.openqa.selenium.Cookie(jmeterCookie.name, jmeterCookie.value, jmeterCookie.domain, jmeterCookie.path, java.util.Date.from(java. time.Instant.ofEpochMilli(jmeterCookie.expiresMillis)), jmeterCookie.secure)
WDS.browser.manage().addCookie(seleniumCookie)
}
java.lang.Thread.sleep(5000)
WDS.sampleResult.sampleEnd();
{UPDATE 2}
Ok, i think that htere is something wrong with Cookies in all Thread Group.
I have [no cookies] on every request:
selenium jmeter integration
selenium jmeter integration
edited Dec 31 '18 at 10:15
bmrki
asked Dec 31 '18 at 8:22
bmrkibmrki
245
245
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
In order to pass the "session" you need to copy all the cookies from JMeter's HTTP Cookie Manager into the Selenium session.
This can be done in the WebDriver Sampler directly as follows:
- Add JSR223 PostProcessor as a child of the request which session you want to copy
Put the following code into "Script" area
vars.putObject('cookieManager', sampler.getCookieManager())
it will store the current state of the HTTP Cookie Manager into JMeter Variables
In the WebDriver Sampler you can copy the cookies from the HTTP Cookie Manager and add them to the WebDriver instance using WDS.browser.manage().addCookie() function as follows:
var cookieManager = WDS.vars.getObject('cookieManager')
for (var i=0; i < cookieManager.getCookieCount(); i++) {
var jmeterCookie = cookieManager.getCookies().get(i)
var seleniumCookie = new org.openqa.selenium.Cookie(jmeterCookie.name, jmeterCookie.value, jmeterCookie.domain, jmeterCookie.path, java.util.Date.from(java.time.Instant.ofEpochMilli(jmeterCookie.expiresMillis)), jmeterCookie.secure)
WDS.browser.manage().addCookie(seleniumCookie)
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985187%2fjmeter-selenium-integration%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In order to pass the "session" you need to copy all the cookies from JMeter's HTTP Cookie Manager into the Selenium session.
This can be done in the WebDriver Sampler directly as follows:
- Add JSR223 PostProcessor as a child of the request which session you want to copy
Put the following code into "Script" area
vars.putObject('cookieManager', sampler.getCookieManager())
it will store the current state of the HTTP Cookie Manager into JMeter Variables
In the WebDriver Sampler you can copy the cookies from the HTTP Cookie Manager and add them to the WebDriver instance using WDS.browser.manage().addCookie() function as follows:
var cookieManager = WDS.vars.getObject('cookieManager')
for (var i=0; i < cookieManager.getCookieCount(); i++) {
var jmeterCookie = cookieManager.getCookies().get(i)
var seleniumCookie = new org.openqa.selenium.Cookie(jmeterCookie.name, jmeterCookie.value, jmeterCookie.domain, jmeterCookie.path, java.util.Date.from(java.time.Instant.ofEpochMilli(jmeterCookie.expiresMillis)), jmeterCookie.secure)
WDS.browser.manage().addCookie(seleniumCookie)
}
add a comment |
In order to pass the "session" you need to copy all the cookies from JMeter's HTTP Cookie Manager into the Selenium session.
This can be done in the WebDriver Sampler directly as follows:
- Add JSR223 PostProcessor as a child of the request which session you want to copy
Put the following code into "Script" area
vars.putObject('cookieManager', sampler.getCookieManager())
it will store the current state of the HTTP Cookie Manager into JMeter Variables
In the WebDriver Sampler you can copy the cookies from the HTTP Cookie Manager and add them to the WebDriver instance using WDS.browser.manage().addCookie() function as follows:
var cookieManager = WDS.vars.getObject('cookieManager')
for (var i=0; i < cookieManager.getCookieCount(); i++) {
var jmeterCookie = cookieManager.getCookies().get(i)
var seleniumCookie = new org.openqa.selenium.Cookie(jmeterCookie.name, jmeterCookie.value, jmeterCookie.domain, jmeterCookie.path, java.util.Date.from(java.time.Instant.ofEpochMilli(jmeterCookie.expiresMillis)), jmeterCookie.secure)
WDS.browser.manage().addCookie(seleniumCookie)
}
add a comment |
In order to pass the "session" you need to copy all the cookies from JMeter's HTTP Cookie Manager into the Selenium session.
This can be done in the WebDriver Sampler directly as follows:
- Add JSR223 PostProcessor as a child of the request which session you want to copy
Put the following code into "Script" area
vars.putObject('cookieManager', sampler.getCookieManager())
it will store the current state of the HTTP Cookie Manager into JMeter Variables
In the WebDriver Sampler you can copy the cookies from the HTTP Cookie Manager and add them to the WebDriver instance using WDS.browser.manage().addCookie() function as follows:
var cookieManager = WDS.vars.getObject('cookieManager')
for (var i=0; i < cookieManager.getCookieCount(); i++) {
var jmeterCookie = cookieManager.getCookies().get(i)
var seleniumCookie = new org.openqa.selenium.Cookie(jmeterCookie.name, jmeterCookie.value, jmeterCookie.domain, jmeterCookie.path, java.util.Date.from(java.time.Instant.ofEpochMilli(jmeterCookie.expiresMillis)), jmeterCookie.secure)
WDS.browser.manage().addCookie(seleniumCookie)
}
In order to pass the "session" you need to copy all the cookies from JMeter's HTTP Cookie Manager into the Selenium session.
This can be done in the WebDriver Sampler directly as follows:
- Add JSR223 PostProcessor as a child of the request which session you want to copy
Put the following code into "Script" area
vars.putObject('cookieManager', sampler.getCookieManager())
it will store the current state of the HTTP Cookie Manager into JMeter Variables
In the WebDriver Sampler you can copy the cookies from the HTTP Cookie Manager and add them to the WebDriver instance using WDS.browser.manage().addCookie() function as follows:
var cookieManager = WDS.vars.getObject('cookieManager')
for (var i=0; i < cookieManager.getCookieCount(); i++) {
var jmeterCookie = cookieManager.getCookies().get(i)
var seleniumCookie = new org.openqa.selenium.Cookie(jmeterCookie.name, jmeterCookie.value, jmeterCookie.domain, jmeterCookie.path, java.util.Date.from(java.time.Instant.ofEpochMilli(jmeterCookie.expiresMillis)), jmeterCookie.secure)
WDS.browser.manage().addCookie(seleniumCookie)
}
answered Dec 31 '18 at 9:12
Dmitri TDmitri T
71.1k33660
71.1k33660
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985187%2fjmeter-selenium-integration%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown