Yes. You can record a selenium script and use this to position the browser to the page or state you want before taking a screenshot. This is very useful in capturing screenshots of pages that cannot be shown directly via a particular url. Using the selenium script, you can navigate to the proper page, enter information into certain fields, perform actions, etc. After this script is finished, the screenshot engine will produce a screenshot of this page.
Recording the selenium script
The selenium script needs to be in json format. The easiest way to add a selenium script to the screenshot system is to use Selenium Builder with the CrossBrowserTesting plugin. With Selenium Builder, you can record a script in your local Firefox browser. When finished, open the CrossBrowserTesting settings screen (File, CrossBrowserTesting Setttings). Make sure your user name and the api auth key (see http://crossbrowsertesting.com/apidocs) for your account is entered. Enter a name for the selenium script, and press ‘Save script to advanced options page’.
Using the selenium script in a screenshot
Launch the test center and go to the Screenshots page. Enter a url for the screenshot test so you can remember what page this screenshot is for. The system will rely on the selenium script to go to the proper page, so this url is not used in making the screenshot. Click on the Advanced Options area, and turn on the Selenium Script. Select the script that you saved previously. We recommend running only one screenshot when first testing a new selenium script – once you have tested it you can rerun the screenshot test and select the browsers you need.
It is suggested to do the following to have the best success rate in creating screenshots using this technique:
- Keep it simple.
- Keep the number of actions to a minimum
- Have good ids on elements you will be interacting with to keep the selectors simpler
For more information on how to use Selenium Builder with the CrossBrowserTesting plugin, see the following FAQ:
How do I record and run selenium tests in Selenium Builder?