2

In my Angular page there are 15 checkboxes and a label that when I select on each checkbox individually, a result will appear in the label. Plus when a checkbox click with a combination with others, the result will change in the label.

How can I run a Protractor loop to test these checkbox with a combination with each other, without involving with a lot of loops?

More Explanation

I have 15 checkboxes and I have to run a smoketest using Protractor. Run every possibility combination of these checkboxes and check the label that has the result to have expected result. Now is there a simple way to run these checkboxes combinations!

4
  • 2
    It sounds like a question with many answers. Perhaps you can be more specific. Ideally if you also show your example code how you approached this problem.
    – pavelsaman
    Jan 18, 2021 at 20:10
  • Do you really want to verify all 225 combinations? When the label value is set by back-end logic, it might be better to create unit tests for the back-end code.
    – Bouke
    Jan 21, 2021 at 12:47
  • Does your application show 225 unique label text based on each combination?? I doubt that. If it doesn't display that many different label values , then we shouldn't create that many test combinations. Feb 7, 2021 at 11:17
  • Let's say it is creating 15 different label text covering all these 225 checkbox combinations then we can reduce it substantially to only make 15-20 checks only. Feb 7, 2021 at 11:23

1 Answer 1

1

Assuming you have a pagebject method pageObject.selectCheckbox(idx) which select a checkbox using index. and pageObject.verify("Message") which takes in the expected message and verifies its present.

let final = []
printCombination = function (arr, n, r) {
    data = Array(r)
    combinationUtil(arr, data, 0, n - 1, 0, r)
}

combinationUtil = function (arr, data, start,
    end, index, r) {
    let i = ""
    if (index == r) {
        for (j of [...Array(r).keys()]) {
            i += data[j]
        }
        console.log(i)
        final.push(i)
        return i
    }

    i = start
    while (i <= end && end - i + 1 >= r - index) {
        data[index] = arr[i]
        combinationUtil(arr, data, i + 1,
            end, index + 1, r)
        i += 1
    }
}

arr = [...Array(15).keys()]

n = arr.length

console.log(arr)
arr.forEach((val, r, array) => {
    printCombination(arr, n, r)
})

//print final to see the full combination list generated
final.forEach((a) => {

    [...a].forEach((idx) => {
        console.log("char", idx)
        pageObject.selectCheckbox(idx)
    })

    pageObject.verify("Message")


})

This will text all 15 combination ( Order ignored and no duplicates)

credit :

https://www.geeksforgeeks.org/print-all-possible-combinations-of-r-elements-in-a-given-array-of-size-n/

4
  • Thank you that seems helpful. I will try it and get back to you. Jan 21, 2021 at 17:15
  • @PDhide, are you suggesting to test 225 checkbox combinations one by one and verifying label in UI? Do you think its correct & efficient approach? Feb 7, 2021 at 11:27
  • @VishalAggarwal its an exhaustive approach if its that the user wants
    – PDHide
    Feb 7, 2021 at 11:28
  • Any automation purely reflects the quality of manual process its automating. Garbage in garbage out. Feb 7, 2021 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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