Skip to content

Instantly share code, notes, and snippets.

@rajeshtaneja
Created June 24, 2015 08:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajeshtaneja/6790b403bdd0df2e296d to your computer and use it in GitHub Desktop.
Save rajeshtaneja/6790b403bdd0df2e296d to your computer and use it in GitHub Desktop.
Webdriver jmx
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.8" jmeter="2.13 r1665067">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="Site" elementType="Argument">
<stringProp name="Argument.name">Site</stringProp>
<stringProp name="Argument.value">http://rajesh.per.in.moodle.com/im</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">4</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">3</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<longProp name="ThreadGroup.start_time">1434948643000</longProp>
<longProp name="ThreadGroup.end_time">1434948643000</longProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
</ThreadGroup>
<hashTree>
<com.googlecode.jmeter.plugins.webdriver.config.FirefoxDriverConfig guiclass="com.googlecode.jmeter.plugins.webdriver.config.gui.FirefoxDriverConfigGui" testclass="com.googlecode.jmeter.plugins.webdriver.config.FirefoxDriverConfig" testname="jp@gc - Firefox Driver Config" enabled="true">
<stringProp name="WebDriverConfig.proxy_type">SYSTEM</stringProp>
<stringProp name="WebDriverConfig.proxy_pac_url"></stringProp>
<stringProp name="WebDriverConfig.http_host"></stringProp>
<intProp name="WebDriverConfig.http_port">8080</intProp>
<boolProp name="WebDriverConfig.use_http_for_all_protocols">true</boolProp>
<stringProp name="WebDriverConfig.https_host"></stringProp>
<intProp name="WebDriverConfig.https_port">8080</intProp>
<stringProp name="WebDriverConfig.ftp_host"></stringProp>
<intProp name="WebDriverConfig.ftp_port">8080</intProp>
<stringProp name="WebDriverConfig.socks_host"></stringProp>
<intProp name="WebDriverConfig.socks_port">8080</intProp>
<stringProp name="WebDriverConfig.no_proxy">localhost</stringProp>
<boolProp name="WebDriverConfig.maximize_browser">true</boolProp>
<boolProp name="WebDriverConfig.reset_per_iteration">false</boolProp>
<boolProp name="WebDriverConfig.dev_mode">false</boolProp>
<boolProp name="FirefoxDriverConfig.general.useragent.override.enabled">false</boolProp>
<boolProp name="FirefoxDriverConfig.network.negotiate-auth.allow-insecure-ntlm-v1">false</boolProp>
<collectionProp name="FirefoxDriverConfig.general.extensions"/>
<collectionProp name="FirefoxDriverConfig.general.preferences"/>
</com.googlecode.jmeter.plugins.webdriver.config.FirefoxDriverConfig>
<hashTree/>
<com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler guiclass="com.googlecode.jmeter.plugins.webdriver.sampler.gui.WebDriverSamplerGui" testclass="com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler" testname="Home page" enabled="true">
<stringProp name="WebDriverSampler.script">var pkg = JavaImporter(org.openqa.selenium)
WDS.sampleResult.sampleStart()
// Go to login page
WDS.browser.get(WDS.Site)
// Click on login link.
WDS.browser.findElement(pkg.By.cssSelector(&apos;span.login a&apos;)).click();
WDS.sampleResult.sampleEnd()
</stringProp>
<stringProp name="WebDriverSampler.parameters"></stringProp>
</com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler>
<hashTree/>
<com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler guiclass="com.googlecode.jmeter.plugins.webdriver.sampler.gui.WebDriverSamplerGui" testclass="com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler" testname="Login page" enabled="true">
<stringProp name="WebDriverSampler.script">var pkg = JavaImporter(org.openqa.selenium)
//var wait = new pkg.WebDriverWait(WDS.browser, 10)
// Enter username/password
var username = WDS.browser.findElement(pkg.By.id(&apos;username&apos;))
username.sendKeys([&apos;admin&apos;])
var password = WDS.browser.findElement(pkg.By.id(&apos;password&apos;))
password.sendKeys([&apos;test&apos;])
WDS.sampleResult.sampleStart()
// Press login button.
var button = WDS.browser.findElement(pkg.By.id(&apos;loginbtn&apos;))
button.click()
//wait.until(pkg.ExpectedConditions.presenceOfElementLocated(pkg.By.xpath(&apos;//a[.=\&apos;Log out\&apos;]&apos;)))
WDS.sampleResult.sampleEnd()
// Verif page
var results = WDS.browser.findElements(pkg.By.xpath(&apos;//a[.=\&apos;Log out\&apos;]&apos;))
if(results.empty) {
WDS.sampleResult.successful = false
WDS.sampleResult.responseMessage = &apos;Login failed.&apos;
}</stringProp>
<stringProp name="WebDriverSampler.parameters"></stringProp>
</com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler>
<hashTree/>
<com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler guiclass="com.googlecode.jmeter.plugins.webdriver.sampler.gui.WebDriverSamplerGui" testclass="com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler" testname="Log out" enabled="true">
<stringProp name="WebDriverSampler.script">// Go to login and enter user password
var pkg = JavaImporter(org.openqa.selenium)
WDS.sampleResult.sampleStart()
// Click on login link.
var logoutbutton = WDS.browser.findElement(pkg.By.xpath(&apos;/html//div[@class=\&apos;logininfo\&apos;]//a[.=\&apos;Log out\&apos;]&apos;))
logoutbutton.click();
WDS.sampleResult.sampleEnd()</stringProp>
<stringProp name="WebDriverSampler.parameters"></stringProp>
</com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler>
<hashTree/>
<JSR223Listener guiclass="TestBeanGUI" testclass="JSR223Listener" testname="JSR223 Listener" enabled="true">
<stringProp name="scriptLanguage">bsh</stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="cacheKey"></stringProp>
<stringProp name="script">import java.io.*;
import java.util.regex.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.util.JMeterUtils; // http://jakarta.apache.org/jmeter/api/org/apache/jmeter/util/JMeterUtils.html
import org.apache.jmeter.threads.JMeterContext; // http://jakarta.apache.org/jmeter/api/org/apache/jmeter/threads/JMeterContext.html
import org.apache.jmeter.samplers.SampleResult; // http://jakarta.apache.org/jmeter/api/org/apache/jmeter/samplers/SampleResult.html
MoodleResult(SampleResult result) {
Integer thread = ctx.getThreadNum();
String html = result.getResponseDataAsString();
String dbreads = &quot;0&quot;;
Pattern pdbreads = Pattern.compile(&quot;.*?DB reads/writes: (\\d+)/\\d+.*&quot;, Pattern.UNIX_LINES | Pattern.DOTALL);
Matcher mdbreads = pdbreads.matcher(html);
if (mdbreads.matches()) {
dbreads = mdbreads.group(1);
}
String dbwritesstr = &quot;0&quot;;
Pattern pdbwrites = Pattern.compile(&quot;.*?DB reads/writes: \\d+/(\\d+).*&quot;, Pattern.UNIX_LINES | Pattern.DOTALL);
Matcher mdbwrites = pdbwrites.matcher(html);
if (mdbwrites.matches()) {
dbwritesstr = mdbwrites.group(1);
}
Integer dbwrites = Integer.parseInt(dbwritesstr);
// Adding logs if required.
if (props.get(&quot;includelogs&quot;) != null) {
Pattern plogwrites = Pattern.compile(&quot;.*?Log DB writes (\\d+).*&quot;, Pattern.UNIX_LINES | Pattern.DOTALL);
Matcher mlogwrites = plogwrites.matcher(html);
if (mlogwrites.matches()) {
dbwrites = dbwrites + Integer.parseInt(mlogwrites.group(1));
}
}
String dbquerytime = &quot;0&quot;;
Pattern pdbquerytime = Pattern.compile(&quot;.*?DB queries time: (\\d+(\\.\\d+)?) secs.*&quot;, Pattern.UNIX_LINES | Pattern.DOTALL);
Matcher mdbquerytime = pdbquerytime.matcher(html);
if (mdbquerytime.matches()) {
dbquerytime = mdbquerytime.group(1);
}
String memoryused = &quot;0&quot;;
Pattern pmemoryused = Pattern.compile(&quot;.*?RAM: (\\d+(\\.\\d+)?)MB.*&quot;, Pattern.UNIX_LINES | Pattern.DOTALL);
Matcher mmemoryused = pmemoryused.matcher(html);
if (mmemoryused.matches()) {
memoryused = mmemoryused.group(1);
}
String filesincluded = &quot;0&quot;;
Pattern pfilesincluded = Pattern.compile(&quot;.*?Included (\\d+) files.*&quot;, Pattern.UNIX_LINES | Pattern.DOTALL);
Matcher mfilesincluded = pfilesincluded.matcher(html);
if (mfilesincluded.matches()) {
filesincluded = mfilesincluded.group(1);
}
String serverload = &quot;0&quot;;
Pattern pserverload = Pattern.compile(&quot;.*?Load average: (\\d+(\\.\\d+)?).*&quot;, Pattern.UNIX_LINES | Pattern.DOTALL);
Matcher mserverload = pserverload.matcher(html);
if (mserverload.matches()) {
serverload = mserverload.group(1);
}
String sessionsize = &quot;0&quot;;
Pattern psessionsize = Pattern.compile(&quot;.*?Session[^:]*: (\\d+(\\.\\d+)?[A-Z]{2}).*&quot;, Pattern.UNIX_LINES | Pattern.DOTALL);
Matcher msessionsize = psessionsize.matcher(html);
if (msessionsize.matches()) {
sessionsize = msessionsize.group(1);
}
String timeused = &quot;0&quot;;
Pattern ptimeused = Pattern.compile(&quot;.*?\&quot;timeused\&quot;&gt;(\\d+(\\.\\d+)?) secs.*&quot;, Pattern.UNIX_LINES | Pattern.DOTALL);
Matcher mtimeused = ptimeused.matcher(html);
if (mtimeused.matches()) {
timeused = mtimeused.group(1);
}
// Actual information collected about the sample by jmeter
String username = vars.get(&quot;username&quot;);
String name = StringUtils.rightPad(result.getSampleLabel(), 30);
String url = result.getUrlAsString();
Integer bytes = result.getBytes();
Long time = result.getTime();
Long latency = result.getLatency();
Long starttime = result.getStartTime();
String status = result.getResponseCode();
headerToString() {
String str = &quot;status | thread | &quot;;
str += StringUtils.rightPad(&quot;user&quot;, 10) + &quot; | &quot;;
str += StringUtils.rightPad(&quot;name&quot;, 30) + &quot; | db-r | db-w | &quot;;
str += StringUtils.rightPad(&quot;dbquerytime&quot;, 8) + &quot; | &quot;;
str += StringUtils.rightPad(&quot;memory&quot;, 8) + &quot; | &quot;;
str += StringUtils.rightPad(&quot;files&quot;, 6) + &quot; | &quot;;
str += StringUtils.rightPad(&quot;load&quot;, 6) + &quot; |&quot;;
return str;
}
toString() {
String str = StringUtils.rightPad(status, 6) + &quot; | &quot;;
str += StringUtils.rightPad(Integer.toString(thread), 6) + &quot; | &quot;;
str += StringUtils.rightPad(username, 10) + &quot; | &quot;;
str += StringUtils.rightPad(name, 30) + &quot; | &quot;;
str += StringUtils.rightPad(dbreads, 4) + &quot; | &quot;;
str += StringUtils.rightPad(Integer.toString(dbwrites), 4) + &quot; | &quot;;
str += StringUtils.rightPad(dbquerytime, 8) + &quot; | &quot;;
str += StringUtils.rightPad(memoryused, 8) + &quot; | &quot;;
str += StringUtils.rightPad(filesincluded, 6) + &quot; | &quot;;
str += StringUtils.rightPad(serverload, 6) + &quot; | &quot;;
str += url;
return str;
}
toPHP() {
String php = &quot;$results[&quot;+thread+&quot;][] = array(\n&quot;;
php += &quot; &apos;thread&apos;=&gt;&quot;+thread+&quot;,\n&quot;; // Int
php += &quot; &apos;starttime&apos;=&gt;&quot;+starttime+&quot;,\n&quot;; // Long
php += &quot; &apos;dbreads&apos;=&gt;&quot;+Integer.parseInt(dbreads)+&quot;,\n&quot;; // String =&gt; Int
php += &quot; &apos;dbwrites&apos;=&gt;&quot;+dbwrites+&quot;,\n&quot;;
php += &quot; &apos;dbquerytime&apos;=&gt;&quot;+dbquerytime+&quot;,\n&quot;;
php += &quot; &apos;memoryused&apos;=&gt;&apos;&quot;+memoryused+&quot;&apos;,\n&quot;;
php += &quot; &apos;filesincluded&apos;=&gt;&apos;&quot;+filesincluded+&quot;&apos;,\n&quot;;
php += &quot; &apos;serverload&apos;=&gt;&apos;&quot;+serverload+&quot;&apos;,\n&quot;;
php += &quot; &apos;sessionsize&apos;=&gt;&apos;&quot;+sessionsize+&quot;&apos;,\n&quot;;
php += &quot; &apos;timeused&apos;=&gt;&apos;&quot;+timeused+&quot;&apos;,\n&quot;;
php += &quot; &apos;name&apos;=&gt;&apos;&quot;+name+&quot;&apos;,\n&quot;;
php += &quot; &apos;url&apos;=&gt;&apos;&quot;+url+&quot;&apos;,\n&quot;;
php += &quot; &apos;bytes&apos;=&gt;&apos;&quot;+bytes+&quot;&apos;,\n&quot;;
php += &quot; &apos;time&apos;=&gt;&apos;&quot;+time+&quot;&apos;,\n&quot;;
php += &quot; &apos;latency&apos;=&gt;&apos;&quot;+latency+&quot;&apos;,\n&quot;;
php += &quot;);\n&quot;;
return php;
}
return this;
}
EscapeQuotes(String text) {
return text.replace(&quot;&apos;&quot;, &quot;\\&apos;&quot;);
}
Runnable mr = MoodleResult(sampleResult);
// Get the file (it is created in testStarted).
String filenamepath = &quot;/home/rajesh/test.txt&quot;;
// We add the run info when starting the first thread
if (JMeterUtils.getProperty(&quot;headerprinted&quot;) == null) {
// Output headers.
JMeterUtils.setProperty(&quot;headerprinted&quot;, &quot;1&quot;);
print(mr.headerToString());
FileWriter fstream = new FileWriter(filenamepath, true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(&quot;$host = &apos;&quot;+vars.get(&quot;host&quot;)+&quot;&apos;;\n&quot;);
out.write(&quot;$sitepath = &apos;&quot;+vars.get(&quot;sitepath&quot;)+&quot;&apos;;\n&quot;);
out.write(&quot;$group = &apos;&quot;+EscapeQuotes(props.get(&quot;group&quot;))+&quot;&apos;;\n&quot;);
out.write(&quot;$rundesc = &apos;&quot;+EscapeQuotes(props.get(&quot;desc&quot;))+&quot;&apos;;\n&quot;);
out.write(&quot;$users = &apos;&quot;+vars.get(&quot;users&quot;)+&quot;&apos;;\n&quot;);
out.write(&quot;$loopcount = &apos;&quot;+vars.get(&quot;loops&quot;)+&quot;&apos;;\n&quot;);
out.write(&quot;$rampup = &apos;&quot;+vars.get(&quot;rampup&quot;)+&quot;&apos;;\n&quot;);
out.write(&quot;$throughput = &apos;&quot;+vars.get(&quot;throughput&quot;)+&quot;&apos;;\n&quot;);
out.write(&quot;$size = &apos;&quot;+vars.get(&quot;size&quot;)+&quot;&apos;;\n&quot;);
out.write(&quot;$baseversion = &apos;&quot;+vars.get(&quot;moodleversion&quot;)+&quot;&apos;;\n&quot;);
out.write(&quot;$siteversion = &apos;&quot;+EscapeQuotes(props.get(&quot;siteversion&quot;))+&quot;&apos;;\n&quot;);
out.write(&quot;$sitebranch = &apos;&quot;+EscapeQuotes(props.get(&quot;sitebranch&quot;))+&quot;&apos;;\n&quot;);
out.write(&quot;$sitecommit = &apos;&quot;+EscapeQuotes(props.get(&quot;sitecommit&quot;))+&quot;&apos;;\n&quot;);
out.close();
// Send the run timestamp to set it as run filename.
props.put(&quot;filepath&quot;, &quot;runs/&quot; + vars.get(&quot;runtimestamp&quot;) + &quot;.php&quot;);
}
FileWriter fstream = new FileWriter(filenamepath, true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(mr.toPHP());
out.close();
print(mr.toString());</stringProp>
</JSR223Listener>
<hashTree/>
</hashTree>
<ResultCollector guiclass="TableVisualizer" testclass="ResultCollector" testname="View Results in Table" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>false</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<threadCounts>true</threadCounts>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
</hashTree>
</hashTree>
</jmeterTestPlan>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment