17

We've written some Lightning Testing Service tests but its been hard work given the asynchronous nature of the code and that the LockerService blocks access to the underlying DOM. I'm now wondering if it would make more sense to run Selenium tests on the components assembled into an app.

I'd like to know what approach to automated testing of Lightning Components others have taken - please share.

PS

One of the big improvements in Lightning Web Componets looks like testability. So writing those and their tests instead of Aura Components and LTS stuff looks like the best way to go.

5
+50

I haven't started this yet, but it's on my list of next projects. I don't have an answer as such, but there's been no discussion yet, so maybe this will help to start one...

For my money, I need to get to the point where I am testing the front-end output and back-end data in the same test. The current approach of the Lightning Testing Service service only tests one slice of the layers that make up a Lightning app, and it's not even the one that causes the most problems.

Many of the problems I see are where the framework ends up rendering nothing, or "Sorry to interrupt" which can be due to the markup not the JS.

I also need to test on multiple platforms. In the course of building a Lightning Community with many customisations, I've had failures specific to: Chrome, Safari, and iPad. The last of which was only visible on an physical iPad, not the Safari mobile mode.

I can live with a test run that takes a day and is performed before a major deployment, but it must be repeatable and require nothing more than a button push to kick off.

So, that means that we are talking about some sort of automation to run the front-end, with some sort of test data setup/teardown on the back-end.

Every time I've had chance to talk to anyone in the know, I've asked about this and the consensus seems to be that SF are miles away from releasing anything like that.

If you can live in SFDX-land, then scratch orgs would work really nicely for the backend part. My first stab (which I started but didn't complete) was to use node.js to create a scratch org and populate tests.

From there, you can run tests with Selenium via something like mocha. I think this might require adding synthetic classes to production code to make selectors work consistently - which is distasteful, but not impossible.

I did talk to some "crowd-sourced testing" companies who take a natural English test spec and get real people to run them. This probably saves you the complication of Selenium selectors, but can be quite expensive. And you still need to automate setup/teardown and user creation. Without scratch orgs, I can't see this working at all easily.

  • 1
    Thanks for getting this discussion started! FYI the multiple browser part and continuous integration is working for us - see How to run Lightning Test Service (LTS) from Jenkins hosted on AWS against e.g. BrowserStack?. – Keith C Mar 21 '18 at 13:55
  • Hi Aidan, I guess we can infer from the lack of response here one or both of a) few people are doing any automated testing; b) those that are don't want to share their insight. 50 points coming your way in a couple of hours. – Keith C Mar 26 '18 at 13:47
  • 1
    Thanks Keith. It surely must be something that a lot of people care about. I've never had so many bugs in production and regressions as since doing significant work in Lightning. Scares the pants off me. My guess is we're all waiting for Salesforce to solve this, but I don't see them doing it soon :( – Aidan Mar 26 '18 at 14:27
  • Sorry for the late reply, but I wanted to drop a link to the integration we've built with Robot Framework to do pretty much exactly what was discussed in this article: be able to interact with the org configuration (metadata, data, etc) and also do browser tests. You can see more info here: cumulusci.readthedocs.io/en/latest/robotframework.html Also, here's a test suite for the NPSP we're building out now on top of this: github.com/SalesforceFoundation/Cumulus/tree/feature/robot/… – Jason Lantz Jul 26 '18 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.