1package com.oracle.framework;23import java.nio.file.WatchEvent.Kind;4import java.util.List;5import java.util.Set;67import org.openqa.selenium.By;8import org.openqa.selenium.Capabilities;9import org.openqa.selenium.HasCapabilities;10import org.openqa.selenium.JavascriptExecutor;11import org.openqa.selenium.OutputType;12import org.openqa.selenium.Platform;13import org.openqa.selenium.TakesScreenshot;14import org.openqa.selenium.WebDriver;15import org.openqa.selenium.WebDriverException;16import org.openqa.selenium.WebElement;17import org.openqa.selenium.chrome.ChromeDriver;18import org.openqa.selenium.chrome.ChromeOptions;19import org.openqa.selenium.firefox.FirefoxDriver;20import org.openqa.selenium.ie.InternetExplorerDriver;21import org.openqa.selenium.interactions.HasInputDevices;22import org.openqa.selenium.interactions.Keyboard;23import org.openqa.selenium.interactions.Mouse;24import org.openqa.selenium.internal.FindsByClassName;25import org.openqa.selenium.internal.FindsByCssSelector;26import org.openqa.selenium.internal.FindsById;27import org.openqa.selenium.internal.FindsByLinkText;28import org.openqa.selenium.internal.FindsByName;29import org.openqa.selenium.internal.FindsByTagName;30import org.openqa.selenium.internal.FindsByXPath;31import org.openqa.selenium.remote.DesiredCapabilities;32import org.openqa.selenium.support.events.EventFiringWebDriver;3334import com.google.common.hash.HashingInputStream;3536public class WrappedWebDriver implements WebDriver,JavascriptExecutor,FindsById,FindsByClassName,FindsByCssSelector,FindsByLinkText,FindsByName,FindsByTagName,FindsByXPath,HasCapabilities,HasInputDevices,TakesScreenshot37{3839 40 41 private WebDriver WebDriver;42 EventFiringWebDriver driver ;43 EnvDetails envDetails;44 String browser;45 public WrappedWebDriver()46 {47 envDetails=Config.getEnvDetails();48 browser=envDetails.getBrowser();49 try50 {51 if (browser.equalsIgnoreCase("Chrome"))52 {53 ChromeOptions options = new ChromeOptions(); 54 options.addArguments("disable-infobars"); 55 // options.addArguments("chrome.switches","--disable-extensions");56// DesiredCapabilities capabilities=DesiredCapabilities.chrome();57// capabilities.setBrowserName(browser);58// capabilities.setPlatform(Platform.WINDOWS);59// capabilities.setCapability(ChromeOptions.CAPABILITY, options);60 System.out.println(System.getProperty("user.dir")+"/drivers/chromedriver.exe");61 System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"//drivers//chromedriver.exe");62 // driver=new ChromeDriver(options);63 WebDriver=new ChromeDriver(options);64 65 }66 else if (browser.equalsIgnoreCase("Firefox")) 67 {68 System.out.println(System.getProperty("user.dir")+"/drivers/geckodriver.exe");69 System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"//drivers//geckodriver.exe");70// DesiredCapabilities caps = DesiredCapabilities.firefox();71// caps.setBrowserName("firefox");72// caps.setPlatform(Platform.WINDOWS); 73 WebDriver = new FirefoxDriver(); 74 }75 else if (browser.equalsIgnoreCase("IE")) 76 {77 //Set Desired Capabilities78 DesiredCapabilities caps = DesiredCapabilities.internetExplorer();79 caps.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);80 caps.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false);81 caps.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, false);82 caps.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);83 caps.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);84 caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);85 86 System.setProperty("webdriver.ie.driver", System.getProperty("user.dir")+"//drivers//IEDriverServer.exe");87 WebDriver=new InternetExplorerDriver(caps);88 }89 driver=new EventFiringWebDriver(WebDriver);90 WrappedWebDriverEventListener eventListener=new WrappedWebDriverEventListener();91 driver.register(eventListener); 92 }93 catch(Exception e)94 {95 Report.log(Status.Fail, "Failed while loading driver");96 }97 98 }99 100 101 102 public void get(String url) {103 // TODO Auto-generated method stub104 driver.get(url);105 }106107 public String getCurrentUrl()108 {109 // TODO Auto-generated method stub110 return driver.getCurrentUrl();111 }112113 public String getTitle() {114 // TODO Auto-generated method stub115 return driver.getTitle();116 }117118 public List<WebElement> findElements(By by) {119 // TODO Auto-generated method stub120 return driver.findElements(by);121 }122123 public WebElement findElement(By by) {124 // TODO Auto-generated method stub125 return driver.findElement(by);126 }127128 public String getPageSource() {129 // TODO Auto-generated method stub130 return driver.getPageSource();131 }132133 public void close() {134 // TODO Auto-generated method stub135 driver.close();136 }137138 public void quit() {139 // TODO Auto-generated method stub140 driver.quit();141 }142143 public Set<String> getWindowHandles() {144 // TODO Auto-generated method stub145 return driver.getWindowHandles();146 }147148 public String getWindowHandle() {149 // TODO Auto-generated method stub150 return driver.getWindowHandle();151 }152153 public TargetLocator switchTo() {154 // TODO Auto-generated method stub155 return driver.switchTo();156 }157158 public Navigation navigate() {159 // TODO Auto-generated method stub160 return driver.navigate();161 }162163 public Options manage() {164 // TODO Auto-generated method stub165 return driver.manage();166 }167168 public Object executeScript(String script, Object... args) {169 // TODO Auto-generated method stub170 return ((JavascriptExecutor)driver).executeScript(script, args);171 }172173 public Object executeAsyncScript(String script, Object... args) {174 // TODO Auto-generated method stub175 return ((JavascriptExecutor)driver).executeAsyncScript(script, args);176 }177178 public WebElement findElementById(String using) {179 // TODO Auto-generated method stub180 return driver.findElement(By.id(using));181 }182183 public List<WebElement> findElementsById(String using) {184 // TODO Auto-generated method stub185 return driver.findElements(By.id(using));186 }187188 public WebElement findElementByXPath(String using) {189 // TODO Auto-generated method stub190 return driver.findElement(By.xpath(using));191 }192193 public List<WebElement> findElementsByXPath(String using) {194 // TODO Auto-generated method stub195 return driver.findElements(By.xpath(using));196 }197198 public WebElement findElementByTagName(String using) {199 // TODO Auto-generated method stub200 return driver.findElement(By.tagName(using));201 }202203 public List<WebElement> findElementsByTagName(String using) {204 // TODO Auto-generated method stub205 return driver.findElements(By.tagName(using));206 }207208 public WebElement findElementByName(String using) {209 // TODO Auto-generated method stub210 return driver.findElement(By.name(using));211 }212213 public List<WebElement> findElementsByName(String using) {214 // TODO Auto-generated method stub215 return driver.findElements(By.name(using));216 }217218 public WebElement findElementByLinkText(String using) {219 // TODO Auto-generated method stub220 return driver.findElement(By.linkText(using));221 }222223 public List<WebElement> findElementsByLinkText(String using) {224 // TODO Auto-generated method stub225 return driver.findElements(By.linkText(using));226 }227228 public WebElement findElementByPartialLinkText(String using) {229 // TODO Auto-generated method stub230 return driver.findElement(By.partialLinkText(using));231 }232233 public List<WebElement> findElementsByPartialLinkText(String using) {234 // TODO Auto-generated method stub235 return driver.findElements(By.partialLinkText(using));236 }237238 public WebElement findElementByCssSelector(String using) {239 // TODO Auto-generated method stub240 return driver.findElement(By.cssSelector(using));241 }242243 public List<WebElement> findElementsByCssSelector(String using) {244 // TODO Auto-generated method stub245 return driver.findElements(By.cssSelector(using));246 }247248 public WebElement findElementByClassName(String using) {249 // TODO Auto-generated method stub250 return driver.findElement(By.className(using));251 }252253 public List<WebElement> findElementsByClassName(String using) {254 // TODO Auto-generated method stub255 return driver.findElements(By.className(using));256 }257258 public Capabilities getCapabilities() {259 // TODO Auto-generated method stub260 HasCapabilities capabilities=null;261 capabilities=(HasCapabilities)driver;262 return capabilities.getCapabilities();263 }264265 public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {266 // TODO Auto-generated method stub267 TakesScreenshot screenShot=(TakesScreenshot)driver;268 return screenShot.getScreenshotAs(target);269 }270271 public Keyboard getKeyboard() {272 // TODO Auto-generated method stub273 return ((HasInputDevices)driver).getKeyboard();274 }275276 public Mouse getMouse() {277 // TODO Auto-generated method stub278 return ((HasInputDevices)driver).getMouse();279 }280281}
...