In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Train of thought:
1. Create a configuration file that writes "name of element = method of location > id/name/xpath expression of element", for example: "locator=name > login"
2. Create a class ProUtilTest that reads the configuration file, and use the Properties class in java to read the configuration file of Java
3. To determine the way of positioning, use the split () method to extract "name" and "login" from "locator=name > login".
4. Judge the positioning method taken by the split () method, and return the corresponding By type, which is used for the subsequent positioning elements.
5. Continue to learn and improve.
/ * * tool class for determining location mode * /
Public class GetByLoctorTest {
/ * *
* read the configuration file
* @ param key String positioning method
* * /
Public static By getLocator (String key) {
/ / the ProUtilTest class reads the configuration file (see figure below). When using the constructor, you need to pass in the path of the configuration file.
/ / the path to the file can be configured by writing a separate class.
ProUtilTest properties = new ProUtilTest ("configs/login.properties")
/ / read the corresponding configuration object from the property configuration file
/ / the configuration file is written in the format "locator=name > login"
String locator = properties.getPro (key)
/ / the locatorType variable exists for the positioning type in the configuration object, and the value of the positioning expression is stored in the locatorValue variable.
/ / [0] is the left side of > [1] is the right side of >
String locatorType = locator.split (">") [0]; / take out the name before >
String locatorValue = locator.split (">") [1]; / / check out and log in
/ / output locatorType variable value and locatorValue variable value to verify whether the assignment is successful
System.out.println ("location type acquired:" + locatorType+ "location expression obtained:" + locatorValue)
/ / based on the content of the variable value of locatorType, what kind of By object is returned?
The / / toLowerCase () method is used to convert a string to lowercase
If (locatorType.toLowerCase () .equals ("id")) {
Return By.id (locatorValue)
} else if (locatorType.toLowerCase () .equals ("name")) {
Return By.name (locatorValue)
} else if ((locatorType.toLowerCase (). Equals ("classname")) | | (locatorType.toLowerCase () .equals ("class") {
Return By.className (locatorValue)
} else if ((locatorType.toLowerCase (). Equals ("tagname")) | | (locatorType.toLowerCase () .equals ("tag") {
Return By.className (locatorValue)
} else if ((locatorType.toLowerCase (). Equals ("linktext")) | | (locatorType.toLowerCase () .equals ("link") {
Return By.linkText (locatorValue)
} else if (locatorType.toLowerCase () .equals ("partiallinktext")) {
Return By.partialLinkText (locatorValue)
} else if ((locatorType.toLowerCase (). Equals ("cssselector")) | | (locatorType.toLowerCase () .equals ("css") {
Return By.cssSelector (locatorValue)
} else if (locatorType.toLowerCase () .equals ("xpath")) {
Return By.xpath (locatorValue)
} else {
Try {
Throw new Exception ("the locator type entered is not defined in the program:" + locatorType)
} catch (Exception e) {
E.printStackTrace ()
}
}
Return null
}
}
/ * * configuration file read class * /
Public class ProUtilTest {
Private String filePath
Private Properties prop;//Properties class, which reads the configuration file of Java
Public ProUtilTest (String filePath) {
This.filePath = filePath
This.prop=readProperties ()
}
Public Properties readProperties () {
Properties properties = new Properties ()
Try {
InputStream ins = new FileInputStream (filePath)
BufferedReader bf=new BufferedReader (new InputStreamReader (ins, "utf-8"))
Properties.load (bf)
Ins.close ()
} catch (Exception e) {
/ / TODO Auto-generated catch block
E.printStackTrace ()
}
Return properties
}
/ / containsKey () to determine whether there is a corresponding key
Public String getPro (String key) {
If (prop.containsKey (key)) {
Return prop.getProperty (key)
} else {
System.out.println ("acquired key does not exist")
}
Return ""
}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.