Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Python script to automate software installation? [closed]

I want to automate the software installation process. The scenario is as follows:

Run the installation file. On first screen it has two buttons next, cancel. On click of next it goes to next screen having two buttons, next, cancel and some input data is required. After details are provided, it will show finish or cancel button.

I want to write a Python script that would automate this activity. It should identify the button and click it. It should enter the data wherever required and finish the installation. To achieve this functionality:

  1. Python API is required, if any?
  2. Some code samples or link of the tutorials to use the same.

Sample image for reference:

Sample image for reference

like image 701
guru Avatar asked Jan 12 '15 12:01

guru


People also ask

How do I automate a Python script in Windows?

In order to schedule the Python script using the Windows Scheduler: Open the Windows Control Panel and then click on the Administrative Tools. Double-click on the Task Scheduler, and then choose the option to 'Create Basic Task…' Type a name for your task (you can also type a description if needed), and then press Next ...

How do I create a Python script?

Create a Python fileIn the Project tool window, select the project root (typically, it is the root node in the project tree), right-click it, and select File | New .... Select the option Python File from the context menu, and then type the new filename. PyCharm creates a new Python file and opens it for editing.


1 Answers

As Rawing mentioned, pywinauto is good choice for Windows installer. Here is nice sample video: http://pywinauto.github.io/

For waiting next page use something like that: app.WizardPageTitle.wait('ready')
When installer finished: app.FinishPage.wait_not('visible')
For edit box input: app.WizardPage.Edit.type_keys('some input path', with_spaces=True)
For button clicks I'd recommend click_input() as more reliable method.

If you want to install the app on many machines automatically, you can create Remote Desktop or VNC session and run local copy of the Python script inside that session. Just do not minimize RDP or VNC window to prevent GUI context loss. Losing focus is safe and you can continue your work on master machine in another window without affecting remote installation.


Example of easy install script for FastStone Image Viewer 4.6:

import os
from pywinauto.application import Application

fsv = Application(backend="win32").start("FSViewerSetup46.exe")

fsv.InstallDialog.NextButton.wait('ready', timeout=30).click_input()
fsv.InstallDialog.IAgreeRadioButton.wait('ready', timeout=30).click_input()
fsv.InstallDialog.Edit.Wait('ready', timeout=30).type_keys(os.getcwd() + "\FastStone Image Viewer", with_spaces=True)
fsv.InstallDialog.InstallButton.wait('ready', timeout=30).click_input()
fsv.InstallDialog.FinishButton.wait('ready', timeout=30).click_input()
like image 110
Vasily Ryabov Avatar answered Oct 19 '22 17:10

Vasily Ryabov