In the previous article, we introduced the automated test environment for Selenium Java. I hope that everyone's JDK and Eclipse are installed.
Because it is scripting Selenium in Java, it is necessary to supplement the most basic Java knowledge.
When many test engineers hear programming languages, especially Java, they tend to be afraid and contradictory. It feels too difficult, I can't learn!
In addition to psychological factors, the main reason is that if our test engineers learn the language separately, there is very little opportunity to participate in the development of the project in practical work, so that learning can not be used, no need will never In-depth understanding, I always feel that it is not well mastered.
But if you use Selenium to learn the Java language, you will find that the Java language is not difficult. The Java knowledge you learned in the whole process is used. It is used to solve various problems in automation. The understanding is profound, the code knocks more, and naturally it is mastered, soSelenium and Java learning are mutually reinforcing roles. Finally, Selenium has also learned, and Java has mastered it.
Moreover, after learning Java, not only can it be used in Selenium's Web-based automated testing, but also many places can be applied, such as the automatic testing of mobile app, Appium, interface testing, etc., will also greatly help the professional development of test engineers. .
Step 1: Create a Java project
Open Eclipse and click on File--New--Java Project
Enter the name of the project javabasic (all lowercase letters)
Note: The naming rules for java will be explained in the following articles.
Step 2: Create a .java file
Expand the project, select the src folder, select New--Class from the context menu.
Name the .java file: HelloWorld
Each of our automated test cases will be a .java file in the future.
Step 3: Add the HelloWorld.java content to the following complete content
Step 4: Run this java file
Select this java file and select Run as--Java Application from the context menu.
After running, you will see the printout of Hello Wrold on the console! Text information, this is the result of the program running.
Congratulations on our first java program running successfully!

1. class HelloWorld { ..... }
In Java, the beginning of each .java file is defined by a class or class. The class is the java keyword used to declare the class, and HelloWorld is the name of the class.
The part inside the braces is the concrete implementation of this class, which is generally written about related properties and methods.
The concepts of these classes, objects, methods, etc. will be explained later. Now everyone just needs to remember,Every java file needs to define a class. The name of this class HelloWorld is the same as the name of the corresponding .java file., ie HelloWorld.java
2. public static void main(String[] args) { ...... }
This is a key point we have to master in this article.Is the main method in the class.
Now everyone just needs to remember that the main method is written in a fixed way. Public, static, void These are also java keywords. We will learn slowly in the following articles.
The key point we have to master here isThe main method is the execution entry or starting point of the java program.The java program will first find the main method when executing, and then execute the main method body in the order from top to bottom, that is, the program statement corresponding to the braces { ... }. If the main method in the java file is removed, then this Java programs can not run independently, that is, the right can not run as--java application, you can try, because the compiler can not find the entrance, do not know where to start execution.
Another important point to be aware of about the main method is thatWhen the java program is executed, only the main method body, that is, the statement corresponding to the braces, is executed, and the statements outside the method are not executed.
For example, the following example adds a new one after the main method.seleniumMethod to output hello selenium!
If executed, you will find that the console still only outputs Hello World!
It is because the selenium method is not in the body of the main method and is not executed.
3.System.out.println("Hello World!");
This is the program statement in the body of the method. Every java statement needs to end in English ";".
The purpose of this statement is to print out Hello World in the console line break! text information.
This java statement is often used when we do automation, such as the title of the printout jump page, the content input by the text box obtained by the printout, and so on.
Ok, this is our first java applet. Is it particularly simple?
Learn to program more code, we will knock it together with our first java program!
****************************************************************************************************
I will continue to update Selenium Java related articles recently, and please pay attention to me.Video course
The latest, most complete, most cost-effective, and continuously updated automated test course on the entire network
*****************************************************************************************************
Hello World Just built a folder New Java file File suffix name .java Hello.java [Notes] The system may not display the file suffix name, need to be opened manually Write code Compile the Javac Java fi...
First Java program Output hello world !!...
Hello world Create a new folder, store the code New Java file File suffix name .java egļ¼Hello.java Note: The system may hide the suffix name, need to manually open Write code Compile: Javac Java file,...
Hello World Enter the first program of the Java world Hello, World! The ceremony of the program. In the Desktop New Folder (NOTO), create a subfolder (code) and establish a text in a subfile. (The fil...
Install the JDK and Java integrated development environment Eclipse, our Java learning trip is officially started. As a step in this journey, let us get the first Java program - "Hello World"...
Non-hello, world, non-hello, world, non-hello, world Important things say three times No more nonsense, directly on the code That's right, to get into Java, the first thing we should say hello is Java...
/* The variable must be declared, assigned, and used. variable can only be valid in its scope, leaving range is invalid is not allowed to generate 2 names with the same name in the same scope. */...
classPath (can execute .class file anywhere If the classPath is not configured, it will automatically go to the current directory to find the bytecode of the specified name. If the classPath is config...
Learning any language, the first program is hello world. Just beginning to learn java junior partner, I suggest writing code in Notepad so you can lay a better foundation for the next. First create a ...
Under eclipse and other development tools are packed situation. java project java engineering means After Next, fill in the project name here Click finish After filling, meaning complete Then cre...