Scenario: When writing a method, there are 1 parameters with 3 values, and the parameter type is an array. For example: AAA|BBB|CCC. And we need to loop the printing, this time we need to use the array loop output method.
One: feature example
When I click on menu Time management > Leave balance > leave balance set up from HCM page0006 for nal| sl2| ol|
Two: steps Example:
@Then ("^i Select Leavecode for (. +) $") publicvoidthrows throwable { Vp.selectleavecodefor (Leavecode); }
Three: Page Example:
/*** Leave balance set menu to filter multiple leave types. * @paramLeavecode *@throwsException*/ Public voidSelectleavecodefor (String Leavecode)throwsException {waitFor (By.xpath ("//span[@id = ' Divleavecodesshowwindow ']") . Click (); String[] Array= Leavecode.split ("\\|"); for(inti = 0; i < Array.Length; i++) {String XPath= "//tr[./td[text () = '" + array[i] + "']]/td[1]/input"; WaitFor (By.xpath (XPath)). Click (); } waitloading (); WaitFor (By.xpath ("//input[@id = ' Confirmdivleavecodesselection ' [@value = ' Confirm ']") . Click (); WaitFor (By.xpath ("//a[@id = ' btnsearch ']/i") . Click (); Waitloading (); }
Scene Map:
:
Four: Split common use method
There is a String.Split () method in the Java.lang package, which returns an array
I use in the application of some, to summarize for you, for your reference only:
1. If you use "." As a separate word, it must be written as follows, String.Split ("\ \"), so that the correct separation can not be used String.Split (".");
2. If you use "|" As a separate word, must be the following wording, String.Split ("\\|"), so that the correct separation, can not be used String.Split ("|");
“.” and "|" is an escape character and must be added "\ \";
3. If you have more than one delimiter in a string, you can use the ' | ' As a hyphen, for example, "Acount=?" and UU =? Or n=? ", the three are separated out, you can use String.Split (" And|or ");
When you use the String.Split method to separate strings, separators may not get the results we expect if they use some special characters.
We look at the JDK Doc description
Public string[] Split (String regex)
Splits this string around matches of the given regular expression.
Parameter regex is a regular-expression matching pattern instead of a simple string, and he may have unexpected results for some special characters, such as testing the following code with a vertical bar | Delimited string, you will not get the expected result
For example the situation A:AAA|BBB|CCC
string[] aa = "AAA|BBB|CCC". Split ("\\|" ); This will get the correct result for (int i = 0; I <aa.length; i++ ) { System.out.println ("--" +
7>aa[i]);
such as B:AAA*BBB*CCC
string[] aa = "AAA|BBB|CCC". Split ("\\*") to get the correct result for (int i = 0; I <aa.length; i+ + ) { System.out.println ("--" +aa[i]); }
How Java loops an array and uses split