Useful Tips & Commands When Recording Test Cases

Updated 1 week ago by Copado Solutions

Copado Selenium Testing does not control some actions which have to be performed by your provider, such as BrowserStack, Sauce Lab, etc. Some commands are recommendable in order to avoid possible provider’s latencies or failures. Here you will find a list of useful commands as well as tips and tricks when recording Selenium test cases.

  • Use the Open command and add a direct URL to access one tab or specific page instead of recording all the clicks to get to that page. It is shorter, network-latencies-free and more efficient. We don’t want to test if Salesforce is working properly, rather if Copado is working as expected.
  • Use the Generate test case from last page feature in Copado Recorder to create a complete script from the page you are recording. 
  • Use datasets within your tests instead of creating several test cases.
  • Copy & paste commands from one test case to another instead of recording the whole path again.
  • Use the CopadoContext command to switchToClassic and switchToLightning context to make sure the test does not fail because someone changed the context. This command also allows you to find a New button or the Details tab in a page.
  • Some locators are sometimes difficult to detect. In case the element is not detected by the test, select another locator from the drop-down menu in Copado Recorder. In different environments, elements have different identifiers, so sometimes Selenium does not find them easily.
  • Use the Manage Test Runs manually checkbox in order to have a customized test group where each suite or test is run in a specific environment.
  • Use the copadoSetRetries and waitForElementPresent commands to avoid a failing test because of network or provider latencies.
  • Use v10 new commands: gotoIfError / gotoIf / gotoLabel / … to avoid known or possible errors which will make your tests fail.
  • Some alerts are not being properly detected by Selenium. Use the verifyConfirmation, verifyAlert, etc. commands to detect them.
  • You can get a screen capture at any moment during a test run by just adding the following command in the recorder window: captureEntirePageScreenshot.
  • If you are testing a managed app before and after packaging, you can use the {!NS} variable to insert the namespace configured in the environment record.
  • If you need to execute a command with a blank value (to set a field as empty, for example), you can use the {!BLANK} variable for the value.
  • Useful date and datetime variables are: {!TODAY}, {!TODAY-1} (yesterday), {!NOW}, etc.
  • If possible, use the generate test case from last page button. It saves time and allows you to reuse the same test case for other purposes.
  • If you do record, start on the "all tabs" Salesforce page, and avoid clicking on Salesforce tabs. This reduces issues with the selected app and the visible tabs in multiple orgs.
  • Remember that some commands without a text in the value/dataset column will not be executed, so they will not slow down the test case.
  • Remember that the {!RUN_ID} variable can be used in value/dataset/apex columns. It is a random number per execution and it helps ensure that the created records are unique.
  • Watch out for locators containing a Salesforce ID. Some pages use these IDs as part of the name of an element, and they might be different among environments. Remember that you can manually choose another locator.
  • If you know that the page being tested is particularly slow, you can configure a complete test case to wait longer by inserting the command: copadoSetRetries <number of retries> <milliseconds between retries>, e.g. copadoSetRetries 50 1000 will try 50 times, waiting 1 second between tries, before failing a command.
  • You can reorder your test case commands and copy and paste rows/columns between test cases, or even from/to spreadsheets. Additional locators and other related information will not be copied/pasted.
  • Developers can help greatly in testing by assigning HTML labels to form fields, clear name attributes and meaningful Ids.
  • Remember that this tool is geared towards Smoke Testing. It cannot replace Apex Testing or other forms of integration tests.
  • If you want to skip a step in a test case, you can use the # before the desired command, e.g. #click, #assertText, #type.

How did we do?