Guest User

Untitled

a guest
Jan 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. FirefoxDriver driver = new FirefoxDriver();
  2. InternetExplorerDriver driver = new InternetExplorerDriver();
  3. ChromeDriver driver = new ChromeDriver();
  4.  
  5. //Define the interface with the common methods
  6. Interface ISuperDriver
  7. {
  8. void run();
  9. }
  10.  
  11. //implement the interface on firefox
  12. class FireFoxDriver:ISuperDriver{
  13. void run(){
  14. //firefox driver
  15. }
  16. }
  17.  
  18. //implement the interface on IE
  19. class InternetExplorerDriver:ISuperDriver{
  20. void run(){
  21. //ie driver
  22. }
  23. }
  24.  
  25. //chrome
  26. class ChromeDriver:ISuperDriver{
  27. void run(){
  28. //chrome
  29. }
  30. }
  31.  
  32. //create reference for the interface
  33. ISuperDriver Driver;
  34.  
  35. if(<input 1>){
  36. Driver= new FireFoxDriver();}//instantiate firefox
  37. else if(<input 2>){
  38. Driver= new InternetExplorerDriver();}//IE
  39. else if(<input 3>){
  40. Driver= new ChromeDriver();}//Chrome
  41.  
  42. //Finally invoke your method
  43. Driver.Run();
  44.  
  45. public abstract class Browser {
  46. public abstract Navigate(string link);
  47. }
  48.  
  49. public class Firefox : Browser {
  50. FirefoxDriver driver;
  51. public Firefox(){
  52. driver = new FirefoxDriver();
  53. }
  54.  
  55. public abstract Navigate(string link){
  56. driver.GoTo(link);
  57. }
  58. }
  59.  
  60. public class Chrome : Browser {
  61. ChromeDriver driver;
  62. public Chrome (){
  63. driver = new ChromeDriver();
  64. }
  65.  
  66. public abstract Navigate(string link){
  67. driver.FollowLink(link);
  68. }
  69. }
  70.  
  71. public abstract class BrowserDriver { ... }
  72.  
  73. public class InternetExplorerDriver : BrowserDriver { ... }
  74. public class FirefoxDriver : BrowserDriver { ... }
  75. public class ChromeDriver : BrowserDriver { ... }
  76.  
  77. BrowserDriver driver = null;
  78.  
  79. switch (BrowserType) // assuming BrowserType is a property of type Browser enum, holding the value from the set {InternetExplorer, Firefox, Chrome}
  80. {
  81. case Browser.InternetExplorer:
  82. driver = new InternetExplorerDriver();
  83. break;
  84. case Browser.Firefox:
  85. driver = new FirefoxDriver();
  86. break;
  87. case Browser.Chrome:
  88. driver = new ChromeDriver();
  89. break;
  90. }
  91.  
  92. SomeFunction(driver);
  93.  
  94. // ...
  95.  
  96. public void SomeFunction(BrowserDriver driver)
  97. {
  98. //... your code here
  99. }
Add Comment
Please, Sign In to add comment