Jmeter ForEachController breaking out after HTTPRequest - foreach

I've a forEachController which appears to be breaking out after the first run of a HTTP Request that happens within it.
The Controller looks like the following
The 'Navigate to Next FileId' HTTP Request executes fine with a Response 200 and Status ok. However while the first two debug samplers execute the final two don't happen. Any sampler that is put after the HTTPRequest doesn't occur and yet the test continues on with the next sampler after the ForEach FileId controller.
Any ideas would be greatly appreciated, this one has stumped me for a couple of days.
Here's the forEachController configuration.
Thanks,
Mark.
#UBIK_LOAD_PACK
Without the BeanShell Preprocessor and the HTTP Request (Navigate to Next fileId) is set to a request that is successfully performed earlier in the test and still the same result. First two debug samplers print out and the last two are ignored and the ForEachController exits.

There is no reason for this behaviour unless you Beanshell Pre Processor does something particular like breaking the ForeachController loop condition by playing on fileIds variable value.

Related

Google Adwords/Ads AdGroupAdService

I was wondering, if I add and delete some ads with the service AdGroupAdService, using the method mutate, If It returns me some errors ( not in all the operations i want to upload ), does it perfom correctly the others operations?
My initial guess was it does, but after a few checks, it does not.
So Am I missing something?
Thank you so much for your help
That is a feature known as partial failure.
If you set it to true within your SOAP header, then the program will run the operations that have no errors correctly.
If it is not set to true, then the whole program will fail if any operation has an error.

Skip "Capture Page Screenshot" for some keywords

I'm writing test cases in Robot Framework using AppiumLibrary.
I'm importing AppiumLibrary with the following code to get a screenshot whenever something goes wrong:
AppiumLibrary.__init__(self, run_on_failure="Capture Page Screenshot")
Is there a way to NOT take a screenshot for a specific keyword? This keyword will for example create 15 screenshots (if it's not able to find Donald):
Wait Until Keyword Succeeds 30 seconds 2 seconds Element Text Should Be Username Donald
There is nothing built-in to do what you want. There are many solutions, however.
One solution would be to turn off capturing the keyword (using register keyword to run on failure) immediately before calling wait until keyword succeeds. You could then call wait until keyword succeeds, and then turn capturing back on afterwards.
Or, you can register your own custom keyword instead of Capture page screenshot. Your own keyword can use whatever logic it wants to determine whether to capture screenshots or not. For example, it could look for a global variable that tells it whether to capture or not.
You could also write your own keyword to use in place of wait until keyword succeeds which also uses one of the other two solutions.
For example, create a keyword named wait until element contains text which turns off the capturing, runs wait until keyword succeeds, and then turns it back on. Then, in your test you still just have a single statement:
wait until element contains text Username Donald
Register Keyword To Run On Failure NONE
${Status} Run Keyword And Return Status Wait Until Keyword Succeeds 30 seconds 2 seconds Element Text Should Be Username Donald
Register Keyword To Run On Failure Capture Page Screenshot
IF ${Status}==False
Element Text Should Be Username Donald
END
-Lets Walkthrough whats happening in the above code snippet
Register Keyword To Run On Failure NONE (To avoid multiple
screenshots when Element Text Should Be keyword fails in the
next line )
After waiting for 30 seconds it will return status If the keyword passes it returns pass and if it fails it returns fails and gets stored in status variable (Remember no screenshots are generated in this process since we turned off screenshots in point 1.)
Again setting back Capture Page Screenshot Keyword on Failure to take screenshot.
Lastly one more time it will run Element Text Should Be and if it fails it generates a screenshot and keyword fails.(Since ${Status}==False that means it will run only if Wait Until Keyword Succeeds keyword fails otherwise this IF block will not run since our keyword already passed)

Capybara test intermittently failing when using Selenium driver

I've got an integration test here which is passing flawlessly using the poltergeist driver every time, but when I run this test using Selenium it passes on average 3 times and fails 1 time.
def fill_in_inclusion_criteria
find("div.measure#age label[for='16']").click
find("div.measure#substance_use_met label[for='1']").click
find("div.measure#participant_consent label[for='1']").click
click_link("Next")
end
When it fails, the error that I get back is this
expected to find css "div.measure#participant_consent" but there were no matches. Also found "", which matched the selector but not all filters.
The participant consent button appears when div.measure#age label[for='16'] is clicked, so it's dependent on Javascript. I see this happening in Firefox most of the time, but when it errors, the div isn't visible on the page.
It seems like it's not waiting for the element to display on the page before clicking it, but I thought that wrapping it in a "find" waits for the element to be visible on the page before trying to click it?
Any idea why this could be happening?
The one confusing thing with your question is that the error message you posted isn't actually for the code you've shown, since if it was the error message would be expected to find css "div.measure#participant_consent label[for='1']" ... . Assuming that's just a copy paste error/from a previous slightly different version of the code and the line you specified is where the error is actually coming from:
Since the previous find/click lines are working there are 2 potential reasons for the third one to not find the label element
The age label[for='16'] element click either isn't actually occurring, or is occurring before the JS that enables the showing behavior is attached. You can check for this by adding a sleep for a few seconds before it and seeing whether the failures go away
The participant_consent find/click isn't waiting long enough for the element to appear. find waits up to Capybara.default_max_wait_time seconds for elements to appear, so if that is long enough you could increase that setting, or pass a :wait option to find to override the setting for that call
find("div.measure#participant_consent label[for='1']", wait: 10).click
Technically, there is a third potential cause but it's highly unlikely due to the sporadic nature of the failure, which would be a JS failure on the page. You can check for this by rescuing the error and pausing your test so that you can look at the developer console in the browser for any errors.

Geb: Element is no longer attached to the DOM inside waitFor

I am getting an "Element is no longer attached to the DOM" error from Geb tests. The thing that's confusing me is that the error is from within waitFor itself -- I inserted the wait specifically to allow the async activity on the page to complete before moving ahead with clicking a link, which was previously the source of the same error. If the wait itself fails, now I'm at a loss.
The code is something like
waitFor { $("div", text: "... search string ... ") }
$("a", id: "element-id").click()
and the stack trace shows that the waitFor itself is actually the problem:
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.getText(RemoteWebElement.java:152)
at geb.navigator.NonEmptyNavigator.matches_closure28(NonEmptyNavigator.groovy:474)
at geb.navigator.NonEmptyNavigator.matches(NonEmptyNavigator.groovy:471)
at geb.navigator.NonEmptyNavigator.filter_closure2(NonEmptyNavigator.groovy:63)
at geb.navigator.NonEmptyNavigator.filter(NonEmptyNavigator.groovy:63)
at geb.navigator.NonEmptyNavigator.find(NonEmptyNavigator.groovy:48)
at geb.content.NavigableSupport.$(NavigableSupport.groovy:96)
at geb.Browser.methodMissing(Browser.groovy:193)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:51)
at [my test]_closure7([my test].groovy:147)
at [my test]_closure7([my test].groovy)
at geb.waiting.Wait.waitFor(Wait.groovy:106)
From the stacktrace I can see that you use that selector inside of a test class and not a module so the possibility of a module base element being detached can be ruled out.
If this is happening consistently for you then it means that one of the elements selected by the div selector gets removed from DOM before its text is being retrieved to filter on it.
There are two reasons why this can happen:
Your selector is very slow - selecting all div elements in a page and then filtering them based on text in the JVM can take a lot of time. Assuming that you use the default waiting preset then if that selector takes more than 5 seconds then the waitFor {} block will simply run once, get the exception and never retry because it runs out of time. You should do as much filtering as possible in the browser, that is use a CSS3 compatible selector and use Geb's text filtering extension on an as small as possible element set.
Your page is async in a periodic way and it changes quicker than the selector is able to filter based on element text. This would be again possible because your selector looks like it could be potentially very slow.
Basically I would suggest coming up with a more specific selector than what you have there currently.

