Using Perl, Python, or Ruby, how to write a program to click on the screen at scheduled time?
If you are trying to automate some task in a website you might want to look at WWW::Selenium
. It, along with Selenium Remote Control, allows you to remote control a web browser.
How can I accurately program an automated click on Windows?
You do not decide what delay setting between mouse down and mouse up results in a valid single click, the operating system does.
No sleep
function can guarantee the timing between the mouse down and mouse up events you want. Perl's Win32::GuiTest module allows you to send an actual click event rather than messing with the timing of down and up events. Later: Looking at the source code, Win32::GuiTest seems to just fire mouse down and up events without any delay between them see GuiTest.pm:
elsif ( $item =~ /leftclick/i ) {
SendLButtonDown ();
SendLButtonUp ();
}
In addition, http://msdn.microsoft.com/en-us/library/ms646260(VS.85).aspx states that mouse_event
has been superseded by SendInput
http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspx which allows you to send a MOUSEINPUT
event with timestamps etc.
Making a program where you click as many times you can in a set time and stop the program and break the program after time is up
The easiest way to handle this is to make a timer on a new thread (via the threading
module), and have it disable clicking when it goes off. For example:
import threading
canClick = True
def disableClicking():
global canClick
canClick = False
timer = threading.Timer(20.0, disableClicking)
timer.start()
while canClick:
# the rest of your code for counting clicks
After 20 seconds, the timer will go off, canClick
will be set to false, and the loop will end.
Python: How to click on the screen at a specific place in python, MAC OS
Instead of searching for "how to move the cursor in OSX using Python", you'll find much better results if you search for "how to move the cursor in OSX", then search for how to use that interface with Python.
It seems that Objective-C/Cocoa is used to integrate with the native Mac OS X interface, and the Python documentation recommends using PyObjC as a Python binding to Apple’s Objective-C/Cocoa framework.
Hopefully this is enough information to get you on your way.
Jenkins console output not in realtime
To clarify some of the answers.
ruby
orpython
or any sensible scripting language will buffer the output; this is in order to minimize the IO; writing to disk is slow, writing to a console is slow...- usually the data gets
flush()
'ed automatically after you have enough data in the buffer with special handling for newlines. e.g. writing a string without newline thensleep()
would not write anything until after thesleep()
is complete (I'm only usingsleep
as an example, feel free to substitute with any other expensive system call).
e.g. this would wait 8 seconds, print one line, wait 5 more seconds, print a second line.
from time import sleep
def test():
print "ok",
time.sleep(3)
print "now",
time.sleep(5)
print "done"
time.sleep(5)
print "again"
test()
for
ruby
,STDOUT.sync = true
, turns theautoflush
on; all writes toSTDOUT
are followed byflush()
. This would solve your problem but result in more IO.STDOUT.sync = true
for
python
, you can usepython -u
or the environment variablePYTHONUNBUFFERED
to makestdin/stdout/stout
not buffered, but there are other solutions that do not changestdin
orstderr
export PYTHONUNBUFFERED=1
for
perl
, you haveautoflush
autoflush STDOUT 1;
Python vs Bash - In which kind of tasks each one outruns the other performance-wise?
Typical mainframe flow...
Input Disk/Tape/User (runtime) --> Job Control Language (JCL) --> Output Disk/Tape/Screen/Printer
| ^
v |
`--> COBOL Program --------'
Typical Linux flow...
Input Disk/SSD/User (runtime) --> sh/bash/ksh/zsh/... ----------> Output Disk/SSD/Screen/Printer
| ^
v |
`--> Python script --------'
| ^
v |
`--> awk script -----------'
| ^
v |
`--> sed script -----------'
| ^
v |
`--> C/C++ program --------'
| ^
v |
`--- Java program ---------'
| ^
v |
: :
Shells are the glue of Linux
Linux shells like sh/ksh/bash/... provide input/output/flow-control designation facilities much like the old mainframe Job Control Language... but on steroids! They are Turing complete languages in their own right while being optimized to efficiently pass data and control to and from other executing processes written in any language the O/S supports.
Most Linux applications, regardless what language the bulk of the program is written in, depend on shell scripts and Bash has become the most common. Clicking an icon on the desktop usually runs a short Bash script. That script, either directly or indirectly, knows where all the files needed are and sets variables and command line parameters, finally calling the program. That's a shell's simplest use.
Linux as we know it however would hardly be Linux without the thousands of shell scripts that startup the system, respond to events, control execution priorities and compile, configure and run programs. Many of these are quite large and complex.
Shells provide an infrastructure that lets us use pre-built components that are linked together at run time rather than compile time. Those components are free-standing programs in their own right that can be used alone or in other combinations without recompiling. The syntax for calling them is indistinguishable from that of a Bash builtin command, and there are in fact numerous builtin commands for which there is also a stand-alone executable on the system, often having additional options.
There is no language-wide difference between Python and Bash in performance. It entirely depends on how each is coded and which external tools are called.
Any of the well known tools like awk, sed, grep, bc, dc, tr, etc. will leave doing those operations in either language in the dust. Bash then is preferred for anything without a graphical user interface since it is easier and more efficient to call and pass data back from a tool like those with Bash than Python.
Performance
It depends on which programs the Bash shell script calls and their suitability for the subtask they are given whether the overall throughput and/or responsiveness will be better or worse than the equivalent Python. To complicate matters Python, like most languages, can also call other executables, though it is more cumbersome and thus not as often used.
User Interface
One area where Python is the clear winner is user interface. That makes it an excellent language for building local or client-server applications as it natively supports GTK graphics and is far more intuitive than Bash.
Bash only understands text. Other tools must be called for a GUI and data passed back from them. A Python script is one option. Faster but less flexible options are the binaries like YAD, Zenity, and GTKDialog.
While shells like Bash work well with GUIs like Yad, GtkDialog (embedded XML-like interface to GTK+ functions), dialog, and xmessage, Python is much more capable and so better for complex GUI windows.
Summary
Building with shell scripts is like assembling a computer with off-the-shelf components the way desktop PCs are.
Building with Python, C++ or most any other language is more like building a computer by soldering the chips (libraries) and other electronic parts together the way smartphones are.
The best results are usually obtained by using a combination of languages where each can do what they do best. One developer calls this "polyglot programming".
Language to learn to move out of manual testing towards automated/programming
Wow this is quite a widesweeping question. I'd say you were in a good position as the industry moves towards a Test Driven Development (or write your tests before your code) model.
First of all you'll want to know about Unit Testing, Continuous Integration and Web Automation.
I'm going to focus on the areas I know (.NET, Java, Javascript, Build automation, Selenium)
In .NET NUnit is probably the most widely used unit testing framework. It is a port (copy of) JUnit in the java world. Most unit testing frameworks are very similar to these in terms of the concepts. So learn one and it won't take you long to pick up the others.
I think reading the above links and having an idea about these concepts will get you on your way. It's probably worth experimenting with Python or Ruby as these have low barriers to entry to mess around with some simple tests.
For web based testing the most well known are probably Selenium and Watin. These allow you to script browsers to perform actions automatically. However, I have come across very few good usage of these and they are very fiddly (you're talking days/weeks of effort) to get set up and useful. Again the concepts behind these are similar whatever framework you use.
Think I answered 4,5,6 in 1,2,3 :-)
HTH
Related Topics
Using Beautifulsoup to Extract Text Without Tags
Inverting a Dictionary with List Values
Tensorflow Different Ways to Export and Run Graph in C++
How to Customise Qgroupbox Title in Pyqt5
Converting Yes and No to 0 and 1 in R
Pyobjc VS Rubycocoa for MAC Development: Which Is More Mature
If Monkey Patching Is Permitted in Both Ruby and Python, Why Is It More Controversial in Ruby
Import Pandas Dataframe Column as String Not Int
What Is the Performance Impact of Non-Unique Indexes in Pandas
Preserving Styles Using Python's Xlrd,Xlwt, and Xlutils.Copy
Pyqt: No Error Msg (Traceback) on Exit
In Python, How to Capture the Stdout from a C++ Shared Library to a Variable
Using Beautiful Soup to Convert CSS Attributes to Individual HTML Attributes
Matplotlib Analog of R's 'Pairs'
Restrictons of Python Compared to Ruby: Lambda'S
Looking for Recommendation on How to Convert PDF into Structured Format
Vscode -- How to Set Working Directory for Debugging a Python Program