Skip to content

squape.squishserver

SquishServer

SquishServer(location=None, host=None, port=None)

Class to configure a running local or remote squishserver

Parameters:

Name Type Description Default
location str

The location of the Squish package. If provided, this value will be used. If not provided, it will be taken from the squishserver process.

None
host str

The host of the squishserver. If provided, this value will be used. If not provided, the value of the squishrunner's "--host" will be used if set. If "--host" was not set, the default value "127.0.0.1" will be used.

None
port int

The port of the squishserver. If provided, this value will be used. If not provided, the value of the squishrunner's "--port" will be used if set. If "--port" was not set, the default value "4322" will be used.

None
Source code in squape/squishserver.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def __init__(self, location=None, host=None, port=None):
    """Open an RemoteSystem connection to a running squishserver

    Args:
        location (str, optional): The location of the Squish package.
            If provided, this value will be used.
            If not provided, it will be taken from the squishserver process.
        host (str, optional): The host of the squishserver.
            If provided, this value will be used.
            If not provided, the value of the squishrunner's "--host"
            will be used if set.
            If "--host" was not set, the default value "127.0.0.1" will be used.
        port (int, optional): The port of the squishserver.
            If provided, this value will be used.
            If not provided, the value of the squishrunner's "--port"
            will be used if set.
            If "--port" was not set, the default value "4322" will be used.
    """

    if host is None:
        self._host = os.environ.get("SQUISHRUNNER_HOST", "127.0.0.1")
    else:
        self._host = host

    if port is None:
        if "SQUISHRUNNER_PORT" in os.environ:
            self._port = int(os.environ["SQUISHRUNNER_PORT"])
        else:
            self._port = 4322
    else:
        self._port = port

    try:
        self._remotesys = RemoteSystem(self.host, self.port)
    except Exception:
        raise SquishserverError(
            f"Unable to connect to squishserver ({self.host}:{self.port})"
        )

    if location is None:
        try:
            self._location = self.remotesys.getEnvironmentVariable("SQUISH_PREFIX")
        except KeyError:
            raise EnvironmentError(
                "The SQUISH_PREFIX environment variable is not set, "
                "and location of the squishserver "
                f"({self.host}:{self.port}) is not specified!"
            )
    else:
        self._location = location

host property

host

The host of the squishserver.

location property

location

The location of the Squish package.

os_name property

os_name

Name of the Operating System where the squishserver is running.

port property

port

The port of the squishserver.

remotesys property

remotesys

RemoteSystem of the squishserver.

addAUT

addAUT(aut, path)

Register an AUT

Parameters:

Name Type Description Default
aut str

the name of the executable

required
path str

path to the executable folder

required
Source code in squape/squishserver.py
130
131
132
133
134
135
136
137
138
139
140
141
def addAUT(self, aut: str, path: str) -> None:
    """Register an AUT

    Args:
        aut (str): the name of the executable
        path (str): path to the executable folder
    """
    log(
        f"[Squishserver {self.host}:{self.port}] "
        f"Registering {Path(path)/aut} AUT"
    )
    self._config_squishserver("addAUT", [aut, path])

addAppPath

addAppPath(path)

Register an AUT path

Parameters:

Name Type Description Default
path str

the AUT path to register

required
Source code in squape/squishserver.py
156
157
158
159
160
161
162
163
def addAppPath(self, path: str) -> None:
    """Register an AUT path

    Args:
        path (str): the AUT path to register
    """
    log(f"[Squishserver {self.host}:{self.port}] " f"Registering AUT path: {path}")
    self._config_squishserver("addAppPath", [path])

addAttachableAut

addAttachableAut(aut, port, host='127.0.0.1')

Register an attachable AUT

Parameters:

Name Type Description Default
aut str

the name of the attachable AUT

required
port int

port of the machine where the attachable AUT is supposed to be running.

required
host str

host of the machine where the attachable AUT is supposed to be running. Defaults to "127.0.0.1".

'127.0.0.1'
Source code in squape/squishserver.py
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
def addAttachableAut(self, aut: str, port: int, host: str = "127.0.0.1") -> None:
    """Register an attachable AUT

    Args:
        aut (str): the name of the attachable AUT
        port (int): port of the machine where the attachable AUT
                    is supposed to be running.
        host (str, optional):   host of the machine where the attachable AUT
                                is supposed to be running.
                                Defaults to "127.0.0.1".
    """
    log(
        f"[Squishserver {self.host}:{self.port}] "
        f"Registering an attachable AUT {aut}"
    )
    self._config_squishserver("addAttachableAUT", [aut, f"{host}:{port}"])

attachToApplication

attachToApplication(aut)

Attaches to an application with given name.

Parameters:

Name Type Description Default
aut str

the name of the attachable AUT

required

Returns:

Type Description
ApplicationContext

application context

Source code in squape/squishserver.py
211
212
213
214
215
216
217
218
219
220
221
222
223
def attachToApplication(self, aut: str):
    """
    Attaches to an application with given name.

    Args:
        aut (str): the name of the attachable AUT

    Returns:
        (ApplicationContext): application context
    """
    log(f"[Squishserver {self.host}:{self.port}] " f"Attach to application {aut}")
    ctx = squish.attachToApplication(aut, self.host, self.port)
    return ctx

execute_cmd_async

