Here is the updated version using individual browser selection:
@When("^I check if the user has a \"([^\"]*)\" linked account$")
public void linkChecker(String socialLoginXpathNotLinked) throws Throwable {
driverWait = new WebDriverWait(driver, 20);
driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(socialLoginXpathNotLinked)));
driverElement = driver.findElement(By.xpath(socialLoginXpathNotLinked));
if(!driverElement.isDisplayed())
{
isLinked = true;
}
}
@Then("^I unlink user if \"([^\"]*)\" linked$")
public void unlinkUser(String socialLoginXpathLinked) throws Throwable {
if(isLinked)
{
driver.findElement(By.xpath(socialLoginXpathLinked)).click();
isLinked = false;
}
}
And where I call my browser initialization which is what JeffC recommended:
@Given("^I use \"([^\"]*)\" browser$")
public void browserInitialization(String browser) throws Throwable {
if (browser.equals("Chrome"))
{
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
driver = new ChromeDriver();
}
else if(browser.equals("Firefox"))
{
System.setProperty("webdriver.gecko.driver", "C:\\Program Files (x86)\\Mozilla Firefox\\geckodriver.exe");
driver = new FirefoxDriver();
}
else if(browser.equals("Edge"))
{
System.setProperty("webdriver.edge.driver", "C:\\Program Files (x86)\\Edge Driver\\MicrosoftWebDriver.exe");
driver = new EdgeDriver();
}
else if(browser.equals("IE11"))
{
System.setProperty("webdriver.ie.driver", "C:\\Program Files (x86)\\Internet Explorer\\IEDriverServer32.exe");
driver = new InternetExplorerDriver();
}
}
And on the cucumber side I use a scenario outline I just use a data table for browser grabbing:
|Browser|
|Chrome|
|FireFox|
|Edge|
|IE11|