Please suggest how can pass the the Switch case Condition with IF Statement
baseclass.java
class Baseclass {
public static WebDriver driver;
public void GetDriver(int browserId) {
{
switch (browserId) {
case 1:
// For Firefox Driver
driver = new FirefoxDriver();
break;
case 2:
// For Chrome Driver
System.setProperty("webdriver.chrome.driver",
"D:\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
break;
case 3:
// For IE Driver
System.setProperty("webdriver.ie.driver",
"D:\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
}
}
}
}
another class i have inherit the base class and set the condition
public class AdminRenewals extends Baseclass {
@BeforeTest
public final void Startup() {
Baseclass ed = new Baseclass();
ed.GetDriver(3);
}
}
from the AdminRenewals class how can we check the switch case condition with another method
sonething like
if(GetDriver==2)
{
if (!name1.equals("")) {
name1 = new StringBuffer(name1).insert(name1.length() - 1, " ")
.toString();
if(GetDriver==3)
{
if (!name1.equals("")) {
name1 = new StringBuffer(name1).insert(name1.length() - 1, "test ")
.toString();
Expected: if i use the chrome driver its should be execute that particular if condition (based on switch case)
Try something like this:
if(Baseclass.driver instanceof FirefoxDriver)
{
...
}
if(Baseclass.driver instanceof ChromeDriver)
{
...
}
etc.
Using instanceof
, you can determine which type of WebDriver
was created and assigned to driver
.
Learn more about instanceof here!
(Your question wasn't very clear, so I believe this is what you were asking, but if it isn't then comment below with more info and I will update my answer)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.