ServiceNow Selenium Tests – The Left Nav

In every other post I’ve done regarding Selenium testing in ServiceNow, my tests have all left the navigation pane (or Left Nav) out of the tests.  Everything gets the page via table name and a query parameter, or the direct sys_id.  From my original point of view, this is all I need my tests to do: fill out forms, check mandatory fields, make sure the record state flows properly.  But some may want more of the user experience for their tests.  Or maybe you’re like me and you want to make sure filters from the left nav are working properly.  So, I’ve got a quick way to generate a left nav page object, and some quick instructions on how to use it.

The Script

I created a script include that goes with the other Selenium scripts I’ve created in the past.  Just add it to your instance, initialize with a language, and call the process function.  Now you have a LeftNav page object class!


Using The Navigation Class

Just like with our other pages, this is a page object that we can instantiate with the PageFactory.initElements function.  Add that to a test setup.  The trick with using the left nav is to switch frames with driver.switchTo().


Adding the switchTo().defaultContent() prevents the code from breaking.  The driver has trouble finding gsft_main from gsft_nav.  Thanks, iFrames!

The next trick to make this work is ensuring the objects are going to be clickable.  If you ever look under the hood at the Collapse All/Expand All in the left nav options, you’ll see there’s some javascript at work.  Cool, we can use that in Selenium.

As I said earlier, I’m using this mainly to ensure bread crumbs are what they are supposed to be.  To aid this process, I created a LeftNavFilter class, which just holds data about a module element, the table it’s for, and it’s expected breadcrumb text.  That way I can quickly iterate through clicking a link, getting it’s text, and ensuring it’s correct.

I’ve updated the repo with a brief example.  Note, the left nav class in the repo is very abbreviated.  It’s likely going to have 1000+ lines thanks to all the left nav elements.  Now, one thing I considered is doing the navigation by role and having them extend each other (ie: LeftNav, LeftNavEss, LeftNavItil, LeftNavAdmin).  I may do that over Black Friday.

For now, this is meeting my needs well.  These tests are really simple and fast to write.  They should be good as long as you’re on UI15 or older.  Have fun with it!


One thought on “ServiceNow Selenium Tests – The Left Nav

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s