1

I'm setting up a testing suite with Testcafe that is able to check the interface of multiple web apps made with the XAF framework. Problem is, that some buttons on the same place with the same functionality do have different names (i.e. "Sortierung aufheben" and "Sortierung entfernen"). Now I'd like to give Testcafe these two options to choose and let it use the one needed in the test.

I'm writing my test in Typescript 3.5 using VSC and Chrome to run the tests. Testcafe runs my assertion neatly when I only add one of the options on the withText() selector. If I try adding two in an array (see code below) it starts checking the first one first - which in case of one website is the wrong one - and fails.

My testing is working like this:

// Functions_Library.ts
FindListMultipleElements(propertyName, elementNames: string[]): Selector {
        var selector = "[class^='dxm-"+propertyName+"']";
        for (var i=0; i < elementNames.length; i++) {
            var element = Selector('body').find(selector).withText(elementNames[i]);
            if (element != null) {
                        return element;
                    }
        }
// all_tests.ts
listViews.forEach(listView => {

        test(`${moduleName} - ${listView.navbarItem} - ColumnCheck Tests`, async t => {
            await t
        .click(lib.FindListMultipleElements('content', ['Sortierung aufheben','Sortierung entfernen']))
         });
});

I would like to either have Testcafe skip the misfitting parameter or only choose the right one. Is this possible in some kind of way?

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Kalex
  • 35
  • 6
  • Do you control the html? If the button has the same functionality, I would ad a class `my-button-type` and have that be found. That way, you stay safe of wording changes in the future. – k0pernikus Aug 12 '19 at 08:43
  • Sadly not, a senior is using the XAF-Framework to generate it. – Kalex Aug 12 '19 at 08:47

1 Answers1

3

As I understand, you need to check if element exists before you click on it. It's possible with TestCafe. Please refer to this answer to get details.

Thus, you can create a array of selectors and iterate through them until the selector is found. If it is found successfully, you can continue working with it.

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Alex Kamaev
  • 6,198
  • 1
  • 14
  • 29