I wanted to create testcase with loops. I got latest sideflow.js extension and targeted to it in Selenium options. Then I restarted Selenium IDE but it doesn't work.
Sample testcase:
store|i|1
while|${i}<200|
echo|${i}|
storeEval|i=1*storedVars['i']; i+1|i
endWhile||
It displayed the following error message:
[error] Unexpected Exception: fileName -> chrome://selenium-ide/content/tools.js -> file:///home/imslavko/bin/sideflow.js?1346044911197, lineNumber -> 100
Firefox version: 14.0.1 for Ubuntu
Selenium IDE version: 1.9.0
sideflow.js: latest from this page https://github.com/darrenderidder/sideflow/blob/master/sideflow.js
How to make it work? Thanks in advance.
Instead of
store|i|1
write it as
store|1|i
If you want to create a loop, the following is suggested. I am still learning so I am not sure but this has worked for me.
For i=0; i <= 200; i++ i
break "${i}" == 200
Echo *** "${i}" ***
endFor
Here is an example triple array looper (With static variables so you can see it changing)
This is a custom one I have made, notice the syntax for storing incremental variables (Such as counters e.t.c.)
This looper will cycle through all of your options (In the example below there are 6*5*4=120 options). It echo's each option out once and then moves onto the next one.
example_array_looper
storeEval new Date().getTime(); timeStart
echo ${timeStart}
storeEval new Array("1","2","3","4"); toparray
storeEval new Array("A", "B", "C", "D", "E"); middlearray
storeEval new Array("i","ii","iii","iv","v","vi"); bottomarray
getEval topindex=0;
getEval middleindex=0;
getEval bottomindex=0;
getEval loopCounter=0;
while topindex < storedVars['toparray'].length
storeEval topindex temptop
while middleindex < storedVars['middlearray'].length
storeEval middleindex tempmiddle
while bottomindex < storedVars['bottomarray'].length
storeEval bottomindex tempbottom
echo javascript{storedVars['toparray'][storedVars['temptop']]+" -> "+storedVars['middlearray'][storedVars['tempmiddle']]+" -> "+storedVars['bottomarray'][storedVars['tempbottom']]}
getEval bottomindex++;
getEval loopCounter++;
endWhile
getEval bottomindex=0;
getEval middleindex++;
endWhile
getEval bottomindex=0;
getEval middleindex=0;
getEval topindex++;
endWhile
storeEval loopCounter loops
echo Total number of loops is: ${loops}
storeEval new Date().getTime(); timeEnd
echo ${timeEnd}
storeEval (${timeEnd}-${timeStart})/1000 scriptRunTime
echo Total Run Time for Script was: ${scriptRunTime}s
storeEval ${scriptRunTime}/${loops} averageTime
echo Average Loop Duration was: ${averageTime}s
I opted to remove all the html tagging (So the gaps should be quite evident). StoreEval command is best for holding your loop counters because you can then use them as incrementals in one step instead of 2.
Related
3 login based questions in the website to be automated
I need correct code to automate these.
enter image description here
When using "if ..." Commands in test steps in Selenium IDE for Chrome, you need to remember the following:
Use "if ... end" to form a single branch of test steps.
Use "if ... else ... end" to form two branches of test steps.
Use "if ... else if ... else ... end" to form multiple branches of test steps.
Use JavaScript Boolean expression syntax to specify conditions to "if" and "else if" commands.
${variable} is allowed in condition expressions.
Here is a sample test called "Condition" on how to use variables:
1 execute script | return (new Date()).getDay(); | day
2 echo | ${day}
3 if | ${day} < 1
4 echo | Sunday
5 else if | ${day} > 5
6 echo | Saturday
7 else
8 echo Weekday
9 end
Here is the log output when you execute the above test.
1. executeScript on return (new Date()).getDay(); with value day OK
echo: 0
3. if on ${day} < 1 OK
echo: Sunday
5. elseIf on ${day} > 5 OK
7. else OK
9. end OK
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
This code is valid in vim. It is the syntax of vimscript. It can also work in neovim's configuration file init.vim. how can I achieve the same effect in init.lua?
Tested on 0.7.2, if not available, the version may be too low.
vim.api.nvim_create_autocmd("BufReadPost", {
pattern = {"*"},
callback = function()
if vim.fn.line("'\"") > 1 and vim.fn.line("'\"") <= vim.fn.line("$") then
vim.api.nvim_exec("normal! g'\"",false)
end
end
})
I have googled this a lot and I can only find answers that relate to conditions within the loop being met. I want this loop to run infinitely (Hence while 1==1) and I'm testing it at the moment by just leaving it running in Thonny. It runs for variable lengths of time and then just stops. It doesn't exit the program or stop running, it just behaves as if it's waiting for something but there's nothing that I can see that it's waiting for. The shell doesn't report any errors or report that it has stopped running, it simply stops printing the string in the fourth line print statement.
I am very new to python and Linux and I have no idea how to debug this problem or where to look for the stopping point. Even running it in debug mode doesn't render any helpful information. Has anyone got any suggestions please?
The only other thing that I have tried outside of what I have said is I have tried running it on a fresh install of Raspberry Pi OS on three different Raspberry Pi 4 Model B computers. It behaves exactly the same on all of them.
while 1==1:
time.sleep(1)
cnt = 1
print('One = One loop ' + str(datetime.today()) + ' CNT: ' + str(cnt))
while Decimal(target_temperature()) - Decimal(0.3) >= Decimal(actual_temperature()) and switch_state() == 'currently not running':
print('Before heating loop ' + str(datetime.today()))
try:
if cnt == 1:
if Decimal(target_temperature()) - Decimal(0.3) >= Decimal(actual_temperature()) and switch_state() == 'currently not running':
print('First heating loop ' + str(datetime.today()))
requests.get('http://192.168.1.167/4/on')
log_db('On', str(target_temperature()), str(actual_temperature()))
time.sleep(225)
requests.get('http://192.168.1.167/4/off')
log_db('Off', str(target_temperature()), str(actual_temperature()))
time.sleep(300)
cnt = cnt + 1
if(cnt != 1):
if Decimal(target_temperature()) - Decimal(0.3) >= Decimal(actual_temperature()) and switch_state() == 'currently not running':
print('Second heating loop ' + str(datetime.today()))
requests.get('http://192.168.1.167/4/on')
log_db('On', str(target_temperature()), str(actual_temperature()))
time.sleep(180)
requests.get('http://192.168.1.167/4/off')
log_db('Off', str(target_temperature()), str(actual_temperature()))
time.sleep(300)
except Exception as e:
print(e)
Bearing in mind i don't know anything about python i will try to help.
1 - The first thing i would do is put the whole program in a try catch block. That wasy if anything bad happens you should be told about it
try:
<all your code>
except Exception as e2:
print('The whole thing errored' + e2)
2 - The delays are in seconds? For testing i would change every sleep to (30) so you can see what is going on without getting too bored waiting, when you have it working then change the times back.
3 - I would add some more print('got here!') like where you have if(cnt == 1) add else print('first loop wasnt 1 it was ' + cnt)
4 - try and make the code easier for you to read, when it gets actually run it will be so optimized that it wont bear any relation to what you write. So write it in a way that is easiest for you
5 - You turn it on and then off, but if the off failed it would never be turned off, you should assume that it will go badly and that will be the day you get a big bill. Try and stop it if an error occurs by adding another check if actualTemp > targetTemp then turn it off?
6 - the http request might take ages, specify a time in seconds you are prepared to wait like , timeout=60
try:
while 1==1:
try:
time.sleep(30)
targetTemp = Decimal(target_temperature())
actualTemp = Decimal(actual_temperature())
switchState = switch_state()
print('Doing it at ' + str(datetime.now()) + ' target ' + str(targetTemp) + ' actual ' + str(actualTemp) + ' switch ' + switchState)
if targetTemp - Decimal(0.3) >= actualTemp and switchState == 'currently not running'
print('too cold turning it for a bit!')
requests.get('http://192.168.1.167/4/on', timeout=60)
log_db('On', targetTemp , actualTemp)
else if actualTemp > targetTemp and switchState != 'currently not running'
print('too hot turning it off!')
requests.get('http://192.168.1.167/4/off', timeout=60)
log_db('Off', targetTemp , actualTemp)
else
print('Not doing anything!')
except Exception as e1:
print('Loop errored -> ' + e1)
except Exception as e2:
print('Whole thing errored -> ' + e2)
Thanks Billy the Kid. You were right. Sometimes the devices that the loop uses via HTTPRequests just don't reapond (the two functions use HTTPRequests) and sometimes they create errors that aren't caught in the loop. Putting the whole thing in a try/catch oddly did identify that. Problem solved.
Is there any windows or unix/linux commandline script that can do this?I.e the word "boss" should be incremented from 1 to 60,then 1 to 60 again.
I have a file that contains a list of text like so;
She is the new boss
She is the new boss
She is the new boss
She is the new boss
She is the new boss
She is the new boss
She is the new boss
She is the new boss
She is the new boss
.
.
.
I want the output to be:
She is the new boss1
She is the new boss2
She is the new boss3
.
.
.
She is the new boss60
She is the new boss1
She is the new boss2
She is the new boss3
.
.
.
She is the new boss60
.
.
.
So,far I use this perl -i.bak -ape "s/"old-text"/$&.++$A /ge" input.txt && del input.txt.bak to do repeated increment but the output it produces is not what I want.
perl -pe 's/\bboss\b\K/(++$n > 60 ? $n=1 : $n)/eg' file
Word boundaries \b have been added around boss to prevent matching bossy or embossed.
Originally, you used $&.++$A:
The incremented variable needs to be reset conditionally. A ternary ?: expression can be used to achieve that.
$& can be removed by using the PCRE \K escape.
It's easier to not use the save-in-place -i option until you know that the processing being applied is correct.
perl -ple'$_ .= ($. - 1) % 60 + 1'
$. is the current line number.
Specifying file to process to Perl one-liner
This Linux command may do:
i=1 && while read f; do echo "$f$i"; i=$(( i+1 )); done <original_file.txt > new_file.txt
Here is an awk:
$ echo "She is the new boss
She is the new boss
She is the new boss
She is the new boss
She is the new boss
She is the new boss
She is the new boss
She is the new boss" | awk -v max=3 '{cnt>=max ? cnt=1:cnt++; $NF=$NF cnt;} 1'
Prints:
She is the new boss1
She is the new boss2
She is the new boss3
She is the new boss1
She is the new boss2
She is the new boss3
She is the new boss1
She is the new boss2
So just change the input max to 60 and that should work as your example describes.
For a file, just do:
$ awk -v max=60 '{cnt>=max ? cnt=1:cnt++; $NF=$NF cnt;} 1' your_file
I don't think python is clean in this task. But I write this for you.
import re
class LineReplacer(object):
def __init__(self, replace_word, max_word_count):
self.word_index = 1
self.word_to_replace = replace_word
self.max_word_count = max_word_count
#property
def word_regex(self):
return re.compile(f"(?<=[^a-zA-Z0-9]){self.word_to_replace}(?=[^a-zA-Z0-9])")
def replace_function(self, match):
current_index = self.word_index
if self.word_index < self.max_word_count:
self.word_index += 1
else:
self.word_index = 1
return f"{match.group()}{current_index}"
def replace_file(self, input_file_path, output_file_path):
output = open(output_file_path, "w")
with open(input_file_path, "r") as f:
for line in f.readlines():
new_line = self.word_regex.sub(self.replace_function, line)
output.write(new_line)
output.close()
if __name__ == "__main__":
replacer = LineReplacer("boss", 60)
replacer.replace_file("test.txt", "output.txt")
This will generate a new file.
I am rendering an Adobe After Effects Project with Autoit and aerender,
I put this line of code in the console:
aerender -project C:\aeProjects\projekt_1.aep -comp "Main" -output C:\aeProjects\output\asd.avi
Now how can I check if this proccess is done, so that I can resume safely other steps.
At the moment I just put a sleep but that is not a good practice I think.
You can use the ProcessExists function to do this.
Here is a simple example with a timeout option:
MsgBox(64, "RunCmdWait", RunCmdWait("notepad.exe"))
Func RunCmdWait($sRuncmd, $iTimeout = 10000)
Local $iPid = Run(#ComSpec & " /c " & $sRuncmd, #ScriptDir, #SW_HIDE, 6)
Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
While 1
Sleep(250)
;Returns 0 when the process is closed
If ProcessExists($iPid) = 0 Then
SetError(0)
ExitLoop
EndIf
;Returns 1 on time out error
If TimerDiff($hTimer) >= $iTimeout Then
SetError(1)
ExitLoop
EndIf
WEnd
Return #error
EndFunc ;==>RunCmdWait
Here is a example with StdoutRead if you need to read the output:
MsgBox(64, "StdoutRead", GetStdoutRead("dir"))
Func GetStdoutRead($sRuncmd)
Local $iPid = Run(#ComSpec & " /c " & $sRuncmd, #ScriptDir, #SW_HIDE, 6)
Local $sStdoutRead = ""
While ProcessExists($iPid)
$sStdoutRead &= StdoutRead($iPid)
WEnd
Return $sStdoutRead
EndFunc ;==>GetStdoutRead