Selenium automation-java-encapsulation assertions, selenium-java-
Encapsulated assertions.
1 package com. baidu. www; 2 3 import org. testng. assert; 4/* 5 * encapsulate assertion 6 */7 public class assertion {8 static boolean flog = true; 9 10 public static void verifyassert (Object actual, Object expected) {11 try {12 Assert. assertEquals (actual, expected); 13} catch (Error e) {14 // TODO: handle exception15 flog = false; 16} 17} 18 19 public static void verifyassert (Object actual, object expected, String message) {20 try {21 Assert. assertEquals (actual, expected, message); 22} catch (Error e) {23 // TODO: handle exception24 flog = false; 25} 26 27} 28}
Call method, Judge error, continue execution
1 @ Test 2 public void test1 () {3 System. out. println ("Test Case 1"); 4 int actual; 5 int expected; 6 actual = 1; 7 expected = 2; 8 assertion. flog = true; 9 for (int I = 0; I <3; I ++) {10 System. out. println ("assertions start 1"); 11 assertion. verifyassert (I, expected, "test whether the connections are the same"); 12 System. out. println ("assertion ended"); 13 // The result is tur; to modify 14} 15 Assert. assertTrue (assertion. flog); // The result is changed to flog, error