Monday, June 9, 2014

Automation test using regexp


Here I have a scenario outline. I will be testing the store finder mileage accuracy when displaying results of stores starting with the closest regardless of zip code entered.




I created a Ruby File named env.rb in a Support Folder where I set as default @Browser.close to close scenarios after tests are ran for more test efficiency, and to translate the commands of the test I require the following gems:




Given.
In my_steps.rb
I open fire fox browser, and i tell it to go "guitarcenter.com"  by using watir-webdriver commands.





When.
On the website i located the link for the Store Finder and click it.
Once the pop up appears I located the text_field to input zip code, named sszipCode (found with fire bug) and with method .wait_until_present, as definition it waited to be present.
The text field has been located, now i entered the zip code value in such with method .set "#{zipcode}"
With that set, i go ahead and locate the search button and click on it to give me results.



If i run this test with only one example of my scenario outline i should get...
1 scenario (1 failed)
3 steps (2 passed, 1 undefined)

everything looks good so far, now lets define our last step. Here is when it gets a little difficult; i personally needed some assistance from my instructor and mentor Brian Warner (SDET)

Then.
In this step the idea is to factor out the miles from each store listed, and compare it to each other to know if the first store listed is closer to your zip code than the second store, and so on...
I'm going to cut Then into 3 screenshots to explain the solution
Here is how we did it using regx


After clicking the search button on our previous step it gave us results...
On this step I waited for searchResultlist to appear before we proceed with regx.
We're looking to factor out the first store location to do so

1st.
We created a variable named first_store_location = the text where the miles are located in the first li result, and puts first_store_location to see what we get... this is the string we show after running the test
"San Bernardino (6.75 mi)"
Good! We have factored out the city and the miles of first store.
We just need the miles!
So we created a variable for the miles and we called it miles_of_first_store = /the format below that expresses the way the miles are written/.match(first_store_location variable), and puts miles_of_first_store to confirm the output
Great! we extracted out "6.75"

1/3


2nd.
Same as first store, but now we were looking for miles of second store, so we created new variables and changed the .li(:index=>1 to spot the second store location, then after factor out only the miles.

2/3


3rd.
We had to strings: miles_of_first_store and miles_of_second_store. We just had to turn these strings into decimals with method .to_f to prove the equation
We could have simply done assert miles_of_first_store.to_f  <  miles_of_second_store.to_f
Wrong! We encountered a problem and the only way to pass this assertion. It was to force a string into a string by creating variables that would equal the value of the original variables used to define the miles of the two stores and then do the assertion shown below.
I ran the test; the test passed. When i flipped the < > signs; the test failed.
Then we knew we a had a legit automation test.
3/3