JMeter Response assertion fails - jmeter

I'm getting assertion failure even if the response are correct. But it saying something about expected "/", Before and after the html code. Why is that?
Apply to: Main sample only
Response Field to Test: Text Response
Pattern Matching Rules: Contains
Patterns to test:
< html>
< body>
< h1>Flight request - 5< /h1>
< p>Departure airport code: GBG< /p>
< p>arrivalAirportCode: STM< /p>
< p>No of passengers: 12< /p>
< p>Status: CREATED< /p>
< /body>
< /html>
Response:
< html>
< body>
< h1>Flight request - 5< /h1>
< p>Departure airport code: GBG< /p>
< p>arrivalAirportCode: STM< /p>
< p>No of passengers: 12< /p>
< p>Status: CREATED< /p>
< /body>
< /html>
Assertion failure message: Test failed: text expected to contain /< html>
< body>
< h1>Flight request - 5< /h1>
< p>Departure airport code: GBG< /p>
< p>arrivalAirportCode: STM< /p>
< p>No of passengers: 12< /p>
< p>Status: CREATED< /p>
< /body>
< /html>/

I solved it by creating more "patterns to test" and to have only a single row in each "pattern to test." which it is compared. Probably it was a "invisible" whitespace or something else.

This is because JMeter internally uses a regular expression when you choose Contains or Matches pattern matching rules. Try to use the equals rule if possible, but be mindful of line breaks and white space characters that visually not be different but actually are.
More info: http://jmeter.apache.org/usermanual/component_reference.html#Response_Assertion

Its because in actual your script is not running, look in to Listener "Response in tree " in HTML view and you will find that scripts are not running and pages are not navigating in actual, though response are getting displayed as passed.

Related

Keep original order of requests in JMeter reports

I use following code to label requests by response times.
if (prev.getTime() > 170 && prev.getTime() < 340) {
prev.setSampleLabel(prev.getSampleLabel() + " > 170")
} else if (prev.getTime() > 340 && prev.getTime() < 4000) {
prev.setSampleLabel(prev.getSampleLabel() + " > 340")
} else if (prev.getTime() > 4000 && prev.getTime() < 8000) {
prev.setSampleLabel(prev.getSampleLabel() + " > 4000")
} else if (prev.getTime() > 8000) {
prev.setSampleLabel(prev.getSampleLabel() + " > 8000")
}
Aggregate report and Summary report contain name of requests in a different order than original one in Thread group. Total number of samples per request is not visible in this way.
JMeter's Aggregate Report and Summary Report listeners always store the Sample Results in their execution order and JMeter executes Samplers upside down (or according to the Logic Controllers)
As you can see, Sampler 4 is the first one because it has been executed first, however it is possible to sort requests by label by clicking the column header since JMeter 3.2):
Another option to sort requests by label is generating HTML Reporting Dashboard

AnyLogic - connection to a specified agent

