📜 ⬆️ ⬇️

Visual scripting

Prehistory


Each of us has ever come to the idea of ​​the need to automate certain actions in the system. Personally, this thought came to me when I tried to explain to my brother how to rearrange the modem to the router mode and back (I’ll not go into details of why it was necessary to constantly change modes). Because the sequence of actions was rather obscure, and even required some data to be memorized (for example, the router's ip-addresses), I decided to automate the process, spending as little effort as possible. A little googling found a rather interesting project SIKULI. It allows you to automate the management of the GUI under the main OSes, and at the same time you do not even have to learn a new language! Those who are interested in visual scripting, please under the cat.


What kind of beast is that?


Immediately the question arises, why I put this topic in this blog. It's simple: Sikuli is a visual Python! Those. You can always use Python syntax.
But best of all, this project will be described by the developers themselves: “Sikuli is a visual technology for automating and testing a graphical interface using images (screenshots). Sikuli includes: Sikuli Script, a visual scripting API for Jython, and Sikuli IDE: a development environment for easy writing of screenshots visual scripts. Sikuli Script automates everything that you see on the screen, without using the internal API of the system. You can programmatically control web pages, Windows / Linux / Mac OS X applications, or even applications on the iPhone or Android running in the emulator, or via VNC. " So powerful and, as will be seen below, a simple scripting language is obtained.

Closer to the point


I will not consider IDE myself, since This has already been done for me by comrade KL7 in his topic Sikuli - program ANYTHING using GUI screenshoots . I will give a specific example of how I automated the change of router modes. All further manipulations are performed in Sikuli IDE. So let's get started.
')
The first thing to do is to launch a browser through which we will edit the modem settings. Because I have Crome installed in the user’s folder and the path to it contains Cyrillic, and Sikuli doesn’t support such paths poorly, then I used Opera as my browser. We have three functions for managing applications: openApp (), switchApp (), closeApp (). I will use switchApp () because Someone can already use the browser, in this case it does not make sense to create a new one.

Next, create a new tab. To do this, click on the appropriate button in the browser. To do this programmatically, you need to call the click () function. we select it in the list of functions on the right, the environment will be minimized, giving us the opportunity to select the area that needs to be clicked. Circle the button to create a new tab. in the end, our function in the editor window will look like this:
image

Immediately note how you set where and what to print. This is supported by the type function (), which can be transferred as a simple text, and the text with the image of the line where to write it.

Then it sometimes pops up, and sometimes it doesn't (depending on whether you closed the browser or not since the last login to the router settings), the login and password request window. An excellent case to demonstrate that, in addition to visual scripting, Sikuli also supports Python! So, checking whether the window popped up, I arranged as follows:
image

The next is a series of Click () functions, interrupted only in one place by the wait (10) function, because the browser needs to reload the page.

Finally, I close the tab with the properties of the router, calling the low-level keyboard control function: keyDown (Key.CTRL + "w")

Afterword


As a result, we have a fairly powerful tool for automating routine actions. You can read more about it on the official project website . Successful to you scripts!

Source: https://habr.com/ru/post/121924/


All Articles