{"action":"created","issue":{"url":"https://api.github.com/repos/kelaberetiv/TagUI/issues/289","repository_url":"https://api.github.com/repos/kelaberetiv/TagUI","labels_url":"https://api.github.com/repos/kelaberetiv/TagUI/issues/289/labels{/name}","comments_url":"https://api.github.com/repos/kelaberetiv/TagUI/issues/289/comments","events_url":"https://api.github.com/repos/kelaberetiv/TagUI/issues/289/events","html_url":"https://github.com/kelaberetiv/TagUI/issues/289","id":369414036,"node_id":"MDU6SXNzdWUzNjk0MTQwMzY=","number":289,"title":"Dynamic wait values broken","user":{"login":"brianredbeard","id":57542,"node_id":"MDQ6VXNlcjU3NTQy","avatar_url":"https://avatars1.githubusercontent.com/u/57542?v=4","gravatar_id":"","url":"https://api.github.com/users/brianredbeard","html_url":"https://github.com/brianredbeard","followers_url":"https://api.github.com/users/brianredbeard/followers","following_url":"https://api.github.com/users/brianredbeard/following{/other_user}","gists_url":"https://api.github.com/users/brianredbeard/gists{/gist_id}","starred_url":"https://api.github.com/users/brianredbeard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianredbeard/subscriptions","organizations_url":"https://api.github.com/users/brianredbeard/orgs","repos_url":"https://api.github.com/users/brianredbeard/repos","events_url":"https://api.github.com/users/brianredbeard/events{/privacy}","received_events_url":"https://api.github.com/users/brianredbeard/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-10-12T06:18:31Z","updated_at":"2018-10-12T18:37:53Z","closed_at":null,"author_association":"NONE","body":"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.\r\n\r\nRelated to #122 \r\n"},"comment":{"url":"https://api.github.com/repos/kelaberetiv/TagUI/issues/comments/429420404","html_url":"https://github.com/kelaberetiv/TagUI/issues/289#issuecomment-429420404","issue_url":"https://api.github.com/repos/kelaberetiv/TagUI/issues/289","id":429420404,"node_id":"MDEyOklzc3VlQ29tbWVudDQyOTQyMDQwNA==","user":{"login":"brianredbeard","id":57542,"node_id":"MDQ6VXNlcjU3NTQy","avatar_url":"https://avatars1.githubusercontent.com/u/57542?v=4","gravatar_id":"","url":"https://api.github.com/users/brianredbeard","html_url":"https://github.com/brianredbeard","followers_url":"https://api.github.com/users/brianredbeard/followers","following_url":"https://api.github.com/users/brianredbeard/following{/other_user}","gists_url":"https://api.github.com/users/brianredbeard/gists{/gist_id}","starred_url":"https://api.github.com/users/brianredbeard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianredbeard/subscriptions","organizations_url":"https://api.github.com/users/brianredbeard/orgs","repos_url":"https://api.github.com/users/brianredbeard/repos","events_url":"https://api.github.com/users/brianredbeard/events{/privacy}","received_events_url":"https://api.github.com/users/brianredbeard/received_events","type":"User","site_admin":false},"created_at":"2018-10-12T18:37:53Z","updated_at":"2018-10-12T18:37:53Z","author_association":"NONE","body":"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. \r\n\r\nThis then lead me to see that your examples do indeed work.  This was my sample code.  First, in `tagui_local.js` I have the following functions:\r\n\r\n```\r\nfunction getRandomInt(max) {\r\n        max = typeof max !== 'undefined' ? max : 10;\r\n        return Math.ceil(Math.random() * Math.floor(max));\r\n}\r\n\r\nfunction randomArray(max, count) {\r\n        count = typeof count !== 'undefined' ? count : 10;\r\n        max = typeof max !== 'undefined' ? max : 10;\r\n        var array = [];\r\n        for (c = 1; c <= count; c++) {\r\n                array.push(getRandomInt(max));\r\n        }\r\n        return array;\r\n}\r\n```\r\n\r\nWhich I then utilize in my example:\r\n```\r\nfor n from 1 to 5\r\n{\r\n        x = getRandomInt()\r\n        wait '+x+'\r\n}\r\n```\r\n\r\nThis renders to the following javascript:\r\n\r\n```\r\ncasper.then(function() {for (n=1; n<=5; n++)\r\n{casper.then(function() {for_loop_signal = '[CONTINUE_SIGNAL][n]';});\r\n(function (n) { // start of IIFE pattern\r\n{ // start of code block\r\n\r\ncasper.then(function() { // start of JS code\r\nx = getRandomInt()\r\n}); // end of JS code\r\n\r\ncasper.then(function() {techo('wait '+x+'');});\r\ncasper.wait((parseFloat(''+x+'')*1000), function() {});\r\n\r\n} // end of code block\r\n})(n); // end of IIFE pattern, with dummy marker for break step\r\n```\r\n\r\nThe trouble is I the definition of  `x = getRandomInt()` seems to be in a different scope then `x` provided in the `casper.wait()` call.  Due to the scoping issue, it then renders to zero, leaving no delay.\r\n\r\nAfter realizing the scoping issue I got a bit creative and define 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:\r\n\r\n```\r\ncount = getRandomInt()\r\necho count\r\narr = randomArray(5,count)\r\necho arr\r\n\r\nfor n from 1 to count\r\n{\r\n        x = arr[n - 1]\r\n        wait `arr[n-1]`\r\n}\r\n```\r\n\r\nWhich then results in:\r\n\r\n```\r\n./tagui randjs\r\n\r\nSTART - automation started - Fri Oct 12 2018 11:36:59 GMT-0700 (PDT)\r\n\r\n3\r\n4,1,3\r\nwait 4\r\nwait 1\r\nwait 3\r\n\r\nFINISH - automation finished - 8.4s\r\n```"}}
{"actor":{"display_login":"brianredbeard"}}