Coroutines, multiple requests in Lua

I've been poring over this subject for the past 12 hours, and I simply cannot seem to get anywhere. I do not even know if this is possible, but I'm hoping it is because it would go a long way to continuing my project.
What I am attempting to do is create coroutines so the particular program I use does not freeze up due to its inability to perform asynchronous http requests. I've figured out how to do that part, even though my understanding of coroutines is still in the "Huh? How does that work?" phase. My issue now is being able to respond to multiple requests with the correct information. For instance, the following should produce three separate responses:
foo(a)
foo(b)
foo(c)
where foo initiates a coroutine with the parameters inside. If all requested separately, then it returns the proper results. However, if requested as a block, it will only return foo(c)'s result. Now, I understand the reasoning behind this, but I cannot find a way to make it return all three results when requested as a block. To help understand this problem a bit, here's the actual code:
function background_weather()
local loc = url.escape(querystring)
weatherpage = http.request("http://api.wunderground.com/api/004678614f27ceae/conditions/q/" .. loc .. ".json")
wresults = json.decode(weatherpage)
--process some stuff here, mainly datamining
end
--send datamined information as a response
coroutine.yield()
end
And the creation of the coroutine:
function getweather ()
-- see if backgrounder running
if background_task == nil or
coroutine.status (background_task) == "dead" then
-- not running, create it
background_task = coroutine.create (background_weather)
-- make timer to keep it going
AddTimer ("tickler", 0, 0, 1, "",
timer_flag.Enabled + timer_flag.Replace,
"tickle_it")
end -- if
end -- function
The querystring variable is set with the initial request. I didn't include it here, but for the sake of testing, use 12345 as the querystring variable. The timer is something that the original author of the script initialized to check if the coroutine was still running or not, poking the background every second until done. To be honest, I'm not even sure if I've done this correctly, though it seems to run asynchronously in the program.
So, is it possible to receive multiple requests in one block and return multiple responses, correctly? Or is this far too much a task for Lua to handle?
Coroutines don't work like that. They are, in fact, blocking.
The problem coroutines resolve is "I want to have a function I can execute for a while, then go back to do other thing, and then come back and have the same state I had when I left it".
Notice that I didn't say "I want it to keep running while I do other things"; the flow of code "stops" on the coroutine, and only continues on it when you go back to it.
Using coroutines you can modify (and in some cases facilitate) how the code behaves, to make it more evident or legible. But it is still strictly single-threaded.
Remember that what Lua implements must be specified by C99. Since this standard doesn't come with a thread implementation, Lua is strictly single-threaded by default. If you want multi-threading, you need to hook it to an external lib. For example, luvit hooks Luajit with the libuv lib to achieve this.
A couple good references:
http://lua-users.org/wiki/CoroutinesTutorial
http://lua-users.org/wiki/ThreadsTutorial
http://lua-users.org/wiki/MultiTasking
http://kotisivu.dnainternet.net/askok/bin/lanes/comparison.html
Chapter 9.4 of Programming in Lua contains a fairly good example of how to deal with this exact problem, using coroutines and LuaSocket's socket.select() function to prevent busylooping.
Unfortunately I don't believe there's any way to use the socket.http functions with socket.select; the code in the PiL example is often all you'll need, but it doesn't handle some fairly common cases such as the requested URL sending a redirect.

Resources