Vii. tool class, Thread monitor class creation
Utils package, create Java class: Remotethreadstatusmonitor.java
Package com.lingfeng.utils;/** * This monitor method is important, and if not, causes the JVM to exit and all remotely working threads to throw an exception. * @author Ling Feng * */public class Remotethreadstatusmonitor implements Runnable {private String drivername;private Thread thre ad;private static int deadthreadcount = 0;//records the number of threads that have ended. public static int Getdeadthreadcount () {return deadthreadcount;} Public remotethreadstatusmonitor (String drivername,thread thread) {this.drivername=drivername;this.thread = thread;} @Overridepublic void Run () {//determines if the thread is still alive while (Thread.isalive ()) {}deadthreadcount++; System.out.println (drivername+ "Run End");}}
It contains the printed debug code, which can be removed by itself
Eight, test code, remote services open Baidu home Selenium code
Create Java class in Staticpage package: Remoteserveropenhomepage
Package Com.lingfeng.staticpage;import Org.openqa.selenium.by;import Org.openqa.selenium.webdriver;import Com.lingfeng.utils.remoteserverinit;public class Remoteserveropenhomepage implements Runnable {private Webdriver driver;//This method is used to store the startup name of the browser, which is used for subsequent scripts with the bug's name setting, and so on. Private String drivername;public remoteserveropenhomepage (webdriver driver,string drivername) {this.driver = driver; This.drivername=drivername;} /** * Overrides the Run method, and all the portals that need to run the script can be written in this method for multi-threaded invocation. */@Overridepublic void run () {int i = 1;while (i<=3) {String URL = remoteserverinit.gethomepage ();d river.get (URL); Driver.findelement (By.id ("kw")). SendKeys ("haha");d river.findelement (by.id ("su")). Click (); System.out.println (drivername+ "=====" +i+ "second Start"); i++;} Driver.close ();}}
The two classes in this blog post are all the classes that create multithreading, the monitoring thread in the first article, and the running thread, which can be removed by the printed debug code itself.
Not to be continued!!! Come on NOW!!!
Selenium multi-threaded startup grid Distributed test framework package (III)