execute_cmd_async(command, options=None)

Executes the command with optional arguments asynchronously. This convenience function runs a command as is, leveraging the environment settings provided by the squishserver.

For more advanced use cases, such as specifying a custom current working directory (cwd) or environment variables, please use the squishserver.remotesys.execute(...) method directly.

Parameters:

Name Type Description Default
command str

The command to execute

required
options List[str]

A list of options for the command

None

Returns:

Type Description
None

None

Source code in squape/squishserver.py
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
def execute_cmd_async(self, command: str, options: List[str] = None) -> None:
    """Executes the command with optional arguments asynchronously.
    This convenience function runs a command as is, leveraging the environment
    settings provided by the squishserver.

    For more advanced use cases, such as specifying a custom current working
    directory (cwd) or environment variables, please use the
    `squishserver.remotesys.execute(...)` method directly.

    Args:
        command (str): The command to execute
        options (List[str]): A list of options for the command

    Returns:
        None
    """
    options = options or []
    if self.os_name == "Windows":
        cmd = ["cmd.exe", "/s", "/c", "start", "", "/min", command, *options]
    else:
        cmd = ["sh", "-c", f"{command} {' '.join(options)} >/dev/null 2>&1 &"]
    self.remotesys.execute(cmd)

execute_cmd_sync

execute_cmd_sync(command, options=None)

Executes the command with optional arguments synchronously. This convenience function runs a command as is, leveraging the environment settings provided by the squishserver.

For more advanced use cases, such as specifying a custom current working directory (cwd) or environment variables, please use the squishserver.remotesys.execute(...) method directly.

Parameters:

Name Type Description Default
command str

The command to execute

required
options List[str]

A list of options for the command

None

Returns:

Type Description
List[str]

A list/array with three elements: exitcode, stdout, stderr

Source code in squape/squishserver.py
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
def execute_cmd_sync(self, command: str, options: List[str] = None) -> List[str]:
    """Executes the command with optional arguments synchronously.
    This convenience function runs a command as is, leveraging the environment
    settings provided by the squishserver.

    For more advanced use cases, such as specifying a custom current working
    directory (cwd) or environment variables, please use the
    `squishserver.remotesys.execute(...)` method directly.

    Args:
        command (str): The command to execute
        options (List[str]): A list of options for the command

    Returns:
        A list/array with three elements: exitcode, stdout, stderr
    """
    cmd = [command] + (options or [])
    return self.remotesys.execute(cmd)

removeAUT

removeAUT(aut, path)

Remove registered AUT

Parameters:

Name Type Description Default
aut str

the name of the executable

required
path str

path to the executable folder

required
Source code in squape/squishserver.py
143
144
145
146
147
148
149
150
151
152
153
154
def removeAUT(self, aut: str, path: str) -> None:
    """Remove registered AUT

    Args:
        aut (str): the name of the executable
        path (str): path to the executable folder
    """
    log(
        f"[Squishserver {self.host}:{self.port}] "
        f"Removing registered {Path(path)/aut} AUT"
    )
    self._config_squishserver("removeAUT", [aut, path])

removeAppPath

removeAppPath(path)

Remove a registered AUT path

Parameters:

Name Type Description Default
path str

the path to the AUT

required
Source code in squape/squishserver.py
165
166
167
168
169
170
171
172
173
174
175
def removeAppPath(self, path: str) -> None:
    """Remove a registered AUT path

    Args:
        path (str): the path to the AUT
    """
    log(
        f"[Squishserver {self.host}:{self.port}] "
        f"Removing registered AUT path: {path}"
    )
    self._config_squishserver("removeAppPath", [path])

removeAttachableAut

removeAttachableAut(aut, port, host='127.0.0.1')

Remove registered attachable AUT

Parameters:

Name Type Description Default
aut str

the name of the attachable AUT

required
port int

port of the machine where the attachable AUT is supposed to be running.

required
host str

host of the machine where the attachable AUT is supposed to be running. Defaults to "127.0.0.1".

'127.0.0.1'
Source code in squape/squishserver.py
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
def removeAttachableAut(self, aut: str, port: int, host: str = "127.0.0.1") -> None:
    """Remove registered attachable AUT

    Args:
        aut (str): the name of the attachable AUT
        port (int): port of the machine where the attachable AUT
                    is supposed to be running.
        host (str, optional):   host of the machine where the attachable AUT
                                is supposed to be running.
                                Defaults to "127.0.0.1".
    """
    log(
        f"[Squishserver {self.host}:{self.port}] "
        f"Removing registered attachable AUT {aut}"
    )
    self._config_squishserver("removeAttachableAUT", [aut, f"{host}:{port}"])

startApplication

startApplication(aut)

Starts to an application with given name.

Parameters:

Name Type Description Default
aut str

the name of the mapped AUT

required

Returns:

Type Description
ApplicationContext

application context

Source code in squape/squishserver.py
225
226
227
228
229
230
231
232
233
234
235
236
237
def startApplication(self, aut: str):
    """
    Starts to an application with given name.

    Args:
        aut (str): the name of the mapped AUT

    Returns:
        (ApplicationContext): application context
    """
    log(f"[Squishserver {self.host}:{self.port}] " f"Start an application {aut}")
    ctx = squish.startApplication(aut, self.host, self.port)
    return ctx