Skip to content

Test Complete: managing remote linux services (JBOSS_SVC example)

February 9, 2015

There are some situations when you need to test application on remote Linux server and sometimes one needs to reboot some services. So we face this problem when we need to restart jboss service remotely from Test Complete js code on Windows based PC.

First of all you need to install putty and plink applications onto your Test Executor PC.

Then you need to create files with service commands, e.g.:

startjboss


service JBOSS_SVC start

and stopjboss


service JBOSS_SVC stop

To operate with putty and plink execution use the following code example:

var JBOSS_EXEC_START_FILE_PATH = ProjectSuite.Path + "path\\to\\linuxcmd\\startjboss";
var JBOSS_EXEC_STOP_FILE_PATH = ProjectSuite.Path + "path\\to\\linuxcmd\\stopjboss"

function callServiceLinux(connectorProperties, command) {
    setUpRemoteConnection(connectorProperties)
    var WshShell = new ActiveXObject("WScript.Shell");
    var oExec = WshShell.Exec("cmd.exe /q /k echo off");
    oExec.StdIn.WriteLine("chcp 65001");

    // used for accepting fingerprint
    // using command: "echo y | plink root@172.16.2.210 -pw 11111 exit"

    var plinkCmd = "echo y | plink %s@%s -pw %s exit"
    var puttyCmd = "putty %s@%s -pw %s -m %s"

    oExec.StdIn.WriteLine(aqString.Format(plinkCmd, OSPath.LINUX_USERNAME, connectorProperties.host, OSPath.LINUX_PASSWORD))

    if (command == OSPath.JBOSS_CMD_START) {
        oExec.StdIn.WriteLine(aqString.Format(puttyCmd, OSPath.LINUX_USERNAME, connectorProperties.host, OSPath.LINUX_PASSWORD,
            OSPath.JBOSS_EXEC_START_FILE_PATH))
    } else if (command == OSPath.JBOSS_CMD_STOP) {
        oExec.StdIn.WriteLine(aqString.Format(puttyCmd, OSPath.LINUX_USERNAME, connectorProperties.host, OSPath.LINUX_PASSWORD,
            OSPath.JBOSS_EXEC_STOP_FILE_PATH))
    } else {
        Log.Error("Incorrect command: '" + command + "'")
        return false
    }
    return true
}

plink used for accepting fingerprint prompt, e.g.:

echo y | plink root@172.15.2.210 -pw password1334 exit
Advertisements
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: