1

How can I run an AutoIT script over a Selenium Grid set up?

I have the .exe file on all machines but need to have the Selenium Script to call this to run on each node of the grid, is this possible?

nick
  • 19
  • 1
  • 2
  • Did you ever get your answer? It would help if you better describe your grid execution deployment/environment. Like where does the test code run from. Does the test code run locally at each grid node? Or does test run from some test agent machine A and connects to grid hub B that then passes execution to actual grid node C-Z? – David Jan 12 '15 at 04:15
  • Did u get any answer for this? – HemaSundar Sep 02 '15 at 14:50

3 Answers3

4

Your question (at time of this writing) isn't very detailed about your specific test setup for grid deployment. So an exact answer can't be proposed as it depends on how your environment is set up.

The simplest approach is to use PSExec.exe, telnet, or SSH to remotely call AutoIt on the node machine from your test execution machine. A simple example is given below, note that I have not tested the code, but should work with minor tweaks if needed.

String cmd = "C:\\LocalMachinePathTo\\psexec.exe \\\\%s -u %s -p %s -i C:\\GridNodeMachinePathTo\\autoit.exe";
Process p = Runtime.getRuntime().exec(String.format(cmd,gridNodeHostName,gridNodeWindowsLoginUserName,gridNodeWindowsLoginPassword);
p.waitFor();

The simple example assumes you use the native local desktop (or console/head) session of the grid node machine for running automated tests, and not using a remote desktop session to the grid node. If the latter, you would then need to supply a session ID after the -i parameter to psexec.exe. You can find more info on PSExec.exe here:

http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

The code presented is simple example, you may prefer to add additional logic to check if test is executing locally or over grid, where if executing locally, your command can omit use of psexec and just call autoit.exe directly.

Read these blog posts for more details/insight into making AutoIt run with tests on Selenium grid:

https://autumnator.wordpress.com/2015/01/22/integrating-autoit-sikuli-and-other-tools-with-selenium-when-running-tests-in-selenium-grid/

https://autumnator.wordpress.com/2011/12/22/autoit-sikuli-and-other-tools-with-selenium-grid/

David
  • 3,223
  • 3
  • 29
  • 41
0

This should work for you:

String cmd = "C:\\PathToExe\\autoit.exe";
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
Richard
  • 8,961
  • 3
  • 38
  • 47
  • If the machine executing the Selenium test code is not on same machine as the grid node, won't this just execute the code locally, with the cmd path targeted at Selenium code machine and not the grid node. – David Jan 12 '15 at 04:08
0

I usually package the autoit .exe as a resource into the .jar. Then you can do something like this:

    // locate an executable script in the resources
    URL res = getClass().getResource("/autoit/autoit_helloworld.exe");
    // locate the script in the filesystem
    File f = new File(res.file);
    assertTrue(f.canExecute());

    Process prog = Runtime.runtime.exec(f.canonicalPath);
    assertEquals(0, prog.waitFor());
SiKing
  • 10,003
  • 10
  • 39
  • 90
  • I might be mistaken, but this technique at first glance seems to work only if the machine executing the Selenium test code and the machine running the server JAR (or Java bindings JAR) are the same machine. So if code run on machine A but connects to grid node machine B, this wouldn't work? Because Java code refers to resource in a JAR (but the actual target JAR is on a remote host), so it would only be fetching the local JAR's version of the resource. – David Jan 12 '15 at 04:13
  • Yes, this code does not transfer the resource to a remote machine. – SiKing Jan 12 '15 at 15:34