Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FirefoxDriver driver = new FirefoxDriver();
- InternetExplorerDriver driver = new InternetExplorerDriver();
- ChromeDriver driver = new ChromeDriver();
- //Define the interface with the common methods
- Interface ISuperDriver
- {
- void run();
- }
- //implement the interface on firefox
- class FireFoxDriver:ISuperDriver{
- void run(){
- //firefox driver
- }
- }
- //implement the interface on IE
- class InternetExplorerDriver:ISuperDriver{
- void run(){
- //ie driver
- }
- }
- //chrome
- class ChromeDriver:ISuperDriver{
- void run(){
- //chrome
- }
- }
- //create reference for the interface
- ISuperDriver Driver;
- if(<input 1>){
- Driver= new FireFoxDriver();}//instantiate firefox
- else if(<input 2>){
- Driver= new InternetExplorerDriver();}//IE
- else if(<input 3>){
- Driver= new ChromeDriver();}//Chrome
- //Finally invoke your method
- Driver.Run();
- public abstract class Browser {
- public abstract Navigate(string link);
- }
- public class Firefox : Browser {
- FirefoxDriver driver;
- public Firefox(){
- driver = new FirefoxDriver();
- }
- public abstract Navigate(string link){
- driver.GoTo(link);
- }
- }
- public class Chrome : Browser {
- ChromeDriver driver;
- public Chrome (){
- driver = new ChromeDriver();
- }
- public abstract Navigate(string link){
- driver.FollowLink(link);
- }
- }
- public abstract class BrowserDriver { ... }
- public class InternetExplorerDriver : BrowserDriver { ... }
- public class FirefoxDriver : BrowserDriver { ... }
- public class ChromeDriver : BrowserDriver { ... }
- BrowserDriver driver = null;
- switch (BrowserType) // assuming BrowserType is a property of type Browser enum, holding the value from the set {InternetExplorer, Firefox, Chrome}
- {
- case Browser.InternetExplorer:
- driver = new InternetExplorerDriver();
- break;
- case Browser.Firefox:
- driver = new FirefoxDriver();
- break;
- case Browser.Chrome:
- driver = new ChromeDriver();
- break;
- }
- SomeFunction(driver);
- // ...
- public void SomeFunction(BrowserDriver driver)
- {
- //... your code here
- }
Add Comment
Please, Sign In to add comment