I'm new to AnyLogic and I am trying to create a custom network...but i don't get to succeed in this task :(
Agents have a parameter "AgeClass", that is an int from 0 to 14, according to their age.
Then I have a variable "network" that contains the mean number of links between age class.
What I want is every agent to create link with other agent according to the matrix.
I don't get how I can say to an agent "connect to another agent with AgeClass = 3"
I thought something like this (to put in the "on startup block" or in an event inside the agent type):
int i = AgeClass \\ this is the AgeClass of the agent who is executing the code
for( int j=0; j<network[i].length; j++ ) { \\ in this way I go through all the age classes
for ( int k=0; k<poisson(network[i] [j]); k++) { \\ for every j I get the mean # of link
connectTo(????);
}
}
Instead of ???? i want to say "connect to another agent with AgeClass = j" ...is there a way thorugh?
Thanks for the support!!!
Please use the function "filter()" to select all agents from the population with AgeClass = j. Then, you can get random of them to connect to the agent executing the code. The expression ???? may look like:
randomFrom(filter(main.people, p -> p.AgeClass == j))
Here is the description of the function "filter()":
http://help.anylogic.com/topic/com.xj.anylogic.help/html/agentbased/Subset.html

What do test automation frameworks provide that my approach of scripting with Selenium Webdriver doesn't?

I am a newbie to software test automation and have written the following test script in Selenium Webdriver and Ruby binding. It performs user actions (clicks, enters, fills up values etc.). I have put basic asserts that match the screen text value with value I provide. Below is the code:
puts "Test Run 1 has started ""["+Time.now.strftime('%H:%M:%S CST')+"]"
require "selenium-webdriver"
require "colorize"
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.cache.disk.enable'] = false
browser = $browser = Selenium::WebDriver.for :firefox, :profile => profile
browser.manage().window().maximize();
browser.get "https://cameleon-6945--dev.cs11.cloudforce.com"
main_window = browser.window_handle
browser.find_element(name:"username").clear()
browser.find_element(name:"username").send_keys "abcd#vertex.com"
browser.find_element(name:"pw").send_keys "1234"
browser.find_element(name:"Login").click
browser.find_element(link_text:"Cameleon Quotes").click
wait = Selenium::WebDriver::Wait.new(:timeout => 45)
#Open Test Run 1 created quote
wait.until {browser.find_element(:css,"#bodyCell > div.bRelatedList > div.hotListElement > div > div.pbBody > table > tbody > tr.dataRow.even.first > th > a")}
browser.find_element(:css,"#bodyCell > div.bRelatedList > div.hotListElement > div > div.pbBody > table > tbody > tr.dataRow.even.first > th > a").click
wait.until {browser.find_element(:xpath,"/html/body/div[3]/div[3]/div[2]/div[3]/div[2]/div[2]/div[2]/form/div[3]/div/div[2]/div[2]/div/div/div/table")}
#browser.save_screenshot "Cart Overview - RegressionRun # "+Time.now.strftime('%Y-%m-%d %H%M%S')+".jpeg"
#wait.until {browser.find_element(:css,"body > div.mainPartBox > div.boxBody > div.main > div.processBar > div.backgroundProcessBarMiddle > a:nth-child(7) > div.processBarElement.noSelected > div")}
#browser.find_element(:css,"body > div.mainPartBox > div.boxBody > div.main > div.processBar > div.backgroundProcessBarMiddle > a:nth-child(7) > div.processBarElement.noSelected > div").click
#wait.until {browser.find_element(:css,"body > div.CombinedBox > div.boxBody > div.main > div:nth-child(8) > iframe")}
#wait.until {browser.find_element(:xpath,"/html/body/div[3]/div[3]/div[2]/div[3]/iframe")}
browser.manage.timeouts.page_load = 35
#browser.switch_to.frame(cart_frame)
puts "\n\n"
puts "Assertions to verify cart content values\n\n".yellow
element_value1 = browser.find_element(:css,"#total > tbody > tr > td:nth-child(4) > span").text
if element_value1 == "$314,507.30"
puts 'Contract Sales Price = ' +element_value1
puts 'Value as expected in the cart, Test Passed'
else
puts 'Test failed, Contract Sales price value does not match the expected value'
end
puts "\n"
element_value2 = browser.find_element(:css,"#total > tbody > tr > td:nth-child(6) > span").text
if element_value2 == "$157,253.65"
puts 'Contract Cost Price = ' +element_value2
puts 'Value as expected in the cart, Test Passed'
else
puts 'Test failed, Contract Cost price value does not match the expected value'.red
end
puts "\n"
element_value3 = browser.find_element(:css,"#total > tbody > tr > td:nth-child(8) > span").text
if element_value3 == "50.00"
puts 'Contract gross margin = ' +element_value3
puts 'Value as expected in the cart, Test Passed'
else
puts 'Test failed, Gross margin value does not match the expected value'
end
puts "\n\n\t\t\t\t\tTest Case 1 passed successfully, proceeding to Test Case 2 - Generate Document\n".green
It's not integrated with any framework, it's just a test script.
My questions are:
Is this test totally worthless if compared to tools like Cucumber/Capybara etc.?
I have captured most of the elements using XPaths and this way the only way since it lacked classes, ids etc. Now if there's a minor change in page structure, like a new div is introduced, this script will fail with NoElemenFoundError. Is there any way we can avoid it? Or this is the only way test scripts are written and we need to update them regularly with new developments?
That exercise is worth doing once for your own experience. A couple of ways that using rspec for example would be an improvement are that rspec gives you a way to organize multiple tests, and that it boils down the results of your tests to a single indicator of success or failure, so that you can just look at the last line of output (or have your CI server look at the exit status) instead of reading pages of messages to see whether all your tests passed. Cucumber differs from rspec in that it allows you to read your entire test in English without reading any code in between, which is extremely valuable for thinking through requirements and might allow you to collaborate on your tests with non-programmers. Capybara provides methods that do much what you're doing in your script but are more succinct.
Sensitivity to page structure is an issue even with more sophisticated tools. One way to minimize the issue is to not assert any more of the page structure than you have to. If there is only one table on the page and only one row of results then td:nth-child(6) is all the selector you need. Another way to deal with that issue is to add IDs or classes to your pages to support testing.
I would say it is worth to have such scripts, but as soon as your number of scripts grows you need to manage them in a way where minimum maintenance is required.
So you can use various strategies to design a framework where you can have central object repository and test data. Refer here! for more details on designs.
I agree with Dave, to avoid assert on page structure. And if you maintain a central repository then there would be little modification needed if there is changes in structure of a page.

how javamail imap fetch mail order by receive date desc

how javamail imap fetch mail order by receive date desc? folder.getMessage() no a date arg.
I want to sort by date when fetch mail in imap.
Thanks Advance!
Normally, messages are stored in the INBOX in the order they're received, so message number order is received date order. But note that this can be wrong if messages are moved between folders.
In general, if you want messages in a particular order, you'll need to sort them. If your IMAP server supports the SORT extension, you can ask the server to do the sorting by using the com.sun.mail.imap.IMAPFolder.getSortedMessages method.
#DefaultValue("REVERSE,ARRIVAL") MailSortTerms sortTerms
/**/
if (imapStore.hasCapability("SORT*")) {
Message[] messages = ((IMAPFolder) inbox).getSortedMessages(
sortTerms.getTerms());
for (int i = skip;
i < Math.min(skip + size, inbox.getMessageCount());
i++) {
resultList.add(messages[i]);
}
} else {
Message[] messages = inbox.getMessages();
for (int i = inbox.getMessageCount() - skip - 1;
i >= Math.max(inbox.getMessageCount() - skip - size - 1, 0);
i--) {
resultList.add(messages[i]);
}
}

Ckeditor - How do I "save" to the web page I am editing?

PHP Version 5.3.3-1 Ubuntu 10.10 Apache 2.2
Ckeditor 3.6.1
I can edit and save but the web page I am editing does not update ? The edited text appears in a new window. I want the web page I am editing to be updated.
ckeditor.js, test.html and posteddata.php are all in the same directory /var/www/
test.html
< head>
< title>Test Page < /title >
< meta http-equiv="content-type" content="text/html; charset=utf-8"/ >
< script type="text/javascript" src="ckeditor.js">< /script >
< /head >
< body >
< form action="posteddata.php" method="post" >
< textarea id="editor1" name="editor1" >
<p>Your text goes here</p>
< /textarea>
< script type="text/javascript" >
window.onload = function()
{CKEDITOR.replace( 'editor1' );};
< /script>
< input type="submit" value="Submit"/ >
< /form>
< /body>
< /html>
posteddata.php
< ?php
if ( isset( $_POST ) )
$postArray = &$_POST ; // 4.1.0 or later, use $_POST
else
$postArray = &$HTTP_POST_VARS ; // prior to 4.1.0, use HTTP_POST_VARS
foreach ( $postArray as $sForm => $value )
{
if ( get_magic_quotes_gpc() )
$postedValue = htmlspecialchars( stripslashes( $value ) ) ;
else
$postedValue = htmlspecialchars( $value ) ; ?>
< tr>
< th style="vertical-align: top"><?php echo htmlspecialchars($sForm); ?>
< /th>
< td><pre class="samples"><?php echo $postedValue?></pre></td>
< /tr>
< ?php }
?>
All your code does is print out what you've just typed in. It doesn't save it anywhere.
Probably the simplest way is to store the changes in a database and then load them each time.
Here's a tutorial; worth reading if you want to do anything useful in PHP: http://www.w3schools.com/php/php_mysql_intro.asp
There is a "save" plugin that submits the form. Get the submitted form and save it in your DB or on your file.

Resources