Skip to content

Commit

Permalink
[system variables]
Browse files Browse the repository at this point in the history
- [`nexial.browser.lang`]: now supports changing browser language to aid the testing of language-aware websites.

[web]
- [`switchBrowser(profile,config)`]: fix issue with rendering multiple independent browsers.
  • Loading branch information
mikeliucc committed Nov 29, 2022
1 parent 80af801 commit fcc1a0d
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 91 deletions.
12 changes: 6 additions & 6 deletions commands/web/switchBrowser(profile,config).md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ comments: true
This command instructs Nexial to suspend the automation on the current browser (if any) and switch the automation to
another browser instance.

At times, it is critical to automate with multiple independent browser to browser to sufficiently validate the intended
At times, it is critical to automate with multiple independent browsers to sufficiently validate the intended
functionality of the target application. In the context of automation, "independent browsers" means browsers that are
sequestered from each other in terms of processes and session management. As such, one can toggle automation between
multiple personae and their respective browsing experience. It is then possible to observe and validate the intended
consequences of these personae independently interacting with the application. For example, we can use this command to
simulate 2 users bidding (online) on the same product, or to simulate 2 (or more) users chatting online via the same
channel.

This command takes 2 parameters: `profile` is an user-defined _identifier_ to reference a specific browser instance.
This command takes 2 parameters: `profile` is a user-defined _identifier_ to reference a specific browser instance.
One can toggle between multiple browser instances using the `profile` parameter. The `config` parameter is a set of
name-value configurations to determine the construct of a browser instance. Each name-value pair would take up a line,
or separated by comma. For example,<br/>
name-value configurations to determine the construct of a browser instance. Each name-value pair would take up a line.
For example,<br/>
![](image/switchBrowser_01.png)

This means to switch the automation to another browser, referenced as `adminBrowser`, which :
Expand All @@ -31,8 +31,8 @@ This means to switch the automation to another browser, referenced as `adminBrow
the automation script,
4. shall use "light red" background color as the highlight

Just about any [System variables](../../systemvars/) prefixed by `nexial.browser` or `nexial.web` can be included in
the `config` parameter. If no special configuration is needed, simply use `(empty)` or `(blank)` instead.
Just about any [System variables](../../systemvars/) that is prefixed by `nexial.browser` or `nexial.web` can be
included in the `config` parameter. If no special configuration is needed, simply use `(empty)` or `(blank)` instead.

After this command is executed, any subsequent [web] commands will take effect on the newly switched-to browser. To
switch to another browser instance, simply issue this command again with another `profile` name. To switch to the
Expand Down
164 changes: 82 additions & 82 deletions jsonpath/index.md

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion release/nexial-core-v4.4.changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ comments: true
- [`nexial.targetDisplay`](../systemvars/index.html#nexial.targetDisplay): Support display pinning so that the browser
used during automation will be opened to a display (monitor) of your choice. Expected 0-based value for display, or
use `CURRENT` for currently active monitor. For example, `nexial.targetDisplay=CURRENT|0|1|...`
- [`nexial.browser.windowSize`](../systemvars/content.html#nexial.browser.windowSize): now supports specialized
- [`nexial.browser.windowSize`](../systemvars/index.html#nexial.browser.windowSize): now supports specialized
keyword (one of `maximized`, `maximize`, `fullscreen`, `full`) to maximize browser window when it initially opens.
- [`nexial.browser.lang`](../systemvars/index.html#nexial.browser.lang): now supports changing browser language to aid
the testing of language-aware websites.


### [Expression](../expression)
Expand Down Expand Up @@ -144,6 +146,8 @@ comments: true
- suppress the certification selection dialog that pops up when accessing certain URL on Chrome (esp. when automation
is performed on an enterprise-managed compute resource).
- prevent the changing of window position on headless browsers.
- [`switchBrowser(profile,config)`](../commands/web/switchBrowser(profile,config)): fix issue with rendering multiple
independent browsers.


### [webmail commands](../commands/webmail)
Expand Down
26 changes: 24 additions & 2 deletions systemvars/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -3223,7 +3223,6 @@
Currently only the Chrome and Firefox browsers are support for this feature.
</td>
</tr>

<tr>
<td class="varname" nowrap="nowrap">
<a id="nexial.browser.meta"><code>nexial.browser.meta</code></a>
Expand All @@ -3236,6 +3235,29 @@
<a href="../commands/web/index#browser-metadata">Browser Metadata</a>.
</td>
</tr>
<tr>
<td class="varname" nowrap="nowrap">
<a id="nexial.browser.lang"><code>nexial.browser.lang</code></a>
</td>
<td>string</td>
<td></td>
<td class="read-write">read/write</td>
<td>
<b>NOTE: THIS SYSTEM VARIABLE IS EFFECTIVE ON CHROME BROWSER ONLY. FUTURE VERSION OF NEXIAL WILL LIKELY SUPPORT OTHER BROWSERS.</b>
<br/>
Use this System variable to change the browser's language setting. By default, the browser is launched using
the language setting of its underlying operating system. For the purpose of testing, it is sometimes useful
to change the browser's language setting in order to evaluate its impact on the target web application.<br/>
<br/>
For example, by setting <code>nexial.browser.lang</code> to <code>zh-TW</code>, Google Search is rendered
in Chinese:<br/>
<img src="image/nexial.browser.lang_01.png"/><br/>
<br/>
For more ideas and technical details, visit the <a href='../tipsandtricks/DiffLangSideBySide.html'>How to
automate website in different languages side-by-side</a>
<br/>
</td>
</tr>
<tr>
<td class="varname" nowrap="nowrap">
<a id="nexial.ignoreBrowserAlert"><code>nexial.ignoreBrowserAlert</code></a>
Expand Down Expand Up @@ -4069,7 +4091,7 @@
<li>user profile directory is platform-specified</li>
<li>user profile directory is not applicable for IE, Edge or Safari browser</li>
<li>when specified, this System variable will override the <a href="#nexial.browser.incognito">
<code>nexial.browser.incognito</code></a> System variable (default is <code>false</code>).
<code>nexial.browser.incognito</code></a> System variable (default is <code>true</code>).
</li>
</ol>
</td>
Expand Down
Binary file added systemvars/image/nexial.browser.lang_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 122 additions & 0 deletions tipsandtricks/DiffLangSideBySide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
layout: default
title: How to automate website in different languages side-by-side
parent: Tips and Tricks
tags: command tipsandtricks web language lang side-by-side windowSize windowPosition
comments: true
---

<style>
table {
width: 950px;
margin: 15px 0;
font-size: 10pt;
font-family: Tahoma, serif;
}

table th {
font-weight: bold;
}

table td code {
background-color: transparent;
border: none;
font-family: Consolas, monospace;
}

</style>

### Introduction
Multilingual websites deserve additional tests - namely language-related UX such as content layout and form submission.
Generally speaking, such type of testings are a subset of internationalization (i18n) testing. With Nexial, we can
automate some od the i18n testing within a single execution with the help of 2 specific features:
- [web &raquo; switchBrowser(profile,config)](../commands/web/switchBrowser(profile,config))
- System variable [`nexial.browser.lang`](../systemvars/index.html#nexial.browser.lang)

Read on to learn more.


### Configure the language
By default, web browser aligns to the language setting of its underlying operating system. For multilingual website
testing, it is not always practical to change the language setting of the operating system in order to test the same
website rendered in another language. With Nexial, we can accomplish this by simply using the System variable
[`nexial.browser.lang`](../systemvars/index.html#nexial.browser.lang).

One can pin this System variable via the appropriate data file,
[`project.properties`](../userguide/UnderstandingProjectStructure.html#artifactprojectproperties), or command line for
just-in-time override. Here's an example how one could set this System variable via command line:

```shell
cd ~/projects/nexial-core/bin
./nexial.sh \
-override nexial.browser.lang=es \
-script ~/projects/MyProject/artifact/script/MyScript.xlsx \
... ...
```
As a result, navigating to a language-aware website, such as Google Search, will render its content in Spanish (if the
website supports Spanish).

For a good listing of all possible languages, check out the
<a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes" target="_nexial_link">List of ISO 639-1 codes</a>.


### Switching between multiple independent browsers
In addition to the ability to change browser language, Nexial also provides a way to open up multiple independent
browsers - and possibly in different language setting. To accomplish this, we would use the
[web &raquo; switchBrowser(profile,config)](../commands/web/switchBrowser(profile,config)) command. With this command
we can switch between multiple independent browsers -- browsers that do not share cache or cookies -- and each browser
instance with different settings.

Let's see an example below:<br/>
![](image/DiffLangSideBySide_01.png)

Here, we are instructing Nexial to open `https://www.google.com` on one browser instance (the default browser instance),
and then "switching" to another browser (new browser instance). Notice that the second
argument of the `switchBrowser` command contains a series of settings:

