Know more about Automated Testing in Salesforce
Automated testing is the testing of the software through the specialized tools, which includes performing the following steps: start, initialization, execution, receiving and analysis of the test result.
Selenium is a tool specifically designed to conduct automated testing of web applications in various browsers and within various platforms. It should be noted that any routine actions performed in the browser can be automatically tested using Selenium, not only web applications.
Selenium supports functional and regressive testing.
The main types of locators in Selenium are: ID, ClassName, Name, TagName, LinkText, PartialLinkText, Xpath, CSS Selector, DOM.Xpath is a declarative query language for elements of an XML or XTHML document. It navigates the document based on its logical structure and hierarchy.
- To automate tests on the SF platform, we use the Intelij Idea development environment
- All the tests are related and we use Maven
- pom.xsml is the configuration file of our project
- To write auto tests, we have to use salesforce libraries. Maven automatically downloads them and adds them into our project
- All libraries and their related elements should be enclosed into the Dependencies tag.
- To write auto tests we need junit and selenium webdiver java
- Next, we need to import our changes: click on the link in the lower right corner to Import Changes
- Go to the src folder->test->java, press new package, and define the folder name of our project. We need to make sure that all projects have unique names
In our example, we use Xpath to search elements – we have used it for simplicity although it is not the most reliable way to find the elements. In most cases, it’s better to use unique names as locators.
How to get Xpath for particular element:
- Open the inspector (F12) to find the desired element on the page, click on it;
- After the element is selected in the inspector, right-click on the selected element in the inspector;
- Copy the Xpath element,
- Paste the Xpath into your source where you use driver.findElement (By.xpath (“”)) command.
In our example below, we will log in to the community and create an Idea. For that, we create a Main class containing steps for creating an idea in the Community. We use the AC Enterprise Ideas with Lightning Experience support component v1.28mar19 / 1.28.0
We use the following techniques to post an Idea:
- To find appropriate fields to insert text we use driver.findElement(By.xpath(“”)).sendKeys(“”)
- To find buttons or links to click we, use the driver.findElement(By.xpath(“”)).click()
- To find a drop-down list and select a value from the list, we use
WebElement select = driver.findElement(By.xpath (“”));
List<WebElement>sekect_li = select.findElements(By.tagName (“li”));
- To set the delay in execution, we use the Thread.sleep()
See full source code below
Advanced Communities at Dreamforce 2022: Final Thoughts
5 (3) Last week was both exciting and important to all Salesforce fans due to the Salesforce Dreamforce 20th-anniversary conference...