Wednesday, October 8, 2014

Node.js tips-1, put your configuration in a special .json module, selenium webdriver

if you use node selenium-webdriver to do a basic UI test, here is a quick sample code to open google, enter the keyword and do the serach, then validate the title. https://www.npmjs.org/package/selenium-webdriver

image

if you check the code here, a lot hard coding, bot the url and title are hardcoded here. to prevent this, we can create a json file, put the configuration there. and save it as a .json file.
image

then in the json file, put a require module there, and we can use it directly. no parsing needed.
image

after this, run again, make sure we never break any logic.  can we still improve it?

image

we have to key in the whole helper method webdriver.By.name, let’s improve it. create another module called makenameselector.js

image

now in the test.js , we can promote the selector string to nameselctors.

image

then no more hardcoding, no more duplicate webdriver.By.name

No comments:

 
Locations of visitors to this page