Using Perl, Python, or Ruby, How to Write a Program to "Click" on the Screen at Scheduled Time

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 or python 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 then sleep() would not write anything until after the sleep() is complete (I'm only using sleep 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 the autoflush on; all writes to STDOUT are followed by flush(). This would solve your problem but result in more IO.

    STDOUT.sync = true
  • for python, you can use python -u or the environment variable PYTHONUNBUFFERED to make stdin/stdout/stout not buffered, but there are other solutions that do not change stdin or stderr

    export PYTHONUNBUFFERED=1
  • for perl, you have autoflush

    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)

  1. 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.

  2. 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.

  3. 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



Leave a reply



Submit