Tag Archives: truclient

Handling None Standard File Upload with TruClient

First let’s explain what is the “none standard file upload” for a website. Let a user upload a file is a very common use case for a website. The most common way to implement this would be

  1. <input type="file"/>


Then post the file content with form to the server. This is the standard way to upload a file with HTML. The standard way have several limitation. The most significant is difficult to customize the style for the upload file control.

So the none standard file upload come up with this requirement. The main idea is let the web designer customize the looking as they preferred. After the user click the control then dynamically create an input element or trigger a hidden input click in the background. This make the upload control looks much better, but it lead the feature hard for automation UI test. The common automation tools such as selenium(webdriver) and jmeter do not provide a elegant way to handle none standard upload. The reason is due to the input element is dynamically created which nearly impossible to locate it with CSS selector or XPath.

In TruClient 12.55+ which provide a easy way to handle none standard file upload.

Here is a simply code snippet for demo none standard file upload with jsfiddle at http://jsfiddle.net/erxin/o4menymo/

None standard file upload code sample

None standard file upload code sample

1. Drag a “General Object Action” step
2. Select the aim object which the user will click to upload the file
3. Change the step type from “Click” to “Upload”
4. Assign the right file path to the “Path” parameter
5. Done.

Currently the none standard file upload step only support in TruClient Chrome and IE. The Firefox version will coming soon.


Tip for Easily Backup Local Script Files in TruClient Lite Chrome

Currently TruClient Lite Chrome doesn’t support batch script operations. If the user want to back up all the local scripts, then they have to manually download the scripts one by one.
There are two ways to back up the scripts

  1. All the scripts are saved in the user data directory. So back up the user data directory will back up the script indirectly.
  2. We could use a hack way to download all the scripts as a single zip file.

Steps to back up user data folder

  1. Check the path from the command line of the shortcut of your TruClient Lite Chrome
    1. --user-data-dir=<profile dir> --extensions-on-chrome-urls --silent-debugger-extension-api --disable-web-security --no-first-run
  2. Back up the folder <profile dir>

Steps to download all the scripts as a single zip file

  1. Start the TruClient Lite
  2. Navigate to chrome://extensions/ to open the extension management pages for Chrome
  3. Check the Developer mode
  4. Click background page link for TruClient Lite
  5. Run the below code on console, the scripts will be saved
    1. var zip = new JSZip(); localforage.iterate((v, k) => { if(k.startsWith('/__scripts__/') && k.indexOf(':metadata:') === -1){ zip.file(k.split('/').pop()+'.zip', v); } }).then(()=>{ a = document.createElement('a'); a.href = window.URL.createObjectURL(zip.generate({type:"blob"})); a.download = "scripts.zip"; a.dispatchEvent(new MouseEvent("click")); });
  6. Restart TruClient Lite