WebDriver 1

4 Jan

This ‘Selenium 2 Webdriver Basics With Java’ class is turning into my day job.

AND I LOVE MY JOB!

Really, this is more fun (and aggravation, but the fun kind) than I’ve had in a while. The fun comes, of course, from the process of exceeding my own expectations for myself. I’m learning things about Java now (little things, but big to a newbie like me) that I was turning away from in fear just a little while ago. Throwing exceptions, casting URL objects to strings in one method and then using those strings in other methods and that sort of thing.

The exercise I’ve been working on today involves just some basic navigation using WebDriver and some very basic title validation. I completed the exercise last night and was pretty proud of my efforts, only to find with this morning’s lecture (a 5 minute lecture at that) that I had left some avenues unexplored and was about to learn some new tricks to make my code more flexible and easier to read. I’ve been working all morning to apply the ideas he touched on and things are coming along very nicely. Had to deal with a run-time exception for the first time which was a bit of an adventure in hair-pulling for a while. I had set some static string variables inside the parent class to be shared amongst the methods, and then used the JUnit @BeforeClass method to build some URL’s and cast them as strings to the variables.

Fine.

Problem was, I had put the word ‘String’ in front of each variable in the method, when they had already been declared as Strings at the class level. Shenanigans and lots of pretty red text ensued.

Finally caught the mistake and am now basking warmly in the limelight of my own perfection with a hot cup of tea. (I know, tea while I’m studying Java? Yeesh.)

One more step to refine, however. One page that the instructor has us checking (and refreshing) changes (a 10 digit number in) it’s title with each refresh. I had that covered with a regular expression:

title.matches("Refreshed Page on [0-9]{10}")

But no, Mister Instructor Dude had to take it further. WAAAY further, by my reckoning at least.

You see, the number in the title changes because the number is not random (as I had, conveniently for me, assumed), but rather is a time stamp. He uses a bit of fancy (to me) code wrangling to tease out the time stamp data, cast it to a long variable, wait a couple seconds, cast the current time stamp to another variable and then top it all off with a JUnit assertTrue statement that passes only if the end time is greater than the start time.

No big deal of course to even a moderate code jockey, but it all makes my brain buzz (in a good way) to take it all in and make it work myself.

Like my mom used to say, (sing, actually) “Stretch and grow, reach for the stars…”

And like the proverbial 4 year old kid with his thumb in his mouth, a blanket, and his favorite (worn, but much-loved) USB mouse dragging behind him, that’s exactly what I’m doing.

Maybe I’ll post the code later for others to admire and comment their deep thoughts thereupon. I’ll have to post the instructor’s code too, then, just to prove I’m not a mindless armpit-scratching copy-paste-monkey.

Advertisements

Comments are welcome!

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: