All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ai.platon.pulsar.skeleton.crawl.fetch.driver.JvmWebDriver.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package ai.platon.pulsar.skeleton.crawl.fetch.driver

import ai.platon.pulsar.browser.common.BrowserSettings
import ai.platon.pulsar.browser.driver.chrome.NetworkResourceResponse
import ai.platon.pulsar.common.math.geometric.PointD
import ai.platon.pulsar.common.math.geometric.RectD
import org.jsoup.Connection
import java.time.Duration
import java.util.*
import java.util.concurrent.CompletableFuture

/**
 * [JvmWebDriver] defines a concise interface to visit and interact with web pages,
 * all actions and behaviors are optimized to mimic real people as closely as possible,
 * such as scrolling, clicking, typing text, dragging and dropping, etc.
 *
 * [JvmWebDriver] is programmatically generated from the [WebDriver] class and is designed to
 * help handle [WebDriver] tasks in other JVM languages such as java, clojure, scala, and so on,
 * which had difficulty handling kotlin suspend methods.
 *
 * @see [WebDriver]
 */
interface JvmWebDriver {

    /**
     * Adds a script which would be evaluated in one of the following scenarios:
     *
     * * Whenever the page is navigated.
     *
     * The script is evaluated after the document was created but before any of
     * its scripts were run. This is useful to amend the JavaScript environment, e.g.
     * to seed [Math.random].
     *
     * @param script Javascript source code to add.
     * */
    @Throws(WebDriverException::class)
    fun addInitScriptAsync(script: String): CompletableFuture
    /**
     * Blocks URLs from loading.
     *
     * @param urls URL patterns to block. Wildcards ('*') are allowed.
     * @return the new CompletableFuture
     */
    @Throws(WebDriverException::class)
    fun addBlockedURLsAsync(urls: List): CompletableFuture
    /**
     * Returns the main resource response. In case of multiple redirects, the navigation
     * will resolve with the first non-redirect response.
     *
     * @param url URL to navigate page to.
     * @return the new CompletableFuture
     */
    @Throws(WebDriverException::class)
    fun navigateToAsync(url: String): CompletableFuture

    /**
     * Returns the response of the main resource. In case of multiple redirects, the navigation will resolve
     * with the first non-redirect response.
     *
     * @param entry NavigateEntry to navigate page to.
     * @return the new CompletableFuture
     */
    @Throws(WebDriverException::class)
    fun navigateToAsync(entry: NavigateEntry): CompletableFuture

    @Throws(WebDriverException::class)
    fun setTimeoutsAsync(browserSettings: BrowserSettings): CompletableFuture

    /**
     * Returns a string representing the current URL that the browser is looking at.
     *
     * @return The URL of the page currently loaded in the browser
     */
    @Throws(WebDriverException::class)
    fun currentUrlAsync(): CompletableFuture

    /**
     * Returns the source of the last loaded page. If the page has been modified after loading (for
     * example, by Javascript) there is no guarantee that the returned text is that of the modified
     * page.
     *
     * @return The source of the current page
     */
    @Throws(WebDriverException::class)
    fun pageSourceAsync(): CompletableFuture

    @Throws(WebDriverException::class)
    fun getCookiesAsync(): CompletableFuture>>

    /**
     * Brings page to front (activates tab).
     */
    @Throws(WebDriverException::class)
    fun bringToFrontAsync(): CompletableFuture
    /**
     * Returns when element specified by selector satisfies {@code state} option.
     * */
    @Throws(WebDriverException::class)
    fun waitForSelectorAsync(selector: String): CompletableFuture
    /**
     * Returns when element specified by selector satisfies {@code state} option.
     * Returns the time remaining until timeout.
     * */
    @Throws(WebDriverException::class)
    fun waitForSelectorAsync(selector: String, timeoutMillis: Long): CompletableFuture
    @Throws(WebDriverException::class)
    fun waitForSelectorAsync(selector: String, timeout: Duration): CompletableFuture
    @Throws(WebDriverException::class)
    fun waitForNavigationAsync(oldUrl: String): CompletableFuture
    @Throws(WebDriverException::class)
    fun waitForNavigationAsync(oldUrl: String, timeoutMillis: Long): CompletableFuture
    @Throws(WebDriverException::class)
    fun waitForNavigationAsync(oldUrl: String, timeout: Duration): CompletableFuture

    @Throws(WebDriverException::class)
    fun existsAsync(selector: String): CompletableFuture
    @Throws(WebDriverException::class)
    fun isHiddenAsync(selector: String): CompletableFuture
    @Throws(WebDriverException::class)
    fun isVisibleAsync(selector: String): CompletableFuture
    @Throws(WebDriverException::class)
    fun visibleAsync(selector: String): CompletableFuture
    @Throws(WebDriverException::class)
    fun isCheckedAsync(selector: String): CompletableFuture

