This article is M3 Career Advent Calendar 2019 Day 13 article. In this article, we will use Selenide, which is a wrapper of Selenium Web Driver, to quickly try out the browser operation.
--People who want to try the automatic operation of the browser for the time being --People who want to write UI tests in Java --People who want to create tools for browser operation
Let's start by preparing the development environment. Use eclispe for the IDE. Download Java Full Edition from https://mergedoc.osdn.jp/ and unzip it to any location.
After unzipping, start eclipse.exe.
Next, create a Gradle project.
Once the project is created, add the following sentence to build.gradle.
testCompile 'com.codeborne:selenide:5.5.1'
This completes the environment preparation.
Since / [project name] /src/test/java/[project name] /LibraryTest.java was created when the Gradle project was finally created, comment out the original process and rewrite it as follows.
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package selenideSample;
import static com.codeborne.selenide.Selenide.*;
import org.junit.Test;
public class LibraryTest {
@Test public void testSomeLibraryMethod() {
// Library classUnderTest = new Library();
// assertTrue("someLibraryMethod should return 'true'", classUnderTest.someLibraryMethod());
open("https://www.yahoo.co.jp/");
}
}
Well, it's finally time to run. Right-click on the LibraryTest.java file and run the JUnit test.
If the execution is successful, you can see that a new chrome is started and the Yahoo screen is displayed. (The browser will close automatically after a certain period of time)
The environment for realizing browser operation on the code has been easily created. This time, I only opened the specified URL, but it is also very convenient because I can write general browser operations such as inputting to a text box, selecting a pull-down, checking a check box, etc. in code. In my work, I use it when creating a large amount of test data from a browser. The Official Reference of selenide is also substantial, so we hope you will take advantage of it.
https://selenide.org/quick-start.html https://qiita.com/tatesuke/items/589e30ab9b3dc7037e26
Recommended Posts