/* * Copyright (C) 2017 Igalia S.L. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #pragma once #include "Actions.h" #include "Capabilities.h" #include #include #include #include #include #include #include namespace WebDriver { class CommandResult; class SessionHost; class Session : public RefCounted { public: static Ref create(std::unique_ptr&& host) { return adoptRef(*new Session(WTFMove(host))); } ~Session(); const String& id() const; const Capabilities& capabilities() const; bool isConnected() const; double scriptTimeout() const { return m_scriptTimeout; } double pageLoadTimeout() const { return m_pageLoadTimeout; } double implicitWaitTimeout() const { return m_implicitWaitTimeout; } static const String& webElementIdentifier(); enum class FindElementsMode { Single, Multiple }; enum class ExecuteScriptMode { Sync, Async }; struct Cookie { String name; String value; std::optional path; std::optional domain; std::optional secure; std::optional httpOnly; std::optional expiry; std::optional sameSite; }; InputSource& getOrCreateInputSource(const String& id, InputSource::Type, std::optional); void waitForNavigationToComplete(Function&&); void createTopLevelBrowsingContext(Function&&); void close(Function&&); void getTimeouts(Function&&); void setTimeouts(const Timeouts&, Function&&); void go(const String& url, Function&&); void getCurrentURL(Function&&); void back(Function&&); void forward(Function&&); void refresh(Function&&); void getTitle(Function&&); void getWindowHandle(Function&&); void closeWindow(Function&&); void switchToWindow(const String& windowHandle, Function&&); void getWindowHandles(Function&&); void newWindow(std::optional typeHint, Function&&); void switchToFrame(RefPtr&&, Function&&); void switchToParentFrame(Function&&); void getWindowRect(Function&&); void setWindowRect(std::optional x, std::optional y, std::optional width, std::optional height, Function&&); void maximizeWindow(Function&&); void minimizeWindow(Function&&); void fullscreenWindow(Function&&); void findElements(const String& strategy, const String& selector, FindElementsMode, const String& rootElementID, Function&&); void getActiveElement(Function&&); void isElementSelected(const String& elementID, Function&&); void getElementAttribute(const String& elementID, const String& attribute, Function&&); void getElementProperty(const String& elementID, const String& attribute, Function&&); void getElementCSSValue(const String& elementID, const String& cssProperty, Function&&); void getElementText(const String& elementID, Function&&); void getElementTagName(const String& elementID, Function&&); void getElementRect(const String& elementID, Function&&); void isElementEnabled(const String& elementID, Function&&); void isElementDisplayed(const String& elementID, Function&&); void elementClick(const String& elementID, Function&&); void elementClear(const String& elementID, Function&&); void elementSendKeys(const String& elementID, const String& text, Function&&); void getPageSource(Function&&); void executeScript(const String& script, RefPtr&& arguments, ExecuteScriptMode, Function&&); void getAllCookies(Function&&); void getNamedCookie(const String& name, Function&&); void addCookie(const Cookie&, Function&&); void deleteCookie(const String& name, Function&&); void deleteAllCookies(Function&&); void performActions(Vector>&&, Function&&); void releaseActions(Function&&); void dismissAlert(Function&&); void acceptAlert(Function&&); void getAlertText(Function&&); void sendAlertText(const String&, Function&&); void takeScreenshot(std::optional elementID, std::optional scrollIntoView, Function&&); private: Session(std::unique_ptr&&); void switchToTopLevelBrowsingContext(const String&); void switchToBrowsingContext(const String&, Function&&); void switchToBrowsingContext(const String& toplevelBrowsingContext, const String& browsingContext, Function&&); void closeTopLevelBrowsingContext(const String& toplevelBrowsingContext, Function&&); void closeAllToplevelBrowsingContexts(const String& toplevelBrowsingContext, Function&&); void getToplevelBrowsingContextRect(Function&&); std::optional pageLoadStrategyString() const; void handleUserPrompts(Function&&); void handleUnexpectedAlertOpen(Function&&); void dismissAndNotifyAlert(Function&&); void acceptAndNotifyAlert(Function&&); void reportUnexpectedAlertOpen(Function&&); RefPtr createElement(RefPtr&&); Ref createElement(const String& elementID); RefPtr extractElement(JSON::Value&); String extractElementID(JSON::Value&); Ref handleScriptResult(Ref&&); void elementIsEditable(const String& elementID, Function&&); struct Point { int x { 0 }; int y { 0 }; }; struct Size { int width { 0 }; int height { 0 }; }; struct Rect { Point origin; Size size; }; enum class ElementLayoutOption { ScrollIntoViewIfNeeded = 1 << 0, UseViewportCoordinates = 1 << 1, }; void computeElementLayout(const String& elementID, OptionSet, Function&&, std::optional&&, bool, RefPtr&&)>&&); void elementIsFileUpload(const String& elementID, Function&&); enum class FileUploadType { Single, Multiple }; std::optional parseElementIsFileUploadResult(const RefPtr&); void selectOptionElement(const String& elementID, Function&&); void setInputFileUploadFiles(const String& elementID, const String& text, bool multiple, Function&&); void didSetInputFileUploadFiles(bool wasCancelled); enum class MouseInteraction { Move, Down, Up, SingleClick, DoubleClick }; void performMouseInteraction(int x, int y, MouseButton, MouseInteraction, Function&&); enum class KeyboardInteractionType { KeyPress, KeyRelease, InsertByKey }; struct KeyboardInteraction { KeyboardInteractionType type { KeyboardInteractionType::InsertByKey }; std::optional text; std::optional key; }; enum KeyModifier { None = 0, Shift = 1 << 0, Control = 1 << 1, Alternate = 1 << 2, Meta = 1 << 3, }; String virtualKeyForKey(UChar, KeyModifier&); void performKeyboardInteractions(Vector&&, Function&&); struct InputSourceState { enum class Type { Null, Key, Pointer }; Type type; String subtype; std::optional pressedButton; std::optional pressedKey; HashSet pressedVirtualKeys; }; InputSourceState& inputSourceState(const String& id); std::unique_ptr m_host; double m_scriptTimeout; double m_pageLoadTimeout; double m_implicitWaitTimeout; std::optional m_toplevelBrowsingContext; std::optional m_currentBrowsingContext; std::optional m_currentParentBrowsingContext; HashMap m_activeInputSources; HashMap m_inputStateTable; }; } // WebDriver