I am trying to call a batch file from watir-webdriver. I am using ruby with watir. I tried to use system(filename.bat) but it doesn't work.
I have written a step definition for this and when I run it I got an error stack level too deep (SystemStackError).
And(/^I execute a batch file$/) do
system('filename.bat')
end
Related
I have a .bat file that calls different things and runs different scripts to compile and build a system developed by other programmers.
I am trying to call that .bat file from Python using Qprocess. The bat file runs smoothly. However, if the bat file by some reason fails, my python script needs to be terminated in some way.
I had a short discusion with some of the guys that wrote that huge .bat file and they told me that the .bat file has a standard structure and returns error levels if something is failed.
I don't really know how to catch those levels and I don't know so much about batch programming. Is Error level something universal? Can it be catched from Python?
I googled a bit and I found some very old articles that didn't teach me so much. Any one has a short example on how to catch those levels?
Error level in a batch file context means it will exit with a certain code. You can query this exit code as soon as the process finished.
def properties(self):
self.process=QProcess()
self.process.finished.connect(self.onFinished)
self.process.start('test.bat', ['arg'])
def onFinished(self, exitCode, exitStatus):
[check exit code here...]
I have the following Java code in PeopleCode to execute a batch file (which in turn executes WinSCP script file). How to get the return code?
Else if you guys have similar code in people code to transfer file. Please let me know.
Local JavaObject &runtime = GetJavaClass("java.lang.Runtime").getRuntime();
Local JavaObject &process = &runtime.exec("\\xyz\BATCH_FILE_NAME.bat");
Rest of the code.
Use the Process.exitValue() method:
&process.exitValue()
This will of course get you an exit code of the batch file. Whether that gets you exit code of WinSCP depends on how the batch file is implemented. You didn't show us.
In general you propagate exit code of WinSCP to exit code of batch file like:
winscp.com /ini=nul /command ...
exit /b %ERRORLEVEL%
Read also about Checking script results.
Though with such trivial batch file, it does not really make sense to use the batch file in the first place. You can execute the winscp.com (or the winscp.exe) directly from your PeopleCode.
Is it possible to load the step definitions I have defined into the calabash-android console?
I would like to be able to use them when navigating the app within the console.
Thanks
No from the console you can not run a single step definition.
But you can start execution of a test at a specific line appending parameter to the call to start your test
:<linenumber>
This will start execution of your feature file from that specific line and it will run from there to the end of the file.
So while it is not what you are looking for at least it is something.
Did you try step('<step_name>') method?
To be honest I'm not sure if this will work. I know it's working insinde Ruby methods and step definitions - I wanted to post a comment but I can't with 28 points of reputation ;)
You can also try making ruby methods with code from within the step definition:
Then /^I do something$/ do
some code
goes here
end
def do_something
some code
goes here
# same code as in step definition
end
or just use step method:
def do_something
step('I do something')
end
and then call it in a calabash console (I prefer using binding.pry inside some script rather than calling "pure" calabash-console - it makes me sure that I will have all needed methods included).
I'll explain the task requested from me:
I have two containers in Azure, one called "data" and one called "script". In the "data" container there's a txt file with data, and in the "script" container there's a script file.
Now, I need programatically (with WorkerRole) to execute the script file, with the content of the data file as parameters (Example: a script file that accepts a string 's' and returns to the screen "Hello, 's'", when 's' in the string given, and in the data file there's a string), and save the result of the run into another file which needs to be saved in another container called "result".
How do I do all these? I've already uploaded the files and created the blobs programatically, but I can't seem to understand how to execute the file of how to save its result to another file?
Can I please have some help?
Thanks in advance
Here are the steps in pseudo code:
Retrieve the script from the blob(using DownloadToStream())
Compile the script(I will leave this to you as I have no idea what
format your script is)
Load parameters from blob(same as step 1)
Execute script with those parameters.
If your script's can be written as lambda expressions then this becomes a lot easier as you can turn them into Action's
Edit based on your questiions:
DownloadText() is no longer included in Azure Storage 2.0, you only have access to DownloadToStream(). Even if you are using an older version(say 1.7) I would recommend using DownloadToStream() in the event you ever upgrade in the future. This will prevent having to refactor your code.
In terms of executing your script, depending on what type of script it is(if it is c# code you can use this example: Is it possible to dynamically compile and execute C# code fragments?. If you need to execute a different type of script you would need to run it using Process.Start and you can look at this example: http://www.dotnetperls.com/process-start
I do not have much experience with point number 2 but those are the processes I have heard and seen used.
I am a beginner to Cucumber. I have installed cucumber by the help of internet. I have written a .feature file. But I don`t know where to place this file and how to execute it.
Because it wants you to succeed in BDD, cucumber will guide you through the process. From the project directory, type cucumber in the cmd prompt or terminal, which returns:
You don't have a 'features' directory. Please create one to get started.
Create a features directory, and put your .feature file in it. Again, run cucumber, which returns pending step definitions that map to your feature file. As an example:
You can implement step definitions for undefined steps with these snippets:
Given /^I want to use cucumber$/ do
pending # express the regexp above with the code you wish you had
end
Now--as #siekfried indicates--create a directory called features/step_definitions for your step definition files, which should end with _steps (e.g. example_steps.rb). Then, edit your step definition file with the appropriate code to execute the step.