Selenium multi-threaded startup grid Distributed test framework package (II)

Source: Internet
Author: User

V. Domain class creation

Create a class in the domain package: Remotelanchinfo.java is used to save the startup information.

Package Com.lingfeng.domain;public class Remotelanchinfo {private string Id;private string Name;private string address; Public String GetId () {return ID;} public void SetId (String id) {this.id = ID;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;} Public String getaddress () {return address;} public void setaddress (String address) {this.address = address;}}

This javabean is used to save the boot information in a configuration file, which will be encapsulated into the collection later, it is convenient to call when it comes to this information, such as encountered IE6 which page is incompatible, you can use the name to do the file naming, This will tell you which browser is out of the question.

VI. Tools class, remote service profile initialization class

Create the Java class in the Utils package Remoteserverinit.java

Package Com.lingfeng.utils;import Java.io.file;import Java.net.malformedurlexception;import java.net.URL;import Java.util.arraylist;import java.util.hashmap;import java.util.iterator;import Java.util.List;import java.util.Map; Import Org.dom4j.document;import Org.dom4j.documentexception;import Org.dom4j.element;import Org.dom4j.io.saxreader;import Org.openqa.selenium.webdriver;import Org.openqa.selenium.remote.desiredcapabilities;import Org.openqa.selenium.remote.remotewebdriver;import com.lingfeng.domain.remotelanchinfo;/** * Remote Server initialization class * @author Ling * */public class Remoteserverinit {//store read configuration document Private STA Tic Document document;//stores all remote server-side information with the state on the private static map<string,remotelanchinfo> Alllaunchinfomap = new Hashmap<string,remotelanchinfo> ();//store all remote server Browser-initiated driverprivate static map<string,webdriver> Alllaunchdrivermap = new hashmap<string, webdriver> ();//After calling the Launchbrowser method, this method can be used to obtain the driverpublic to all remote server Static map<string,webdriver> Getalllaunchdrivermap () {return alllaunchdrivermap;} After calling the Launchbrowser method, this method can be used to obtain boot information to all remote server ends. public static map<string,remotelanchinfo> Getalllaunchinfomap () {return alllaunchinfomap;} public static void Launchbrowser () throws Documentexception, malformedurlexception{file file = new file ("src/ Remoteserverlaunchinfo.xml ");D ocument = readinitfile (file); list<element> servers = getallremoteservers (DOCUMENT);iterator<element> it = Servers.iterator (); while ( It.hasnext ()) {addwebdriver (alllaunchdrivermap,it);}} /** * Store the startup information and the corresponding driver in the respective map collection * * @param alllaunchdrivermap * @param it * @throws malformedurlexception */private s tatic void Addwebdriver (map<string, webdriver> Alllaunchdrivermap, iterator<element> it) throws malformedurlexception {Element e = It.next (); String remoteaddress = E.gettext (); String Remoteid = E.attributevalue ("ID"); String remotename = e.attributevalue ("name");//stores all information that is started in JavaBean. Remotelanchinfo info = setremotelanchinfo (remoteaddress,remoteid,remotename); alllAunchinfomap.put (remotename, info);//start-up information is placed in the map collection desiredcapabilities desiredcapabilities = Desiredcapabilities.internetexplorer (); Webdriver Driver = new Remotewebdriver (new URL (remoteaddress), desiredcapabilities); Alllaunchdrivermap.put ( RemoteName, driver);} /** * Set remote boot information as an object saved to the Map collection * @param remoteaddress * @param remoteid * @param remotename * @return Remotelanchinfo Remote Boot information */private static remotelanchinfo setremotelanchinfo (String remoteaddress,string Remoteid, string remotename) { Remotelanchinfo info = new Remotelanchinfo (); info.setaddress (remoteaddress); Info.setid (Remoteid); Info.setName ( RemoteName); return info;} public static String Gethomepage () {return document.getrootelement (). Elementtext ("homepage");} /** * Stores remote-server tag objects in all profiles into the list collection * @param document * @return List<element> stores a collection of Remote-server tag objects. */private static list<element> getallremoteservers (document document) {list<element> servers = new Arraylist<element> (); list<element&Gt List = Document.getrootelement (). Elements ("Remote-server");iterator<element> it = List.iterator (); while ( It.hasnext ()) {element element = (Element) It.next (), if (Element.attributevalue ("status"). Equals ("on")) {Servers.add ( element);}} return servers;} /** * Read config file, return file * @param files * @return document * @throws documentexception */public static document Readinitfile (file File) throws Documentexception {Saxreader reader = new Saxreader (); return reader.read (file);}}

Not to be continued!!! Come on NOW!!!

Selenium multi-threaded startup grid Distributed test framework package (II)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.