Tag Archives: assertion

Joining multiple for loops in Python with ‘chain’ for repeating the same check for multiple groups of indexes

I will start with an example: say you have a page table with 2 columns. You want to check, in your UI testing, that the values in the second column are the expected ones. By looking at the table you see that the first 2 and the last 5 values are the same. You have to iterate the table values to compare to the expected ones, but what is the simplest way to do this? You could use 2 for loops to check for those identical values, but you would just be repeating the code inside those for loops, as you would be writing the exact same checks. Even if it’s calling a separate method, it would still be a code repeat. Let me exemplify solving this situation using ‘chained’ for loops. Continue reading Joining multiple for loops in Python with ‘chain’ for repeating the same check for multiple groups of indexes