How to use Either class of org.openqa.selenium.internal package

Best Selenium code snippet using org.openqa.selenium.internal.Either

Source:WebDriverCommandProcessor.java Github

copy

Full Screen

1/*2Copyright 2007-2009 WebDriver committers3Copyright 2007-2009 Google Inc.45Licensed under the Apache License, Version 2.0 (the "License");6you may not use this file except in compliance with the License.7You may obtain a copy of the License at89 http://www.apache.org/licenses/LICENSE-2.01011Unless required by applicable law or agreed to in writing, software12distributed under the License is distributed on an "AS IS" BASIS,13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14See the License for the specific language governing permissions and15limitations under the License.16*/1718package org.openqa.selenium;1920import com.google.common.base.Supplier;21import com.google.common.collect.Maps;2223import com.thoughtworks.selenium.CommandProcessor;24import com.thoughtworks.selenium.SeleniumException;2526import org.openqa.selenium.internal.WrapsDriver;27import org.openqa.selenium.internal.seleniumemulation.AddLocationStrategy;28import org.openqa.selenium.internal.seleniumemulation.AddSelection;29import org.openqa.selenium.internal.seleniumemulation.AlertOverride;30import org.openqa.selenium.internal.seleniumemulation.AltKeyDown;31import org.openqa.selenium.internal.seleniumemulation.AltKeyUp;32import org.openqa.selenium.internal.seleniumemulation.AssignId;33import org.openqa.selenium.internal.seleniumemulation.AttachFile;34import org.openqa.selenium.internal.seleniumemulation.CaptureScreenshotToString;35import org.openqa.selenium.internal.seleniumemulation.Check;36import org.openqa.selenium.internal.seleniumemulation.Click;37import org.openqa.selenium.internal.seleniumemulation.Close;38import org.openqa.selenium.internal.seleniumemulation.CompoundMutator;39import org.openqa.selenium.internal.seleniumemulation.ControlKeyDown;40import org.openqa.selenium.internal.seleniumemulation.ControlKeyUp;41import org.openqa.selenium.internal.seleniumemulation.CreateCookie;42import org.openqa.selenium.internal.seleniumemulation.DeleteAllVisibleCookies;43import org.openqa.selenium.internal.seleniumemulation.DeleteCookie;44import org.openqa.selenium.internal.seleniumemulation.DoubleClick;45import org.openqa.selenium.internal.seleniumemulation.DragAndDrop;46import org.openqa.selenium.internal.seleniumemulation.DragAndDropToObject;47import org.openqa.selenium.internal.seleniumemulation.ElementFinder;48import org.openqa.selenium.internal.seleniumemulation.FindFirstSelectedOptionProperty;49import org.openqa.selenium.internal.seleniumemulation.FindSelectedOptionProperties;50import org.openqa.selenium.internal.seleniumemulation.FireEvent;51import org.openqa.selenium.internal.seleniumemulation.FireNamedEvent;52import org.openqa.selenium.internal.seleniumemulation.GetAlert;53import org.openqa.selenium.internal.seleniumemulation.GetAllButtons;54import org.openqa.selenium.internal.seleniumemulation.GetAllFields;55import org.openqa.selenium.internal.seleniumemulation.GetAllLinks;56import org.openqa.selenium.internal.seleniumemulation.GetAllWindowTitles;57import org.openqa.selenium.internal.seleniumemulation.GetAttribute;58import org.openqa.selenium.internal.seleniumemulation.GetAttributeFromAllWindows;59import org.openqa.selenium.internal.seleniumemulation.GetBodyText;60import org.openqa.selenium.internal.seleniumemulation.GetConfirmation;61import org.openqa.selenium.internal.seleniumemulation.GetCookie;62import org.openqa.selenium.internal.seleniumemulation.GetCookieByName;63import org.openqa.selenium.internal.seleniumemulation.GetElementHeight;64import org.openqa.selenium.internal.seleniumemulation.GetElementIndex;65import org.openqa.selenium.internal.seleniumemulation.GetElementPositionLeft;66import org.openqa.selenium.internal.seleniumemulation.GetElementPositionTop;67import org.openqa.selenium.internal.seleniumemulation.GetElementWidth;68import org.openqa.selenium.internal.seleniumemulation.GetEval;69import org.openqa.selenium.internal.seleniumemulation.GetExpression;70import org.openqa.selenium.internal.seleniumemulation.GetHtmlSource;71import org.openqa.selenium.internal.seleniumemulation.GetLocation;72import org.openqa.selenium.internal.seleniumemulation.GetSelectOptions;73import org.openqa.selenium.internal.seleniumemulation.GetTable;74import org.openqa.selenium.internal.seleniumemulation.GetText;75import org.openqa.selenium.internal.seleniumemulation.GetTitle;76import org.openqa.selenium.internal.seleniumemulation.GetValue;77import org.openqa.selenium.internal.seleniumemulation.GetXpathCount;78import org.openqa.selenium.internal.seleniumemulation.GoBack;79import org.openqa.selenium.internal.seleniumemulation.Highlight;80import org.openqa.selenium.internal.seleniumemulation.IsAlertPresent;81import org.openqa.selenium.internal.seleniumemulation.IsChecked;82import org.openqa.selenium.internal.seleniumemulation.IsConfirmationPresent;83import org.openqa.selenium.internal.seleniumemulation.IsCookiePresent;84import org.openqa.selenium.internal.seleniumemulation.IsEditable;85import org.openqa.selenium.internal.seleniumemulation.IsElementPresent;86import org.openqa.selenium.internal.seleniumemulation.IsOrdered;87import org.openqa.selenium.internal.seleniumemulation.IsSomethingSelected;88import org.openqa.selenium.internal.seleniumemulation.IsTextPresent;89import org.openqa.selenium.internal.seleniumemulation.IsVisible;90import org.openqa.selenium.internal.seleniumemulation.JavascriptLibrary;91import org.openqa.selenium.internal.seleniumemulation.KeyEvent;92import org.openqa.selenium.internal.seleniumemulation.KeyState;93import org.openqa.selenium.internal.seleniumemulation.MetaKeyDown;94import org.openqa.selenium.internal.seleniumemulation.MetaKeyUp;95import org.openqa.selenium.internal.seleniumemulation.MouseEvent;96import org.openqa.selenium.internal.seleniumemulation.MouseEventAt;97import org.openqa.selenium.internal.seleniumemulation.NoOp;98import org.openqa.selenium.internal.seleniumemulation.Open;99import org.openqa.selenium.internal.seleniumemulation.OpenWindow;100import org.openqa.selenium.internal.seleniumemulation.Refresh;101import org.openqa.selenium.internal.seleniumemulation.RemoveAllSelections;102import org.openqa.selenium.internal.seleniumemulation.RemoveSelection;103import org.openqa.selenium.internal.seleniumemulation.RunScript;104import org.openqa.selenium.internal.seleniumemulation.ScriptMutator;105import org.openqa.selenium.internal.seleniumemulation.SelectFrame;106import org.openqa.selenium.internal.seleniumemulation.SelectOption;107import org.openqa.selenium.internal.seleniumemulation.SelectWindow;108import org.openqa.selenium.internal.seleniumemulation.SeleneseCommand;109import org.openqa.selenium.internal.seleniumemulation.SetNextConfirmationState;110import org.openqa.selenium.internal.seleniumemulation.SetTimeout;111import org.openqa.selenium.internal.seleniumemulation.ShiftKeyDown;112import org.openqa.selenium.internal.seleniumemulation.ShiftKeyUp;113import org.openqa.selenium.internal.seleniumemulation.Submit;114import org.openqa.selenium.internal.seleniumemulation.Timer;115import org.openqa.selenium.internal.seleniumemulation.Type;116import org.openqa.selenium.internal.seleniumemulation.TypeKeys;117import org.openqa.selenium.internal.seleniumemulation.Uncheck;118import org.openqa.selenium.internal.seleniumemulation.WaitForCondition;119import org.openqa.selenium.internal.seleniumemulation.WaitForPageToLoad;120import org.openqa.selenium.internal.seleniumemulation.WaitForPopup;121import org.openqa.selenium.internal.seleniumemulation.WindowFocus;122import org.openqa.selenium.internal.seleniumemulation.WindowMaximize;123import org.openqa.selenium.internal.seleniumemulation.Windows;124import org.openqa.selenium.remote.DesiredCapabilities;125126import java.util.Map;127128129/**130 * A CommandProcessor which delegates commands down to an underlying webdriver131 * instance.132 */133public class WebDriverCommandProcessor implements CommandProcessor, WrapsDriver {134 private final Map<String, SeleneseCommand<?>> seleneseMethods = Maps.newHashMap();135 private final String baseUrl;136 private final Timer timer;137 private final CompoundMutator scriptMutator;138 private Supplier<WebDriver> maker;139 private WebDriver driver;140141 /**142 * Create an instance that will later be configured by calling143 * {@link #start(Object)} with a {@link Capabilities}144 * instance.145 *146 * @param baseUrl The URL from which relative URLs should be based on147 */148 public WebDriverCommandProcessor(String baseUrl) {149 // Firefox seems like a reasonable default150 this(baseUrl, new SuppliesWebDriver(DesiredCapabilities.firefox()));151 }152153 /**154 * Create an instance that will later be started by calling155 * {@link #start()}156 *157 * @param baseUrl The URL from which relative URLs should be based on158 * @param likeThis Typically a {@link org.openqa.selenium.remote.DesiredCapabilities} instance159 */160 public WebDriverCommandProcessor(String baseUrl, Capabilities likeThis) {161 this(baseUrl, new SuppliesWebDriver(likeThis));162 }163164 public WebDriverCommandProcessor(String baseUrl, WebDriver driver) {165 this(baseUrl, new ExplodingSupplier());166 this.driver = driver;167168 assertDriverSupportsJavascript(driver);169170 setUpMethodMap();171 }172173 public WebDriverCommandProcessor(String baseUrl, Supplier<WebDriver> maker) {174 this.maker = maker;175176 if (baseUrl.endsWith("/")) {177 this.baseUrl = baseUrl.substring(0, baseUrl.length() - 1);178 } else {179 this.baseUrl = baseUrl;180 }181182 this.timer = new Timer(30000);183 this.scriptMutator = new CompoundMutator(baseUrl);184 }185186 public WebDriver getWrappedDriver() {187 return driver;188 }189190 public String getRemoteControlServerLocation() {191 throw new UnsupportedOperationException();192 }193194 public String doCommand(String commandName, String[] args) {195 Object val = execute(commandName, args);196 if (val == null) {197 return null;198 }199200 return val.toString();201 }202203 public void setExtensionJs(String s) {204 throw new UnsupportedOperationException();205 }206207 public void start() {208 start((Object) null);209 }210211 public void start(String s) {212 throw new UnsupportedOperationException("Unsure how to process: " + s);213 }214215 public void start(Object o) {216 if (driver != null) {217 throw new SeleniumException("You may not start more than one session at a time");218 }219220 driver = maker.get();221222 assertDriverSupportsJavascript(driver);223224 setUpMethodMap();225 }226227 public void stop() {228 timer.stop();229 if (driver != null) {230 driver.quit();231 }232 driver = null;233 }234235 public String getString(String commandName, String[] args) {236 return (String) execute(commandName, args);237 }238239 public String[] getStringArray(String commandName, String[] args) {240 return (String[]) execute(commandName, args);241 }242243 public Number getNumber(String commandName, String[] args) {244 return (Number) execute(commandName, args);245 }246247 public Number[] getNumberArray(String s, String[] strings) {248 throw new UnsupportedOperationException();249 }250251 public boolean getBoolean(String commandName, String[] args) {252 return (Boolean) execute(commandName, args);253 }254255 public boolean[] getBooleanArray(String s, String[] strings) {256 throw new UnsupportedOperationException();257 }258259 private Object execute(String commandName, final String[] args) {260 final SeleneseCommand<?> command = seleneseMethods.get(commandName);261 if (command == null) {262 throw new UnsupportedOperationException(commandName);263 }264265 return timer.run(command, driver, args);266 }267268 public void addMutator(ScriptMutator mutator) {269 scriptMutator.addMutator(mutator);270 }271272 public boolean isMethodAvailable(String methodName) {273 return seleneseMethods.containsKey(methodName);274 }275276 public void addMethod(String methodName, SeleneseCommand command) {277 seleneseMethods.put(methodName, command);278 }279280 public SeleneseCommand getMethod(String methodName) {281 return seleneseMethods.get(methodName);282 }283284 private void assertDriverSupportsJavascript(WebDriver driver) {285 // TODO(simon): We're starting to need a "describe" interface for checks286 // like this.287 if (!(driver instanceof JavascriptExecutor)) {288 throw new IllegalStateException("Driver instance must support JS.");289 }290291 if (!((JavascriptExecutor) driver).isJavascriptEnabled()) {292 throw new IllegalStateException("JS support must be enabled.");293 }294 }295296 private void setUpMethodMap() {297 JavascriptLibrary javascriptLibrary = new JavascriptLibrary();298 ElementFinder elementFinder = new ElementFinder(javascriptLibrary);299 KeyState keyState = new KeyState();300301 AlertOverride alertOverride = new AlertOverride();302 Windows windows = new Windows(driver);303304 // Note the we use the names used by the CommandProcessor305 seleneseMethods.put("addLocationStrategy", new AddLocationStrategy(elementFinder));306 seleneseMethods.put("addSelection", new AddSelection(javascriptLibrary, elementFinder));307 seleneseMethods.put("altKeyDown", new AltKeyDown(keyState));308 seleneseMethods.put("altKeyUp", new AltKeyUp(keyState));309 seleneseMethods.put("assignId", new AssignId(javascriptLibrary, elementFinder));310 seleneseMethods.put("attachFile", new AttachFile(elementFinder));311 seleneseMethods.put("captureScreenshotToString", new CaptureScreenshotToString());312 seleneseMethods.put("click", new Click(alertOverride, elementFinder));313 seleneseMethods.put("check", new Check(alertOverride, elementFinder));314 seleneseMethods.put("chooseCancelOnNextConfirmation", new SetNextConfirmationState(false));315 seleneseMethods.put("chooseOkOnNextConfirmation", new SetNextConfirmationState(true));316 seleneseMethods.put("close", new Close());317 seleneseMethods.put("createCookie", new CreateCookie());318 seleneseMethods.put("controlKeyDown", new ControlKeyDown(keyState));319 seleneseMethods.put("controlKeyUp", new ControlKeyUp(keyState));320 seleneseMethods.put("deleteAllVisibleCookies", new DeleteAllVisibleCookies());321 seleneseMethods.put("deleteCookie", new DeleteCookie());322 seleneseMethods.put("doubleClick", new DoubleClick(elementFinder));323 seleneseMethods.put("dragdrop", new DragAndDrop(elementFinder));324 seleneseMethods.put("dragAndDrop", new DragAndDrop(elementFinder));325 seleneseMethods.put("dragAndDropToObject", new DragAndDropToObject(elementFinder));326 seleneseMethods.put("fireEvent", new FireEvent(elementFinder, javascriptLibrary));327 seleneseMethods.put("focus", new FireNamedEvent(elementFinder, javascriptLibrary, "focus"));328 seleneseMethods.put("getAlert", new GetAlert(alertOverride));329 seleneseMethods.put("getAllButtons", new GetAllButtons());330 seleneseMethods.put("getAllFields", new GetAllFields());331 seleneseMethods.put("getAllLinks", new GetAllLinks());332 seleneseMethods.put("getAllWindowTitles", new GetAllWindowTitles());333 seleneseMethods.put("getAttribute", new GetAttribute(javascriptLibrary, elementFinder));334 seleneseMethods.put("getAttributeFromAllWindows", new GetAttributeFromAllWindows());335 seleneseMethods.put("getBodyText", new GetBodyText());336 seleneseMethods.put("getConfirmation", new GetConfirmation(alertOverride));337 seleneseMethods.put("getCookie", new GetCookie());338 seleneseMethods.put("getCookieByName", new GetCookieByName());339 seleneseMethods.put("getElementHeight", new GetElementHeight(elementFinder));340 seleneseMethods.put("getElementIndex", new GetElementIndex(elementFinder,341 javascriptLibrary));342 seleneseMethods.put("getElementPositionLeft", new GetElementPositionLeft(elementFinder));343 seleneseMethods.put("getElementPositionTop", new GetElementPositionTop(elementFinder));344 seleneseMethods.put("getElementWidth", new GetElementWidth(elementFinder));345 seleneseMethods.put("getEval", new GetEval(scriptMutator));346 seleneseMethods.put("getExpression", new GetExpression());347 seleneseMethods.put("getHtmlSource", new GetHtmlSource());348 seleneseMethods.put("getLocation", new GetLocation());349 seleneseMethods.put("getSelectedId", new FindFirstSelectedOptionProperty(javascriptLibrary, elementFinder, "id"));350 seleneseMethods.put("getSelectedIds", new FindSelectedOptionProperties(javascriptLibrary, elementFinder, "id"));351 seleneseMethods.put("getSelectedIndex", new FindFirstSelectedOptionProperty(javascriptLibrary, elementFinder, "index"));352 seleneseMethods.put("getSelectedIndexes", new FindSelectedOptionProperties(javascriptLibrary, elementFinder, "index"));353 seleneseMethods.put("getSelectedLabel", new FindFirstSelectedOptionProperty(javascriptLibrary, elementFinder, "text"));354 seleneseMethods.put("getSelectedLabels", new FindSelectedOptionProperties(javascriptLibrary, elementFinder, "text"));355 seleneseMethods.put("getSelectedValue", new FindFirstSelectedOptionProperty(javascriptLibrary, elementFinder, "value"));356 seleneseMethods.put("getSelectedValues", new FindSelectedOptionProperties(javascriptLibrary, elementFinder, "value"));357 seleneseMethods.put("getSelectOptions", new GetSelectOptions(javascriptLibrary, elementFinder));358 seleneseMethods.put("getSpeed", new NoOp("0"));359 seleneseMethods.put("getTable", new GetTable(elementFinder, javascriptLibrary));360 seleneseMethods.put("getText", new GetText(javascriptLibrary, elementFinder));361 seleneseMethods.put("getTitle", new GetTitle());362 seleneseMethods.put("getValue", new GetValue(elementFinder));363 seleneseMethods.put("getXpathCount", new GetXpathCount());364 seleneseMethods.put("goBack", new GoBack());365 seleneseMethods.put("highlight", new Highlight(elementFinder, javascriptLibrary));366 seleneseMethods.put("isAlertPresent", new IsAlertPresent(alertOverride));367 seleneseMethods.put("isChecked", new IsChecked(elementFinder));368 seleneseMethods.put("isConfirmationPresent", new IsConfirmationPresent(alertOverride));369 seleneseMethods.put("isCookiePresent", new IsCookiePresent());370 seleneseMethods.put("isEditable", new IsEditable(elementFinder));371 seleneseMethods.put("isElementPresent", new IsElementPresent(elementFinder));372 seleneseMethods.put("isOrdered", new IsOrdered(elementFinder, javascriptLibrary));373 seleneseMethods.put("isSomethingSelected", new IsSomethingSelected(javascriptLibrary));374 seleneseMethods.put("isTextPresent", new IsTextPresent(javascriptLibrary));375 seleneseMethods.put("isVisible", new IsVisible(elementFinder));376 seleneseMethods.put("keyDown", new KeyEvent(elementFinder, javascriptLibrary, keyState, "doKeyDown"));377 seleneseMethods.put("keyPress", new TypeKeys(alertOverride, elementFinder));378 seleneseMethods.put("keyUp", new KeyEvent(elementFinder, javascriptLibrary, keyState, "doKeyUp"));379 seleneseMethods.put("metaKeyDown", new MetaKeyDown(keyState));380 seleneseMethods.put("metaKeyUp", new MetaKeyUp(keyState));381 seleneseMethods.put("mouseOver", new MouseEvent(elementFinder, javascriptLibrary, "mouseover"));382 seleneseMethods.put("mouseOut", new MouseEvent(elementFinder, javascriptLibrary, "mouseout"));383 seleneseMethods.put("mouseDown", new MouseEvent(elementFinder, javascriptLibrary, "mousedown"));384 seleneseMethods.put("mouseDownAt", new MouseEventAt(elementFinder, javascriptLibrary, "mousedown"));385 seleneseMethods.put("mouseMove", new MouseEvent(elementFinder, javascriptLibrary, "mousemove"));386 seleneseMethods.put("mouseMoveAt", new MouseEventAt(elementFinder, javascriptLibrary, "mousemove"));387 seleneseMethods.put("mouseUp", new MouseEvent(elementFinder, javascriptLibrary, "mouseup"));388 seleneseMethods.put("mouseUpAt", new MouseEventAt(elementFinder, javascriptLibrary, "mouseup"));389 seleneseMethods.put("open", new Open(baseUrl));390 seleneseMethods.put("openWindow", new OpenWindow(new GetEval(scriptMutator)));391 seleneseMethods.put("refresh", new Refresh());392 seleneseMethods.put("removeAllSelections", new RemoveAllSelections(elementFinder));393 seleneseMethods.put("removeSelection", new RemoveSelection(javascriptLibrary, elementFinder));394 seleneseMethods.put("runScript", new RunScript(scriptMutator));395 seleneseMethods.put("select", new SelectOption(alertOverride, javascriptLibrary, elementFinder));396 seleneseMethods.put("selectFrame", new SelectFrame(windows));397 seleneseMethods.put("selectWindow", new SelectWindow(windows));398 seleneseMethods.put("setBrowserLogLevel", new NoOp(null));399 seleneseMethods.put("setContext", new NoOp(null));400 seleneseMethods.put("setSpeed", new NoOp(null));401 seleneseMethods.put("setTimeout", new SetTimeout(timer));402 seleneseMethods.put("shiftKeyDown", new ShiftKeyDown(keyState));403 seleneseMethods.put("shiftKeyUp", new ShiftKeyUp(keyState));404 seleneseMethods.put("submit", new Submit(elementFinder));405 seleneseMethods.put("type", new Type(alertOverride, javascriptLibrary, elementFinder, keyState));406 seleneseMethods.put("typeKeys", new TypeKeys(alertOverride, elementFinder));407 seleneseMethods.put("uncheck", new Uncheck(alertOverride, elementFinder));408 seleneseMethods.put("useXpathLibrary", new NoOp(null));409 seleneseMethods.put("waitForCondition", new WaitForCondition(scriptMutator));410 seleneseMethods.put("waitForFrameToLoad", new NoOp(null));411 seleneseMethods.put("waitForPageToLoad", new WaitForPageToLoad());412 seleneseMethods.put("waitForPopUp", new WaitForPopup(windows));413 seleneseMethods.put("windowFocus", new WindowFocus(javascriptLibrary));414 seleneseMethods.put("windowMaximize", new WindowMaximize(javascriptLibrary));415 }416} ...

Full Screen

Full Screen

Source:SeleneseCommandExecutor.java Github

copy

Full Screen

1/*2Copyright 2007-2009 Selenium committers3Licensed under the Apache License, Version 2.0 (the "License");4you may not use this file except in compliance with the License.5You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07Unless required by applicable law or agreed to in writing, software8distributed under the License is distributed on an "AS IS" BASIS,9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10See the License for the specific language governing permissions and11limitations under the License.12 */13package org.openqa.selenium;14import static org.openqa.selenium.remote.DriverCommand.CLEAR_ELEMENT;15import static org.openqa.selenium.remote.DriverCommand.CLICK_ELEMENT;16import static org.openqa.selenium.remote.DriverCommand.CLOSE;17import static org.openqa.selenium.remote.DriverCommand.EXECUTE_ASYNC_SCRIPT;18import static org.openqa.selenium.remote.DriverCommand.EXECUTE_SCRIPT;19import static org.openqa.selenium.remote.DriverCommand.FIND_CHILD_ELEMENT;20import static org.openqa.selenium.remote.DriverCommand.FIND_CHILD_ELEMENTS;21import static org.openqa.selenium.remote.DriverCommand.FIND_ELEMENT;22import static org.openqa.selenium.remote.DriverCommand.FIND_ELEMENTS;23import static org.openqa.selenium.remote.DriverCommand.GET;24import static org.openqa.selenium.remote.DriverCommand.GET_ACTIVE_ELEMENT;25import static org.openqa.selenium.remote.DriverCommand.GET_CURRENT_URL;26import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_ATTRIBUTE;27import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_SIZE;28import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_TAG_NAME;29import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_TEXT;30import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_VALUE;31import static org.openqa.selenium.remote.DriverCommand.GET_PAGE_SOURCE;32import static org.openqa.selenium.remote.DriverCommand.GET_TITLE;33import static org.openqa.selenium.remote.DriverCommand.IMPLICITLY_WAIT;34import static org.openqa.selenium.remote.DriverCommand.IS_ELEMENT_DISPLAYED;35import static org.openqa.selenium.remote.DriverCommand.IS_ELEMENT_ENABLED;36import static org.openqa.selenium.remote.DriverCommand.IS_ELEMENT_SELECTED;37import static org.openqa.selenium.remote.DriverCommand.NEW_SESSION;38import static org.openqa.selenium.remote.DriverCommand.QUIT;39import static org.openqa.selenium.remote.DriverCommand.SCREENSHOT;40import static org.openqa.selenium.remote.DriverCommand.SEND_KEYS_TO_ELEMENT;41import static org.openqa.selenium.remote.DriverCommand.SET_SCRIPT_TIMEOUT;42import static org.openqa.selenium.remote.DriverCommand.SUBMIT_ELEMENT;43import static org.openqa.selenium.remote.DriverCommand.SWITCH_TO_FRAME;44import com.google.common.collect.Maps;45import com.thoughtworks.selenium.CommandProcessor;46import com.thoughtworks.selenium.DefaultSelenium;47import com.thoughtworks.selenium.HttpCommandProcessor;48import com.thoughtworks.selenium.Selenium;49import com.thoughtworks.selenium.SeleniumException;50import org.openqa.selenium.internal.selenesedriver.ClearElement;51import org.openqa.selenium.internal.selenesedriver.ClickElement;52import org.openqa.selenium.internal.selenesedriver.Close;53import org.openqa.selenium.internal.selenesedriver.ExecuteAsyncScript;54import org.openqa.selenium.internal.selenesedriver.ExecuteScript;55import org.openqa.selenium.internal.selenesedriver.FindElement;56import org.openqa.selenium.internal.selenesedriver.FindElements;57import org.openqa.selenium.internal.selenesedriver.GetActiveElement;58import org.openqa.selenium.internal.selenesedriver.GetCurrentUrl;59import org.openqa.selenium.internal.selenesedriver.GetElementAttribute;60import org.openqa.selenium.internal.selenesedriver.GetElementText;61import org.openqa.selenium.internal.selenesedriver.GetElementValue;62import org.openqa.selenium.internal.selenesedriver.GetPageSource;63import org.openqa.selenium.internal.selenesedriver.GetSize;64import org.openqa.selenium.internal.selenesedriver.GetTagName;65import org.openqa.selenium.internal.selenesedriver.GetTitle;66import org.openqa.selenium.internal.selenesedriver.GetUrl;67import org.openqa.selenium.internal.selenesedriver.IsElementDisplayed;68import org.openqa.selenium.internal.selenesedriver.IsElementEnabled;69import org.openqa.selenium.internal.selenesedriver.IsElementSelected;70import org.openqa.selenium.internal.selenesedriver.NewSession;71import org.openqa.selenium.internal.selenesedriver.QuitSelenium;72import org.openqa.selenium.internal.selenesedriver.SeleneseFunction;73import org.openqa.selenium.internal.selenesedriver.SendKeys;74import org.openqa.selenium.internal.selenesedriver.SubmitElement;75import org.openqa.selenium.internal.selenesedriver.SwitchToFrame;76import org.openqa.selenium.internal.selenesedriver.TakeScreenshot;77import org.openqa.selenium.remote.BeanToJsonConverter;78import org.openqa.selenium.remote.Command;79import org.openqa.selenium.remote.CommandExecutor;80import org.openqa.selenium.remote.DesiredCapabilities;81import org.openqa.selenium.remote.ErrorCodes;82import org.openqa.selenium.remote.JsonToBeanConverter;83import org.openqa.selenium.remote.Response;84import java.io.File;85import java.net.URL;86import java.util.Map;87public class SeleneseCommandExecutor implements CommandExecutor {88 private final ErrorCodes errorCodes;89 private final Selenium instance;90 private Map<String, SeleneseFunction<?>> functions = Maps.newHashMap();91 public SeleneseCommandExecutor(URL seleniumServer, URL remoteAddress, Capabilities capabilities) {92 this(new HttpCommandProcessor(93 seleniumServer.getHost(), seleniumServer.getPort(),94 startCommand(capabilities), remoteAddress.toString()));95 }96 public SeleneseCommandExecutor(CommandProcessor processor) {97 this(new DefaultSelenium(processor));98 }99 public SeleneseCommandExecutor(Selenium instance) {100 this.instance = instance;101 errorCodes = new ErrorCodes();102 prepareCommands();103 }104 public Selenium getWrappedSelenium() {105 return instance;106 }107 public Response execute(Command command) {108 SeleneseFunction<?> function = functions.get(command.getName());109 if (function == null) {110 throw new UnsupportedOperationException("cannot execute: " + command.getName());111 }112 try {113 Response response = new Response();114 response.setValue(function.apply(instance, command.getParameters()));115 return response;116 } catch (Exception e) {117 return prepareExceptionResponse(e);118 }119 }120 private Response prepareExceptionResponse(Exception e) {121 Response response = new Response();122 Exception toUse = e;123 if (e instanceof SeleniumException) {124 // World of fragility. *sigh*125 if (e.getMessage().matches("ERROR: (Threw an exception: )?Element .+ not found")) {126 toUse = new StaleElementReferenceException(e.getMessage(), e);127 }128 }129 response.setStatus(errorCodes.toStatusCode(toUse));130 // It's like a lesson in inefficiency131 Object raw =132 new JsonToBeanConverter().convert(Map.class, new BeanToJsonConverter().convert(toUse));133 response.setValue(raw);134 return response;135 }136 public void addCommand(String methodName, SeleneseFunction<?> command) {137 functions.put(methodName, command);138 }139 private void prepareCommands() {140 FindElement findElement = new FindElement();141 FindElements findElements = new FindElements();142 SeleneseTimeouts timeouts = new SeleneseTimeouts(143 findElement.implicitlyWait(), findElements.implicitlyWait());144 ExecuteAsyncScript executeAsyncScript = new ExecuteAsyncScript();145 addCommand(CLEAR_ELEMENT, new ClearElement());146 addCommand(CLICK_ELEMENT, new ClickElement());147 addCommand(CLOSE, new Close());148 addCommand(GET_CURRENT_URL, new GetCurrentUrl());149 addCommand(EXECUTE_SCRIPT, new ExecuteScript());150 addCommand(EXECUTE_ASYNC_SCRIPT, executeAsyncScript);151 addCommand(SET_SCRIPT_TIMEOUT, executeAsyncScript.setScriptTimeout());152 addCommand(FIND_CHILD_ELEMENT, findElement);153 addCommand(FIND_CHILD_ELEMENTS, findElements);154 addCommand(FIND_ELEMENT, findElement);155 addCommand(FIND_ELEMENTS, findElements);156 addCommand(IMPLICITLY_WAIT, timeouts);157 addCommand(GET, new GetUrl());158 addCommand(GET_ACTIVE_ELEMENT, new GetActiveElement());159 addCommand(GET_ELEMENT_ATTRIBUTE, new GetElementAttribute());160 addCommand(GET_ELEMENT_SIZE, new GetSize());161 addCommand(GET_ELEMENT_TEXT, new GetElementText());162 addCommand(GET_ELEMENT_VALUE, new GetElementValue());163 addCommand(GET_ELEMENT_TAG_NAME, new GetTagName());164 addCommand(GET_TITLE, new GetTitle());165 addCommand(IS_ELEMENT_DISPLAYED, new IsElementDisplayed());166 addCommand(IS_ELEMENT_ENABLED, new IsElementEnabled());167 addCommand(IS_ELEMENT_SELECTED, new IsElementSelected());168 addCommand(NEW_SESSION, new NewSession());169 addCommand(GET_PAGE_SOURCE, new GetPageSource());170 addCommand(SCREENSHOT, new TakeScreenshot());171 addCommand(SEND_KEYS_TO_ELEMENT, new SendKeys());172 addCommand(SWITCH_TO_FRAME, new SwitchToFrame());173 addCommand(SUBMIT_ELEMENT, new SubmitElement());174 addCommand(QUIT, new QuitSelenium());175 }176 private static String startCommand(Capabilities capabilities) {177 String browser = capabilities.getBrowserName();178 if (browser.startsWith("*")) {179 return browser;180 }181 if (DesiredCapabilities.firefox().getBrowserName().equals(browser)) {182 return "*chrome";183 }184 if ("safari".equals(browser)) {185 String path = findSafari();186 return "*safari " + path;187 }188 if (DesiredCapabilities.chrome().getBrowserName().equals(browser)) {189 return "*googlechrome /Applications/Google Chrome.app/Contents/MacOS/Google Chrome";190 }191 throw new IllegalArgumentException(192 "Cannot determine which selenium type to use: " + capabilities.getBrowserName());193 }194 private static String findSafari() {195 if (Platform.getCurrent().is(Platform.WINDOWS)) {196 File[] locations = new File[] {197 new File("C:\\Program Files (x86)\\Safari\\safari.exe"),198 new File("C:\\Program Files\\Safari\\safari.exe")199 };200 for (File location : locations) {201 if (location.exists()) {202 return location.getAbsolutePath();203 }204 }205 }206 return "";207 }208 private class SeleneseTimeouts implements SeleneseFunction<Void> {209 private final SeleneseFunction<Object>[] functions;210 public SeleneseTimeouts(SeleneseFunction<Object>... functions) {211 this.functions = functions;212 }213 public Void apply(Selenium selenium, Map<String, ?> args) {214 for (SeleneseFunction<Object> function : functions) {215 function.apply(selenium, args);216 }217 return null;218 }219 }220}...

Full Screen

Full Screen

Source:WebComponent.java Github

copy

Full Screen

1/**2 * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com)3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package xxx.com.github.webdriverextensions;17import java.util.List;18import org.openqa.selenium.By;19import org.openqa.selenium.Dimension;20import org.openqa.selenium.OutputType;21import org.openqa.selenium.Point;22import org.openqa.selenium.Rectangle;23import org.openqa.selenium.WebDriver;24import org.openqa.selenium.WebDriverException;25import org.openqa.selenium.WebElement;26import org.openqa.selenium.interactions.internal.Coordinates;27public abstract class WebComponent28 implements org.openqa.selenium.WebElement, org.openqa.selenium.internal.FindsByLinkText,29 org.openqa.selenium.internal.FindsById, org.openqa.selenium.internal.FindsByName,30 org.openqa.selenium.internal.FindsByTagName, org.openqa.selenium.internal.FindsByClassName,31 org.openqa.selenium.internal.FindsByCssSelector, org.openqa.selenium.internal.FindsByXPath,32 org.openqa.selenium.internal.WrapsDriver, org.openqa.selenium.internal.Locatable {33 WebElement wrappedWebElement;34 WebElement delegateWebElement;35 WebDriver webDriver;36 public void init(WebDriver webDriver, WebElement wrappedWebElement) {37 this.wrappedWebElement = wrappedWebElement;38 this.webDriver = webDriver;39 }40 public void init(WebDriver webDriver, WebElement wrappedWebElement,41 WebElement delegateWebElement) {42 this.wrappedWebElement = wrappedWebElement;43 this.delegateWebElement = delegateWebElement;44 this.webDriver = webDriver;45 }46 public WebElement getWrappedWebElement() {47 return wrappedWebElement;48 }49 public WebElement getDelegateWebElement() {50 return delegateWebElement;51 }52 @Override53 public void click() {54 if (delegateWebElement != null) {55 delegateWebElement.click();56 } else {57 wrappedWebElement.click();58 }59 }60 @Override61 public void submit() {62 if (delegateWebElement != null) {63 delegateWebElement.submit();64 } else {65 wrappedWebElement.submit();66 }67 }68 @Override69 public void sendKeys(CharSequence... keysToSend) {70 if (delegateWebElement != null) {71 delegateWebElement.sendKeys(keysToSend);72 } else {73 wrappedWebElement.sendKeys(keysToSend);74 }75 }76 @Override77 public void clear() {78 if (delegateWebElement != null) {79 delegateWebElement.clear();80 } else {81 wrappedWebElement.clear();82 }83 }84 @Override85 public String getTagName() {86 if (delegateWebElement != null) {87 return delegateWebElement.getTagName();88 } else {89 return wrappedWebElement.getTagName();90 }91 }92 @Override93 public String getAttribute(String name) {94 if (delegateWebElement != null) {95 return delegateWebElement.getAttribute(name);96 } else {97 return wrappedWebElement.getAttribute(name);98 }99 }100 @Override101 public boolean isSelected() {102 if (delegateWebElement != null) {103 return delegateWebElement.isSelected();104 } else {105 return wrappedWebElement.isSelected();106 }107 }108 @Override109 public boolean isEnabled() {110 if (delegateWebElement != null) {111 return delegateWebElement.isEnabled();112 } else {113 return wrappedWebElement.isEnabled();114 }115 }116 @Override117 public String getText() {118 if (delegateWebElement != null) {119 return delegateWebElement.getText();120 } else {121 return wrappedWebElement.getText();122 }123 }124 @Override125 public List<WebElement> findElements(By by) {126 return wrappedWebElement.findElements(by);127 }128 @Override129 public WebElement findElement(By by) {130 return wrappedWebElement.findElement(by);131 }132 @Override133 public boolean isDisplayed() {134 if (delegateWebElement != null) {135 return delegateWebElement.isDisplayed();136 } else {137 return wrappedWebElement.isDisplayed();138 }139 }140 @Override141 public Point getLocation() {142 if (delegateWebElement != null) {143 return delegateWebElement.getLocation();144 } else {145 return wrappedWebElement.getLocation();146 }147 }148 @Override149 public Dimension getSize() {150 if (delegateWebElement != null) {151 return delegateWebElement.getSize();152 } else {153 return wrappedWebElement.getSize();154 }155 }156 @Override157 public Rectangle getRect() {158 if (delegateWebElement != null) {159 return delegateWebElement.getRect();160 } else {161 return wrappedWebElement.getRect();162 }163 }164 @Override165 public String getCssValue(String propertyName) {166 if (delegateWebElement != null) {167 return delegateWebElement.getCssValue(propertyName);168 } else {169 return wrappedWebElement.getCssValue(propertyName);170 }171 }172 public void click(WebElement webElement) {173 webElement.click();174 }175 public void clear(WebElement webElement) {176 webElement.clear();177 }178 public boolean isDisplayed(WebElement webElement) {179 return webElement.isDisplayed();180 }181 @Override182 public WebElement findElementByLinkText(String using) {183 return ((org.openqa.selenium.internal.FindsByLinkText) wrappedWebElement)184 .findElementByLinkText(using);185 }186 @Override187 public List<WebElement> findElementsByLinkText(String using) {188 return ((org.openqa.selenium.internal.FindsByLinkText) wrappedWebElement)189 .findElementsByLinkText(using);190 }191 @Override192 public WebElement findElementByPartialLinkText(String using) {193 return ((org.openqa.selenium.internal.FindsByLinkText) wrappedWebElement)194 .findElementByPartialLinkText(using);195 }196 @Override197 public List<WebElement> findElementsByPartialLinkText(String using) {198 return ((org.openqa.selenium.internal.FindsByLinkText) wrappedWebElement)199 .findElementsByPartialLinkText(using);200 }201 @Override202 public WebElement findElementById(String using) {203 return ((org.openqa.selenium.internal.FindsById) wrappedWebElement).findElementById(using);204 }205 @Override206 public List<WebElement> findElementsById(String using) {207 return ((org.openqa.selenium.internal.FindsById) wrappedWebElement).findElementsById(using);208 }209 @Override210 public WebElement findElementByName(String using) {211 return ((org.openqa.selenium.internal.FindsByName) wrappedWebElement).findElementByName(using);212 }213 @Override214 public List<WebElement> findElementsByName(String using) {215 return ((org.openqa.selenium.internal.FindsByName) wrappedWebElement).findElementsByName(using);216 }217 @Override218 public WebElement findElementByTagName(String using) {219 return ((org.openqa.selenium.internal.FindsByTagName) wrappedWebElement)220 .findElementByTagName(using);221 }222 @Override223 public List<WebElement> findElementsByTagName(String using) {224 return ((org.openqa.selenium.internal.FindsByTagName) wrappedWebElement)225 .findElementsByTagName(using);226 }227 @Override228 public WebElement findElementByClassName(String using) {229 return ((org.openqa.selenium.internal.FindsByClassName) wrappedWebElement)230 .findElementByClassName(using);231 }232 @Override233 public List<WebElement> findElementsByClassName(String using) {234 return ((org.openqa.selenium.internal.FindsByClassName) wrappedWebElement)235 .findElementsByClassName(using);236 }237 @Override238 public WebElement findElementByCssSelector(String using) {239 return ((org.openqa.selenium.internal.FindsByCssSelector) wrappedWebElement)240 .findElementByCssSelector(using);241 }242 @Override243 public List<WebElement> findElementsByCssSelector(String using) {244 return ((org.openqa.selenium.internal.FindsByCssSelector) wrappedWebElement)245 .findElementsByCssSelector(using);246 }247 @Override248 public WebElement findElementByXPath(String using) {249 return ((org.openqa.selenium.internal.FindsByXPath) wrappedWebElement)250 .findElementByXPath(using);251 }252 @Override253 public List<WebElement> findElementsByXPath(String using) {254 return ((org.openqa.selenium.internal.FindsByXPath) wrappedWebElement)255 .findElementsByXPath(using);256 }257 @Override258 public WebDriver getWrappedDriver() {259 return webDriver;260 }261 @Override262 public Coordinates getCoordinates() {263 if (delegateWebElement != null) {264 return ((org.openqa.selenium.internal.Locatable) delegateWebElement).getCoordinates();265 } else {266 return ((org.openqa.selenium.internal.Locatable) wrappedWebElement).getCoordinates();267 }268 }269 @Override270 public <X> X getScreenshotAs(OutputType<X> ot) throws WebDriverException {271 return wrappedWebElement.getScreenshotAs(ot);272 }273}...

Full Screen

Full Screen

Source:WebDriverUnpackUtility.java Github

copy

Full Screen

1/*2 * Licensed under the Apache License, Version 2.0 (the "License");3 * you may not use this file except in compliance with the License.4 * See the NOTICE file distributed with this work for additional5 * information regarding copyright ownership.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.appium.java_client.pagefactory.utils;17import io.appium.java_client.pagefactory.bys.ContentType;18import org.openqa.selenium.ContextAware;19import org.openqa.selenium.SearchContext;20import org.openqa.selenium.WebDriver;21import org.openqa.selenium.internal.WrapsDriver;22import org.openqa.selenium.internal.WrapsElement;23public final class WebDriverUnpackUtility {24 private static final String NATIVE_APP_PATTERN = "NATIVE_APP";25 /**26 * This method extract an instance of {@link org.openqa.selenium.WebDriver} from the given27 * {@link org.openqa.selenium.SearchContext}.28 * @param searchContext is an instance of {@link org.openqa.selenium.SearchContext}29 * It may be the instance of {@link org.openqa.selenium.WebDriver}30 * or {@link org.openqa.selenium.WebElement} or some other user's31 * extension/implementation.32 * Note: if you want to use your own implementation then it should implement33 * {@link org.openqa.selenium.internal.WrapsDriver} or34 * {@link org.openqa.selenium.internal.WrapsElement}35 * @return the instance of {@link org.openqa.selenium.WebDriver}.36 * Note: if the given {@link org.openqa.selenium.SearchContext} is not37 * {@link org.openqa.selenium.WebDriver} and it doesn't implement38 * {@link org.openqa.selenium.internal.WrapsDriver} or39 * {@link org.openqa.selenium.internal.WrapsElement} then this method returns40 * null.41 *42 */43 public static WebDriver unpackWebDriverFromSearchContext(SearchContext searchContext) {44 if (searchContext instanceof WebDriver) {45 return (WebDriver) searchContext;46 }47 if (searchContext instanceof WrapsDriver) {48 return unpackWebDriverFromSearchContext(49 ((WrapsDriver) searchContext).getWrappedDriver());50 }51 // Search context it is not only Webdriver. Webelement is search context52 // too.53 // RemoteWebElement and MobileElement implement WrapsDriver54 if (searchContext instanceof WrapsElement) {55 return unpackWebDriverFromSearchContext(56 ((WrapsElement) searchContext).getWrappedElement());57 }58 return null;59 }60 /**61 * @param context is an instance of {@link org.openqa.selenium.SearchContext}62 * It may be the instance of {@link org.openqa.selenium.WebDriver}63 * or {@link org.openqa.selenium.WebElement} or some other user's64 * extension/implementation.65 * Note: if you want to use your own implementation then it should66 * implement {@link org.openqa.selenium.ContextAware} or67 * {@link org.openqa.selenium.internal.WrapsDriver}68 * @return current content type. It depends on current context. If current context is69 * NATIVE_APP it will return70 * {@link io.appium.java_client.pagefactory.bys.ContentType#NATIVE_MOBILE_SPECIFIC}.71 * {@link io.appium.java_client.pagefactory.bys.ContentType#HTML_OR_DEFAULT} will be returned72 * if the current context is WEB_VIEW.73 * {@link io.appium.java_client.pagefactory.bys.ContentType#HTML_OR_DEFAULT} also will be74 * returned if the given {@link org.openqa.selenium.SearchContext}75 * instance doesn't implement76 * {@link org.openqa.selenium.ContextAware} and {@link org.openqa.selenium.internal.WrapsDriver}77 */78 public static ContentType getCurrentContentType(SearchContext context) {79 WebDriver driver = WebDriverUnpackUtility.unpackWebDriverFromSearchContext(context);80 if (!ContextAware.class.isAssignableFrom(driver.getClass())) { //it is desktop browser81 return ContentType.HTML_OR_DEFAULT;82 }83 ContextAware contextAware = ContextAware.class.cast(driver);84 String currentContext = contextAware.getContext();85 if (currentContext.contains(NATIVE_APP_PATTERN)) {86 return ContentType.NATIVE_MOBILE_SPECIFIC;87 }88 return ContentType.HTML_OR_DEFAULT;89 }90}...

Full Screen

Full Screen

Source:QAFWebDriver.java Github

copy

Full Screen

1/*******************************************************************************2 * QMetry Automation Framework provides a powerful and versatile platform to author 3 * Automated Test Cases in Behavior Driven, Keyword Driven or Code Driven approach4 * 5 * Copyright 2016 Infostretch Corporation6 *7 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.8 *9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.10 *11 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR12 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT13 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE14 *15 * You should have received a copy of the GNU General Public License along with this program in the name of LICENSE.txt in the root folder of the distribution. If not, see https://opensource.org/licenses/gpl-3.0.html16 *17 * See the NOTICE.TXT file in root folder of this source files distribution 18 * for additional information regarding copyright ownership and licenses19 * of other open source software / files used by QMetry Automation Framework.20 *21 * For any inquiry or need additional information, please contact support-qaf@infostretch.com22 *******************************************************************************/23package com.qmetry.qaf.automation.ui.webdriver;24import java.util.List;25import org.openqa.selenium.By;26import org.openqa.selenium.HasCapabilities;27import org.openqa.selenium.JavascriptExecutor;28import org.openqa.selenium.TakesScreenshot;29import org.openqa.selenium.WebDriver;30import org.openqa.selenium.interactions.HasInputDevices;31import org.openqa.selenium.interactions.Keyboard;32import org.openqa.selenium.interactions.Mouse;33import org.openqa.selenium.interactions.TouchScreen;34import org.openqa.selenium.internal.FindsByClassName;35import org.openqa.selenium.internal.FindsByCssSelector;36import org.openqa.selenium.internal.FindsById;37import org.openqa.selenium.internal.FindsByLinkText;38import org.openqa.selenium.internal.FindsByName;39import org.openqa.selenium.internal.FindsByTagName;40import org.openqa.selenium.internal.FindsByXPath;41import com.qmetry.qaf.automation.ui.UiDriver;42public interface QAFWebDriver extends UiDriver, WebDriver, TakesScreenshot, JavascriptExecutor, FindsById,43 FindsByClassName, FindsByLinkText, FindsByName, FindsByCssSelector, FindsByCustomStretegy, FindsByTagName,44 FindsByXPath, HasInputDevices, HasCapabilities {45 QAFWebElement findElement(By by);46 List<QAFWebElement> getElements(By by);47 QAFWebElement findElement(String locator);48 List<QAFWebElement> findElements(String locator);49 Mouse getMouse();50 Keyboard getKeyboard();51 TouchScreen getTouchScreen();52}...

Full Screen

Full Screen

Source:MobileDriver.java Github

copy

Full Screen

1/*2 * Licensed under the Apache License, Version 2.0 (the "License");3 * you may not use this file except in compliance with the License.4 * See the NOTICE file distributed with this work for additional5 * information regarding copyright ownership.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.mengge;17import org.openqa.selenium.By;18import org.openqa.selenium.ContextAware;19import org.openqa.selenium.Rotatable;20import org.openqa.selenium.WebDriver;21import org.openqa.selenium.WebElement;22import org.openqa.selenium.html5.LocationContext;23import org.openqa.selenium.internal.FindsByClassName;24import org.openqa.selenium.internal.FindsByCssSelector;25import org.openqa.selenium.internal.FindsById;26import org.openqa.selenium.internal.FindsByLinkText;27import org.openqa.selenium.internal.FindsByName;28import org.openqa.selenium.internal.FindsByTagName;29import org.openqa.selenium.internal.FindsByXPath;30import org.openqa.selenium.remote.Response;31import java.util.List;32import java.util.Map;33public interface MobileDriver<T extends WebElement> extends WebDriver, PerformsTouchActions, ContextAware, Rotatable,34 FindsByAccessibilityId<T>, LocationContext, DeviceActionShortcuts, TouchShortcuts,35 InteractsWithFiles, InteractsWithApps, HasAppStrings, FindsByClassName, FindsByCssSelector, FindsById,36 FindsByLinkText, FindsByName, FindsByTagName, FindsByXPath {37 Response execute(String driverCommand, Map<String, ?> parameters);38 List<T> findElements(By by);39 T findElement(By by);40 T findElementByClassName(String className);41 List<T> findElementsByClassName(String className);42 T findElementByCssSelector(String cssSelector);43 List<T> findElementsByCssSelector(String cssSelector);44 T findElementById(String id);45 List<T> findElementsById(String id);46 T findElementByLinkText(String linkText);47 List<T> findElementsByLinkText(String linkText);48 T findElementByPartialLinkText(String partialLinkText);49 List<T> findElementsByPartialLinkText(String partialLinkText);50 T findElementByName(String name);51 List<T> findElementsByName(String name);52 T findElementByTagName(String tagName);53 List<T> findElementsByTagName(String tagName);54 T findElementByXPath(String xPath);55 List<T> findElementsByXPath(String xPath);56}...

Full Screen

Full Screen

Source:SeleniumDriver.java Github

copy

Full Screen

1/*2 * SonarQube3 * Copyright (C) 2009-2016 SonarSource SA4 * mailto:contact AT sonarsource DOT com5 *6 * This program is free software; you can redistribute it and/or7 * modify it under the terms of the GNU Lesser General Public8 * License as published by the Free Software Foundation; either9 * version 3 of the License, or (at your option) any later version.10 *11 * This program is distributed in the hope that it will be useful,12 * but WITHOUT ANY WARRANTY; without even the implied warranty of13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14 * Lesser General Public License for more details.15 *16 * You should have received a copy of the GNU Lesser General Public License17 * along with this program; if not, write to the Free Software Foundation,18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.19 */20package util.selenium;21public interface SeleniumDriver extends org.openqa.selenium.WebDriver, org.openqa.selenium.JavascriptExecutor, org.openqa.selenium.internal.FindsById, org.openqa.selenium.internal.FindsByClassName, org.openqa.selenium.internal.FindsByLinkText, org.openqa.selenium.internal.FindsByName, org.openqa.selenium.internal.FindsByCssSelector, org.openqa.selenium.internal.FindsByTagName, org.openqa.selenium.internal.FindsByXPath, org.openqa.selenium.interactions.HasInputDevices, org.openqa.selenium.HasCapabilities, org.openqa.selenium.TakesScreenshot {22}...

Full Screen

Full Screen

Either

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.internal.Either;2import org.openqa.selenium.internal.Either.Left;3import org.openqa.selenium.internal.Either.Right;4import org.openqa.selenium.remote.RemoteWebDriver;5import org.openqa.selenium.remote.RemoteWebElement;6import org.openqa.selenium.remote.Response;7import org.openqa.selenium.remote.internal.JsonToWebElementConverter;8import org.openqa.selenium.remote.internal.WebElementToJsonConverter;9import org.openqa.selenium.remote.internal.WebElementToJsonConverter.ElementContext;10import org.openqa.selenium.remote.service.DriverCommandExecutor;11import org.openqa.selenium.support.pagefactory.ElementLocator;12import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;13import org.openqa.selenium.support.pagefactory.internal.LocatingElementListHandler;14import org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler;15import org.openqa.selenium.support.ui.Clock;16import org.openqa.selenium.support.ui.Clock.SystemClock;17import org.openqa.selenium.support.ui.Duration;18import org.openqa.selenium.support.ui.Sleeper;19import org.openqa.selenium.support.ui.SystemClock;20import org.openqa.selenium.support.ui.WebDriverWait;21import java.lang.reflect.InvocationHandler;22import java.lang.reflect.InvocationTargetException;23import java.lang.reflect.Method;24import java.lang.reflect.Proxy;25import java.time.Duration;26import java.util.List;27import java.util.function.Function;28import static java.util.concurrent.TimeUnit.MILLISECONDS;29import static java.util.concurrent.TimeUnit.SECONDS;30import static java.util.stream.Collectors.toList;31import static org.openqa.selenium.support.ui.Duration.of;32public class CustomElementLocatorFactory implements ElementLocatorFactory {33 private final RemoteWebDriver driver;34 private final Duration timeOutDuration;35 public CustomElementLocatorFactory(RemoteWebDriver driver, Duration timeOutDuration) {36 this.driver = driver;37 this.timeOutDuration = timeOutDuration;38 }39 public ElementLocator createLocator(Field field) {40 return new CustomElementLocator(driver, field, timeOutDuration);41 }42}43public class CustomElementLocator implements ElementLocator {44 private final RemoteWebDriver driver;45 private final By by;46 private final Duration timeOutDuration;47 public CustomElementLocator(RemoteWebDriver driver, Field field, Duration timeOutDuration) {48 this.driver = driver;49 this.by = buildByFromFindBys(field);50 this.timeOutDuration = timeOutDuration;51 }52 private static By buildByFromFindBys(Field field) {53 By ans = null;54 if (field.isAnnotationPresent(FindBy.class)) {55 ans = buildByFromFindBy(field.getAnnotation(FindBy.class));56 } else

Full Screen

Full Screen

Either

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.internal.Either;2import org.openqa.selenium.internal.WrapsElement;3import org.openqa.selenium.remote.RemoteWebElement;4import org.openqa.selenium.remote.RemoteWebDriver;5import org.openqa.selenium.remote.RemoteWebElement;6import org.openqa.selenium.remote.RemoteWebDriver;7import org.openqa.selenium.remote.RemoteWebElement;8import org.openqa.selenium.remote.RemoteWebDriver;9import org.openqa.selenium.remote.RemoteWebElement;10import org.openqa.selenium.remote.RemoteWebDriver;11import org.openqa.selenium.remote.RemoteWebElement;12import org.openqa.selenium.remote.RemoteWebDriver;13import org.openqa.selenium.remote.RemoteWebElement;14import org.openqa.selenium.remote.RemoteWebDriver;15import org.openqa.selenium.remote.RemoteWebElement;16import org.openqa.selenium.remote.RemoteWebDriver;17import org.openqa.selenium.remote.RemoteWebElement;18import org.openqa.selenium.remote.RemoteWebDriver;19import org.openqa.selenium.remote.RemoteWebElement;20import org.openqa.selenium.remote.RemoteWebDriver;21import org.openqa.selenium.remote.RemoteWebElement;22import org.openqa.selenium.remote.RemoteWebDriver;23import org.openqa.selenium.remote.RemoteWebElement;24import org.openqa.selenium.remote.RemoteWebDriver;25import org.openqa.selenium.remote.RemoteWebElement;26import org.openqa.selenium.remote.RemoteWebDriver;27import org.openqa.selenium.remote.RemoteWebElement;28import org.openqa.selenium.remote.RemoteWebDriver;29import org.openqa.selenium.remote.RemoteWebElement;30import org.openqa.selenium.remote.RemoteWebDriver;31import org.openqa.selenium.remote.RemoteWebElement;32import org.openqa.selenium.remote.RemoteWebDriver;33import org.openqa.selenium.remote.RemoteWebElement;34import org.openqa.selenium.remote.RemoteWebDriver;35import org.openqa.selenium.remote.RemoteWebElement;36import org.openqa.selenium.remote.RemoteWebDriver;37import org.openqa.selenium.remote.RemoteWebElement;38import org.openqa.selenium.remote.RemoteWebDriver;39import org.openqa.selenium.remote.RemoteWebElement;40import org.openqa.selenium.remote.RemoteWebDriver;41import org.openqa.selenium.remote.RemoteWebElement;42import org.openqa.selenium.remote.RemoteWebDriver;43import org.openqa.selenium.remote.RemoteWebElement;44import org.openqa.selenium.remote.RemoteWebDriver;45import org.openqa.selenium.remote.RemoteWebElement;46import org.openqa.selenium.remote.RemoteWebDriver;47import org.openqa.selenium.remote.RemoteWebElement;48import org.openqa.selenium.remote.RemoteWebDriver;49import org.openqa.selenium.remote.RemoteWebElement;50import org.openqa.selenium.remote.RemoteWebDriver;51import org.openqa.selenium.remote.RemoteWebElement;52import org.openqa.selenium.remote.RemoteWebDriver;53import org.openqa.selenium.remote.RemoteWebElement;54import org.openqa.selenium.remote.RemoteWebDriver;55import org.openqa.selenium.remote.RemoteWebElement;56import org.openqa.selenium.remote.RemoteWebDriver;57import org.openqa.selenium.remote.RemoteWebElement;58import org.openqa.selenium.remote.RemoteWebDriver;59import org.openqa.selenium.remote.RemoteWebElement;60import org.openqa.selenium.remote.RemoteWebDriver;61import org.openqa.selenium.remote.RemoteWebElement;62import org.openqa.selenium.remote.RemoteWebDriver;

Full Screen

Full Screen
copy
1int arr[] = new int[10];2for(int i=0;i<arr.length;i++)3 arr[i] = 0;4
Full Screen
copy
1int[] arr = new int[10];2
Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in Either

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful