-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem using dynamic values for wait step #289
Comments
Adding on Alvin, I tried on macOS and Linux (CentOS), seems ok, even with new variable syntax - (btw nice test case 👍)
Hey Brian, thanks for raising this! You've probably come across some edge case which was missed. |
I think it's actually a rather interesting variable scoping issue. I was playing a bit with the rendered JavaScript code, executing it directly so as to minimize variables. This then lead me to see that your examples do indeed work while mine did not. This was my sample code. First, in
Which I then utilize in my example:
This renders to the following javascript:
The trouble is that the definition of After realizing the scoping issue I got a bit creative and defined an array with values outside of the code block, then use a for loop to iterate over the array and reference the index of the values:
Which then results in:
This solution works as I would expect, though it was a bit of mental gymnastics to come to this conclusion. |
Hi Brian, I was expecting something cool to come out from your response and indeed - nice catch and thanks for sharing your findings & workaround! Yeah, it's kinda convoluted, the way JS code blocks are generated to work with how CasperJS framework works. Can you try if below file (first remove the .txt extension, as GitHub doesn't allow attaching .php file here) works for your original code and perhaps other automation scripts that you've developed? Hi Alvin, In above tagui_parse.php I made changes to 2 lines in wait_intent() function. I encapsulated the casper.wait calls within a casper.then. This seems to fix the scoping issue. But because this is going to be a change that could potentially break other existing user scripts, can you have a look at some of your scripts to see if execution behavior still works as expected? This is a bug to fix, need to figure out if the above change breaks existing scripts. I tried with some of the sample flows seems ok and the generated positive_test.js seems alright. But will be cautious to make this change without first testing exhaustively on current user scripts. Below is amended version of wait_intent() - function wait_intent($raw_intent) {
$params = trim(substr($raw_intent." ",1+strpos($raw_intent." "," "))); if ($params == "") $params = "5";
if (strpos($params,"'+")!==false and strpos($params,"+'")!==false) // handling for dynamic time
return "casper.then(function() {".
"techo('".$raw_intent."');});\ncasper.then(function() {casper.wait((parseFloat('".$params."')*1000), function() {"."});});"."\n\n";
else return "casper.then(function() {".
"techo('".$raw_intent."');});\ncasper.then(function() {casper.wait(" . (floatval($params)*1000) . ", function() {"."});});"."\n\n";} Adding on a minimum replication case which involves interacting with web elements. For example, below script will return
|
I see, I remember this scoping issue with the casper.then back from working with the for loop issues. I'll try to put it in and test out if behavior remains the same on the scripts I have. |
Adding on, I've sent an email to CK copying you. Since he originally raised the dynamic wait enhancement request, and he probably has a wide range of scripts to do good sanity tests. Also, want to note here that popup step and frame step may have similar issues in the future. Their calls are not encapsulated within casper.then(). popup step by default takes in regex string so it probably not relevant here to accept dynamic inputs. frame step would probably not work with a dynamic variable but i do think that is an unlikely use case (calling a frame name which the developer don't know in advance), perhaps can leave it as it is now with just this note for future review. Otherwise, will be adding complexity to the already very complicated frame step implementation. |
So far tested and for the scripts (5 of them) I had, the wait step triggers at the right time and for the right duration. Would be good to wait for CK to provide further confirmation though. |
#289 - enclose wait step with casper.then() in order to make dynamic wait delay in scope for access #295 - PHP 7 issues warning message which is not observed with PHP 5. this change removes the warning by avoiding an empty $repo_data[0]. ie increment repo_count only if there is already data in the array, otherwise discard header and start filling from $repo_data[0].
aisingapore#289 - enclose wait step with casper.then() in order to make dynamic wait delay in scope for access aisingapore#295 - PHP 7 issues warning message which is not observed with PHP 5. this change removes the warning by avoiding an empty $repo_data[0]. ie increment repo_count only if there is already data in the array, otherwise discard header and start filling from $repo_data[0]. For the datatable (custom_csv_file portion), don't drop header as there is a dummy [iteration] header to let users reference current datatable iteration number.
#304 fixes this issue, so I will close this now. |
At some point the parsing of dynamic wait values has become broken. Introspection into what is occurring in
tagui_parse.php
is pretty hard to follow and print/debug statements haven't been much help.Related to #122
The text was updated successfully, but these errors were encountered: