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
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.
then in the json file, put a require module there, and we can use it directly. no parsing needed.
after this, run again, make sure we never break any logic. can we still improve it?
we have to key in the whole helper method webdriver.By.name, let’s improve it. create another module called makenameselector.js
now in the test.js , we can promote the selector string to nameselctors.
then no more hardcoding, no more duplicate webdriver.By.name
No comments:
Post a Comment