Title is a bit long, mainly write a bat out to play,
(1) Do not manually shut down the MySQL service every time (I do not want to set it to manually start, obsessive-compulsive disorder)
(2) Then expect VMware to automatically connect to the virtual machine every time
(3) and each Xshell can be started automatically, and then connected to the virtual machine
(4) Then the campus network every time to open, enter the account password or something, in order to connect the net, I hope it is done by itself
It's a bit of a point to finish these steps, mostly the browser or the Web, and then the Eclipse project is packaged into an executable jar package.
Now listen to me!
The purpose ahead is not associated with subsequent commands.
(1) First close MySQL service in bat
The shutdown of this MySQL service is simple, but it is performed as an administrator, otherwise it will be denied access.
net stop MySQL
This step is still relatively simple.
(2) There are two ways to start a virtual machine in CMD and let it open an operating system, one of which is
"D:\Program Files (x86) \VMware\VMware Workstation\vmware.exe"-X "F:\Virtual Machines\centos_64_minimal\centos 64 bit. VMX "
This way you can open the virtual machine, but it has to be, but it's open with a graphical interface, and it says that if you don't turn off the GUI, the command will always be in the execution state.
This is not good, you fly over Xiang still squatting here, not too suitable, so this is not good, then have to use the following one:
"D:\Program Files (x86) \vmware\vmware Workstation\vmrun.exe" Start "F:\Virtual Machines\centos_64_minimal\centos 64 bit. VMX "Nogui
The advantage of starting this way is not to open the graphical interface, directly in the background to start VMware, and open the corresponding operating system, and the execution of this sentence can immediately execute the next sentence.
(3) Time delay under CMD
After starting VMware and its corresponding operating system, we can not directly use the Xshell to connect the virtual machine, should be for the virtual machine to take a certain amount of time, so we need to delay 40~60s clock, this depends on the configuration of the personal computer, the use of the statement is:
Ping-n 127.0.0.1 > nul
In fact, I also did not expect to use ping this command to delay,-N after the 60 for ping this command 60 times or 60 seconds
> nul is not output ping results, never thought you actually is this ping
(4) Xshell connecting virtual machines
Start "" "D:\Program Files (x86) \netsarang\xshell 5\xshell.exe"-url ssh://jack:[email protected]:22
This command can be used to directly connect the virtual machine with Xshell in CMD, and after opening the Xshell graphical interface, CMD will not be stuck in this command
Where Jack is a user name for my virtual machine
And Rose is the code.
192.168.197.129:22 in 192.168.197.129 is the IP address of the virtual machine, and then 22 is the port number this does not change, just need your user password on the line
(5) Directly fill in the campus Network account password and drive the browser login
This is a more complex part, if the open Web page is not connected, then the browser will jump to the login interface,
Originally, the Campus network account password is to remember, this time just run a JS to execute the login click () is good,
Before the practice is to use CMD directly with Chrome.exe to open Baidu, and then chrome inside will have a plug-in, automatically execute JS
"C:\Program Files (x86) \google\chrome\application\chrome.exe" www.baidu.com
This sentence in cmd execution will make chrome open Baidu, then automatically execute the plugin
These are all the contents of the plugin, put it in a folder called HelloWorld, and add the plugin to Chrome.
1.png is a picture of Hyun as an icon.
Then Manifest.json is the main program of the plugin
{ "name": "First Chrome plugin", "Manifest_version": 2, "version": "1.0", "description": "My first chrome plugin, Not bad ", " Browser_action ": { " Default_icon ":" 1.png " }, " content_scripts ": [ { " matches ": [" http://192.168.0.1/* "], " JS ": [" Myscript.js "] } ]}
This extension is also very simple, where "matches": [http://192.168.0.1/*], which means if it matches the URL
Then execute the following JS inside the content, IP is I make up, our school's IP How can tell you, needs bark!
The contents of the Myscript.js are:
void (function () {document.getElementById ("LoginName"). Value = "+";d Ocument.getelementbyid ("password"). Value = " 119 ";d Ocument.getelementbyid (" Action_login "). Click ();}) ())
This JS is also very simple, just fill in the account password, then, is to execute the login button.
In fact, this practice is also possible, but the key is that I am a have feelings (obsessive-compulsive disorder), such a browser to log on to the campus network account can not automatically shut down, I can't stand it.
Then under CMD can not let Chrome automatically quit, can only forcibly shut down the process, forced to shut down the process, chrome after this open will jutting DAO, what abnormal shutdown blabla
So the road is not going to get through. Let's find another way.
A magical approach came out, the so-called automated test.
The first tool to use is two: one is selenium, the other is Chromedriver_x64.exe
Where Chromedriver_x64.exe is used to drive the Chrome browser,
and selenium I do not know is to do, anyway, you look down.
First download the selenium, then unzip, the jar inside is to call the
Then download chromedriver_x64 and put it in the directory where Chrome.exe is located, mine is in:
C:\Program Files (x86) \google\chrome\application\chrome.exe
The first version of the program is:
Package Com.test.bat;import Org.openqa.selenium.javascriptexecutor;import Org.openqa.selenium.webdriver;import Org.openqa.selenium.chrome.chromedriver;public class Drivechrome {public static void main (string[] args) {//TODO Auto-generated method stub//Sets the path to access Chromedriver System.setproperty ("Webdriver.chrome.driver", "C:\\Program Files" ( x86) \\Google\\Chrome\\Application\\chromedriver_x64.exe "); Webdriver Driver = new Chromedriver ();d river.get ("http://www.baidu.com/");//"http://192.168.0.1/srun_portal.php?" Cmd=login&switchip= "is used to determine whether the Campus network login page//is the login page then we will execute JS, otherwise do not execute if (Driver.getcurrenturl (). StartsWith (" http:// 192.168.0.1/srun_portal.php?cmd=login&switchip= ")) {//system.out.println (Driver.gettitle ());// System.out.println (Driver.getcurrenturl ()); Javascriptexecutor JSE = (javascriptexecutor) driver;jse.executescript ("document.getElementById (\" Loginname\ "). Value = \ "120\"); Jse.executescript ("document.getElementById (\" password\ "). Value = \" 119\ ""); Jse.executescript (" Document.getelemenTbyid (\ "action_login\"). Click () "); Driver.quit (); return;}}
This requires you to unzip the selenium under the 2 jar package and unzip the folder under the Lib folder of the jar are imported into the Java project,
In fact, this is not a problem, you can log in or close the Chrome browser, but, but also, the Chromedriver_x64.exe drive Chrome browser This process has been
It is easy to kill the process directly in CMD at our place, but the people who do the test say it's not going to work, but this chromedriver_x64.exe is always called when testing.
And finally, in this code, turn it off!
The following version was born:
Package Com.test.bat;import Java.io.file;import Java.io.ioexception;import org.openqa.selenium.JavascriptExecutor; Import Org.openqa.selenium.webdriver;import Org.openqa.selenium.webdriverexception;import Org.openqa.selenium.chrome.chromedriverservice;import Org.openqa.selenium.remote.desiredcapabilities;import Org.openqa.selenium.remote.remotewebdriver;import Org.openqa.selenium.support.ui.expectedcondition;import Org.openqa.selenium.support.ui.webdriverwait;public class Startchrome {public static void main (string[] args) { Chromedriverservice service = new Chromedriverservice.builder (). usingdriverexecutable (New File ("C:\\Program Files" ( x86) \\Google\\Chrome\\Application\\chromedriver_x64.exe "). Usinganyfreeport (). build (); try {service.start (); SYSTEM.OUT.PRINTLN ("Test");} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();} Webdriver Driver = new Remotewebdriver (Service.geturl (), Desiredcapabilities.chrome ());//Webdriver Driver = new Chromedriver ();d river.get ("http://www.baidu.com/"),//System.out.println (Driver.getcurrenturl ()),//By judging the title content waiting for the search page to load, the interval of 10 seconds try {(new Webdriverwait (Driver)). Until (new expectedcondition<boolean> () {public Boolean apply (Webdriver D) {return D.gettitle (). toLowerCase (). StartsWith ("User Login");}); catch (Webdriverexception e) {driver.quit (); Service.stop (); return;} if (Driver.getcurrenturl (). StartsWith ("http://192.168.0.1/srun_portal.php?cmd=login&switchip=")) {// System.out.println (Driver.gettitle ());//system.out.println (Driver.getcurrenturl ()); Javascriptexecutor JSE = (javascriptexecutor) driver;jse.executescript ("document.getElementById (\" Loginname\ "). Value = \ "120\"); Jse.executescript ("document.getElementById (\" password\ "). Value = \" 119\ ""); Jse.executescript (" document.getElementById (\ "action_login\"). Click () "); Driver.quit (); Service.stop (); return;}}
What about here? The execution of Chromedriver_x64.exe can be controlled,
Service.start ();
Service.stop ();
These two sentences can solve the open and close of the chromedriver_x64.exe process, and this also adds the wait in the browser loading process
And then, to package this project, I packaged the executable jar package in Eclipse.
The command to invoke this executable jar package is:
Java-jar C:\Users\PC126\Desktop\hahaha.jar
Finally although can close chromedriver_x64 this process, but will leave Conhost.exe this process, this process had to delete in cmd inside
The final bat is:
Echo This is a rare comment, in fact I was in the nonsense, in order to multi-dot the word net stop MySQL "D:\Program Files (x86) \vmware\vmware Workstation\vmrun.exe" Start "f:\ Virtual Machines\centos_64_minimal\centos 64-bit. VMX "Noguiping-n 127.0.0.1echo ping-n 127.0.0.1 > Nulstart" "D:\Program Files (x86) \netsarang\xshell 5\xshell.exe" -url ssh://jack:[email Protected]:22java-jar C:\Users\ Pc126\desktop\hahaha.jar "D:\Program Files (x86) \tencent\qq\bin\qq.exe" taskkill/f/t/im Conhost.exe
This article is purely fun
Start VMware in cmd, Xshell connect virtual machine and control Chrome browser to automatically execute JS Login Campus Network