Base Test

mail@pastecode.io avatar
unknown
java
a year ago
1.8 kB
2
Indexable
package commons;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class BaseTest {
	private WebDriver driver;
	String projectPath = System.getProperty("user.dir");
	
	protected WebDriver getBrowserDriver(String BrowserName) {
		switch(BrowserName) {
		case "Firefox":
			System.setProperty("webdriver.gecko.driver", projectPath + "\\browsersDriver\\geckodriver.exe");
			//WebDriverManager.firefoxdriver().setup();
			driver = new FirefoxDriver();
		case "Chrome":
			System.setProperty("webdriver.chrome.driver", projectPath + "\\browsersDriver\\chromedriver.exe");
			//WebDriverManager.chromedriver().setup();
			driver = new ChromeDriver();
			break;
		
		default:
		    throw new RuntimeException("Please enter the correct BrowserName");
		}
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		driver.get("https://demo.nopcommerce.com/");
		return driver;
	}
	
	protected WebDriver getBrowserDriver(String BrowserName, String url) {
		switch(BrowserName) {
		case "Firefox":
			System.setProperty("webdriver.gecko.driver", projectPath + "\\browsersDriver\\geckodriver.exe");
			//WebDriverManager.firefoxdriver().setup();
			driver = new FirefoxDriver();
		case "Chrome":
			System.setProperty("webdriver.chrome.driver", projectPath + "\\browsersDriver\\chromedriver.exe");
			//WebDriverManager.chromedriver().setup();
			driver = new ChromeDriver();
			break;
		
		default:
		    throw new RuntimeException("Please enter the correct BrowserName");
		}
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		driver.get(url);
		return driver;
	}

}