When I study selenium 2 java, I have a function, which needs to test paging, 20 data per page. It's too troublesome to add one by one. The key is to add more than ten data to each page. I simply write a method to automatically add one of my high school grades. Share as follows:
//Add High School Achievements public static void addRecord(WebDriver driver, int num) throws InterruptedException { findElementByIdAndClick(driver, "btn-user");//Click on Personal Center findElementByIdAndClick(driver, "btn-uc-record");//Click on High School Achievements for(int n = 0;n<num;n++){ findElementByIdAndClick(driver, "btnAddRecord");//Click Add Results findElementByIdAndClick(driver, "button-toggle-semester_id");//Clicking semester findElementByXpathAndClick(driver, ".//* [@id='dropdown-semester_id']/li["+getRandomInt(5)+"]/a";//Choose semester findElementByIdAndClick(driver, "button-toggle-exam_id");//Click test findElementByXpathAndClick(driver, ".//* [@id='dropdown-exam_id']/li["+getRandomInt(7)+"]/a";//click on teacher type findElementByIdAndClick(driver, "button-toggle-year");//Click year findElementByXpathAndClick(driver, ".//* [@id='dropdown-year']/li["+getRandomInt(5)+"]/a";//year of choice;" /*Complete the results of each subject in circle here, and synthesize the science subjects. * Id 123, materialized 456, political history and geography 789, synthesized 10, synthesized 11 */ for(int i =1;i<7;i++){ findElementByIdAndClearSendkeys(driver, "input-score"+i, getRandomInt(100)); findElementByIdAndClearSendkeys(driver, "input-total_score"+i, 100); } findElementByIdAndClearSendkeys(driver, "input-additional_score", getRandomInt(10));//Policy bonus findElementByIdAndClearSendkeys(driver, "input-ranking_province", getRandomInt(10000));//Provincial ranking findElementByIdAndClearSendkeys(driver, "input-ranking_city", getRandomInt(1000));//City ranking findElementByIdAndClearSendkeys(driver, "input-ranking_district", getRandomInt(500));//District ranking findElementByIdAndClearSendkeys(driver, "input-ranking_school", getRandomInt(200));//School Ranking findElementByIdAndClearSendkeys(driver, "input-ranking_class", getRandomInt(50));//Class ranking findElementByIdAndClick(driver, "btnSave");//Click save sleep(1); findElementByXpathAndClick(driver, "html/body/div[3]/div[7]/div/button");//Click OK to Save sleep(1); findElementByXpathAndClick(driver, "html/body/div[3]/div[7]/div/button");//Click to Save Successfully } }
Here's my custom way to generate random numbers
//Get random numbers public static int getRandomInt(int num) { return new Random().nextInt(num)+1; }
I recently finished reading a book entitled Loneliness of Prime Numbers, which talks about twin prime numbers, so I want to check the distribution of twin prime numbers. Among them, it is mainly used to calculate the prime number (prime number). After searching, the top ones are all done by the for loop. It feels a little troublesome. In comparison, it still feels that the recursive screening method is used to solve this problem.
Create a new List < Integer > and start at number 0. If the latter can be divided by this number, the change element is removed from the array, and so on. The last thing left is the prime number. The code is as follows:
static void get(List<Integer> list, int tt) { int num = list.get(tt); for (int i = tt + 1; i < list.size(); i++) { if (list.get(i) % num == 0) list.remove(i--); } if (list.size() > ++tt) get(list, tt); }
Then do the difference between the adjacent elements to get the twin prime number (twin prime number), and stick the code to get all the twin prime number (twin prime number) within 10,000:
List<Integer> list = new ArrayList<>(); for (int i = 2; i < 10000; i+=2) { list.add(i); } get(list, 0); for (int i = 0; i < list.size() - 1; i++) { Integer integer = list.get(i); Integer integer1 = list.get(i + 1); if (integer1 - integer == 2) outputData(TEST_ERROR_CODE, "twin primes:", integer + TAB + TAB + integer1); }
Finally, attach an exercise code for bubble sort and insert sort:
public static void ff(int[] data) { for (int i = 0; i < data.length; i++) { for (int j = i; j > 0; j--) { if (data[j] < data[j - 1]) { int num = data[j]; data[j] = data[j - 1]; data[j - 1] = num; } } } output(changeArraysToList(data)); } public static void ff1(int[] data) { for (int i = 0; i < data.length; i++) { for (int j = 0; j < data.length - i - 1; j++) { if (data[j] > data[j + 1]) { int num = data[j]; data[j] = data[j + 1]; data[j + 1] = num; } } } output(changeArraysToList(data)); }
Groovy is a dynamic language based on JVM. I think there are two advantages. First, it is very compatible with java. Most of the time, it can be used directly by changing Groovy's file suffix to java, and vice versa. Most libraries in java, groovy, can be used directly. This also brings another advantage: low learning cost, very low, no problem to get started directly, you can slowly learn groovy different from Java grammar; second: compiler support has become better, now the ide of intellij, in general, has better support for groovy language, writing code is relatively smooth. Various groovy-based framework tools are also slippery, especially Gradle build tools, which are much better than Maven. This paragraph is imposed in order to support the number of characters, and has nothing to do with the content.
Selection of Technical Articles
- One line of java code prints a heart
- Chinese Language Version of Linux Performance Monitoring Software netdata
- Interface Test Code Coverage (jacoco) Scheme Sharing
- Performance testing framework
- How to Enjoy Performance Testing on Linux Command Line Interface
- Graphic HTTP Brain Map
- How to Test Probabilistic Business Interface
- httpclient handles multi-user simultaneous online
- Automatically convert swagger documents into test code
- Five lines of code to build static blogs
- How httpclient handles 302 redirection
- A preliminary study on the testing framework of linear interface based on java
- Tcloud Cloud Measurement Platform
Selection of non-technical articles
- Why choose software testing as a career path?
- Ten Steps to Become a Great Java Developer
- Writing to everyone about programming thinking
- Obstacles to automated testing
- The Problems of Automated Testing
- Tested "Code Immortality" Brain Map
- Seven Steps to Become an Excellent Automated Testing Engineer
- Attitudes of Excellent Software Developers
- How to Execute Functional API Testing Correctly