```
nexial.browser=chrome
nexial.browser.lang=en
nexial.browser.windowPosition=800,0
nexial.browser.windowSize=800x800
```

... which effectively reads:

> create a new browser instance, named as `en-browser`, that is:
> - a Chrome browser,
> - with browser language set to English
> - with browser window position set to x-position 800, y-position 0
> - with browser window size set to 800x800
The third command (`open(url)`) then opens `https://www.google.com` on the new browser instance.

We can execute the above script with the command line overrides to change the browser language to Chinese (`zh-TW`) and
the browser window size to `800x800`:

```shell
cd ~/projects/nexial-core/bin
./nexial.sh \
-override nexial.browser.lang=zh-TW \
-override nexial.browser.windowSize=800x800 \
-script ~/projects/MyProject/artifact/script/MyScript.xlsx \
... ...
```

The end results looks like this:<br/>
![](image/DiffLangSideBySide_02.png)

Notice that the browsers are laid out side-by-side because of the `nexial.browser.windowPosition` configuration
specified as part of the `switchBrowser()` command. Notice also that Google Search does not look the same when
rendered in English and Chinese. Clearly more i18n testing is needed here!

We can now switch between these 2 browser instances using the same `switchBrowser()` command. For example, we can
open up another website on both browsers to test out the content layout under different language rendering:<br/>

![](image/DiffLangSideBySide_03.png)<br/>

Note that the default browser instance has a "profile" name as `DEFAULT`.

Here are how they look side-by-side:<br/>
![](image/DiffLangSideBySide_04.png)

Binary file added tipsandtricks/image/DiffLangSideBySide_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tipsandtricks/image/DiffLangSideBySide_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tipsandtricks/image/DiffLangSideBySide_03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tipsandtricks/image/DiffLangSideBySide_04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tipsandtricks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ redirect_from:
- [Forcefully update or omit webdriver updates](HOWTOForcefullyUpdateWebDriver)
- [How to check edge browser version](HOWTOCheckEdgeVersion)
- [How to validate canvas-based chart data](ValidateChartData)
- [How to automate website in different languages side-by-side](DiffLangSideBySide)


#### External Services
Expand Down

0 comments on commit fcc1a0d

Please sign in to comment.