within .spec file, check if element exists, and only then run test

399 views
Skip to first unread message

davidbrya...@gmail.com

unread,
Feb 23, 2016, 9:10:33 PM2/23/16
to Galen Framework
I know there is condition-based timeout  like this:

wait 1m until exist "css: span.error"

I have several of those included in my .test file to wait for certain elements to load before doing a check

is there a way to not run a test or set of tests — from within a .spec file if an element does not exist at all on a page?

for instance, I have the code below mixed in with a bunch of other .spec tests:

@objects
    task
-block  css .TaskBlock

= Section 3. Task block =
   
@on *
      task
-block:
          css margin
-top is "${correction(80)}"

I'm running my test across a wide variety of web pages, but the "task-block" element only exists on a limited number of those pages, so I frequently get errors like the following when I run my tests via gulp in command line (or in my HTML reports):

->      :   "task-block" is absent on page

what I would like is if I could do a quick check whether "task-block" exists from within the .spec file.  if it does, continue with that particular test (css margin-top, in this example).  if not, then skip that test.

I imagine creating a variable for "task-block" and passing that to an external JS script that determines whether to run that particular test in the .spec file, but I'm not sure how the round trip back to the .spec file would work, wrapping in the .spec test in question in {} marks, for instance.  the reason I think of externalizing it into an external JS file is so that I don't have to include the IF/THEN a hundred times throughout my .spec tests, it would just be a variable for each element in question passed that would trigger some sort of IF/THEN function. 

even more so, I'm hoping there's something already built into Galen (with indentation or something) to pull this off.

thank you.  


davidbrya...@gmail.com

unread,
Feb 24, 2016, 6:44:02 PM2/24/16
to Galen Framework
Think I've answered my own question by going back through documentation yet again:

http://galenframework.com/docs/reference-galen-spec-language-guide/#ifStatement

= Banners = 
    @if ${isVisible("banner-1")}
        banner-1:
           
width 300 px
           
height 100 px

Seems to be exactly what I need, to avoid running tests (and getting errors) for certain elements when a large number of pages are tested, most of which do include those elements, but several do not.

I'm loving Galen thus far, btw!
Reply all
Reply to author
Forward
0 new messages