    @Throws(WebDriverException::class)
    fun typeAsync(selector: String, text: String): CompletableFuture
    @Throws(WebDriverException::class)
    fun clickAsync(selector: String) = clickAsync(selector, 1)
    @Throws(WebDriverException::class)
    fun clickAsync(selector: String, count: Int): CompletableFuture
    @Throws(WebDriverException::class)
    fun clickMatchesAsync(selector: String, pattern: String) = clickMatchesAsync(selector, pattern, 1)
    @Throws(WebDriverException::class)
    fun clickMatchesAsync(selector: String, pattern: String, count: Int): CompletableFuture
    @Throws(WebDriverException::class)
    fun clickMatchesAsync(selector: String, attrName: String, pattern: String) = clickMatchesAsync(selector, attrName, pattern, 1)
    @Throws(WebDriverException::class)
    fun clickMatchesAsync(selector: String, attrName: String, pattern: String, count: Int): CompletableFuture
    @Throws(WebDriverException::class)
    fun clickNthAnchorAsync(n: Int, rootSelector: String = "body"): CompletableFuture
    @Throws(WebDriverException::class)
    fun checkAsync(selector: String): CompletableFuture
    @Throws(WebDriverException::class)
    fun uncheckAsync(selector: String): CompletableFuture

    @Throws(WebDriverException::class)
    fun scrollToAsync(selector: String): CompletableFuture
    @Throws(WebDriverException::class)
    fun scrollDownAsync(count: Int = 1): CompletableFuture
    @Throws(WebDriverException::class)
    fun scrollUpAsync(count: Int = 1): CompletableFuture
    @Throws(WebDriverException::class)
    fun scrollToTopAsync(): CompletableFuture
    @Throws(WebDriverException::class)
    fun scrollToBottomAsync(): CompletableFuture
    @Throws(WebDriverException::class)
    fun scrollToMiddleAsync(ratio: Float): CompletableFuture
    @Throws(WebDriverException::class)
    fun mouseWheelDownAsync(count: Int = 1, deltaX: Double = 0.0, deltaY: Double = 150.0, delayMillis: Long = 0): CompletableFuture
    @Throws(WebDriverException::class)
    fun mouseWheelUpAsync(count: Int = 1, deltaX: Double = 0.0, deltaY: Double = -150.0, delayMillis: Long = 0): CompletableFuture
    @Throws(WebDriverException::class)
    fun moveMouseToAsync(x: Double, y: Double): CompletableFuture
    @Throws(WebDriverException::class)
    fun dragAndDropAsync(selector: String, deltaX: Int, deltaY: Int = 0): CompletableFuture

    @Throws(WebDriverException::class)
    fun outerHTMLAsync(selector: String): CompletableFuture

    @Throws(WebDriverException::class)
    fun selectFirstTextOrNullAsync(selector: String): CompletableFuture
    @Throws(WebDriverException::class)
    fun selectFirstTextOptionalAsync(selector: String): CompletableFuture>
    @Throws(WebDriverException::class)
    fun selectTextAllAsync(selector: String): CompletableFuture>

    @Throws(WebDriverException::class)
    fun selectFirstAttributeOrNullAsync(selector: String, attrName: String): CompletableFuture
    @Throws(WebDriverException::class)
    fun selectFirstAttributeOptionalAsync(selector: String, attrName: String): CompletableFuture>
    @Throws(WebDriverException::class)
    fun selectAttributeAllAsync(selector: String, attrName: String): CompletableFuture>
    /**
     * Executes JavaScript in the context of the currently selected frame or window. The script
     * fragment provided will be executed as the body of an anonymous function.
     *
     * @param expression Javascript expression to evaluate
     * @return Remote object value in case of primitive values or JSON values (if it was requested).
     * */
    @Throws(WebDriverException::class)
    fun evaluateAsync(expression: String): CompletableFuture

    /**
     * This method scrolls element into view if needed, and then ake a screenshot of the element.
     */
    @Throws(WebDriverException::class)
    fun captureScreenshotAsync(selector: String): CompletableFuture
    @Throws(WebDriverException::class)
    fun captureScreenshotAsync(rect: RectD): CompletableFuture

    /**
     * Calculate the clickable point of an element located by [selector].
     * If the element does not exist, or is not clickable, returns null.
     * */
    @Throws(WebDriverException::class)
    fun clickablePointAsync(selector: String): CompletableFuture
    /**
     * Return the bounding box of an element located by [selector].
     * If the element does not exist, returns null.
     * */
    @Throws(WebDriverException::class)
    fun boundingBoxAsync(selector: String): CompletableFuture
    /**
     * Create a new Jsoup session with the last page's context, which means, the same
     * headers and cookies.
     * */
    @Throws(WebDriverException::class)
    fun newJsoupSessionAsync(): CompletableFuture
    /**
     * Load url as a resource without browser rendering, with the last page's context,
     * which means, the same headers and cookies.
     * */
    @Throws(WebDriverException::class)
    fun loadResourceAsync(url: String): CompletableFuture
    /**
     * Force the page pauses all navigations and PENDING resource fetches.
     * If the page loading stops, the user can still interact with the page,
     * and therefore resources can continue to load.
     * */
    @Throws(WebDriverException::class)
    fun pauseAsync(): CompletableFuture
    /**
     * Force the page stop all navigations and RELEASES all resources. Interaction with the
     * stop page results in undefined behavior and the results should not be trusted.
     *
     * If a web driver stops, it can later be used to visit new pages.
     * */
    @Throws(WebDriverException::class)
    fun stopAsync(): CompletableFuture
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy