there should be just one websriver.build in this class, define caapbility object in your if else condition, and then just pass it to webdriver.build