Get the App
SLTechnology News&Howtos  ›  Servers  › 

The use of Selenium function in Java

Shulou Source: shulou.com Published: 2022-06-03 05:24:21 09月16日 Update

Environment

This project is developed under MacOS, the tools involved are platform-independent, and should also be applicable to Linux and Windows desktop systems. Before starting this example, make sure that the following tools are installed correctly, updated to the latest version, and configured correctly.

DockerFunFcli

The Fun and Fcli tools rely on docker to simulate the local environment.

For MacOS users, you can use homebrew to install:

Brew cask install dockerbrew tap vangie/formulabrew install funbrew install fcli

For Windows and Linux user installation, please refer to:

Https://github.com/aliyun/fun/blob/master/docs/usage/installation.mdhttps://github.com/aliyun/fcli/releases

After installation, remember to initialize the configuration by executing fun config first.

Note that if you have already installed fun, make sure the version of fun is above 2.10.2.

$fun-- version2.10.1 starts initialization quickly

Use the fun init command to quickly initialize this template project locally.

Fun init vangie/selenium-java-example installation depends on $fun install... Local testing

The test code ChromeDemo is as follows:

Public class ChromeDemo implements StreamRequestHandler {public void handleRequest (InputStream inputStream, OutputStream outputStream, Context context) throws IOException {System.setProperty ("webdriver.chrome.driver", "/ code/chromedriver"); ChromeOptions options = new ChromeOptions (); options.setBinary ("/ code/headless-chromium"); options.addArguments ("--disable-extensions") / / disabling extensions options.addArguments ("--disable-gpu"); / / applicable to windows os only options.addArguments ("--disable-dev-shm-usage"); / / overcome limited resource problems options.addArguments ("--no-sandbox"); / / Bypass OS security model options.addArguments ("--headless"); WebDriver driver = new ChromeDriver (options); driver.get ("https://ide.fc.aliyun.com");") OutputStream.write (("Page title is:" + driver.getTitle () + "\ n") .getBytes (); driver.quit () }} run $mvn package & & fun local invoke selenium...FC Invoke Start RequestId: 68c83b4c-b053-479c-9b0e-9503582ccb56handle user request is com.aliyun.fc.selenium.ChromeDemo::handleRequestcache is null starting ChromeDriver 2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881) on port 20652Only local connections are allowed.Mar 05 locally 2019 11:34:27 AM org.openqa.selenium.remote.ProtocolHandshake createSessionINFO: Detected dialect: OSSPage title is: cloud integrated development environment FC Invoke End RequestId: 68c83b4c-b053-479c-9b0e-9503582ccb56RequestId: 68c83b4c-b053-479c-9b0e-9503582ccb56 Billed Duration: 5265 ms Memory Size: 1998 MB Max Memory Used: 240MB deployment $mvn package & & fun deploy execution $fcli function invoke-s chrome-f selenium Page title is: cloud integrated development environment

Tags: Environment tools development cloud version user integrated development project test configuration code content command platform desktop template system installed reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Microsoft Shulou Information NVidia Shulou Tech Info