Best Selenium code snippet using org.openqa.selenium.support.Enum Colors.valueOf
Source:TestCentral.java
...925926 if (accessorPersist.toLowerCase().equals("persist")) {927 testHelper.CreateSectionHeader(AppConstants.indent5 + "[ Start Persisting Calculated Value ]", "", AppConstants.ANSI_CYAN, true, false, true);928 testHelper.UpdateTestResults("Persisting Calculated value: (" + resultNumber + ")", true);929 persistedString = String.valueOf(resultNumber);930 testHelper.CreateSectionHeader(AppConstants.indent5 + "[ End Persisting Calculated Value, but value persisted and usable until end of test file ]", "", AppConstants.ANSI_CYAN, false, false, true);931 } else {932 TestStep testStep = new TestStep();933 testStep.set_command(AppCommands.SendKeys);934 testStep.set_crucial(ts.get_crucial());935 testStep.set_isConditionalBlock(ts.get_isConditionalBlock());936 testStep.set_accessor(accessorPersist);937 testStep.set_actionType("write");938 testStep.set_accessorType(ts.get_accessorType());939 Argument argument = new Argument();940 argument.set_parameter(String.valueOf(resultNumber));941 List<Argument> arguments = new ArrayList<>();942 arguments.add(argument);943 testStep.ArgumentList = arguments;944 PerformAction(testStep, String.valueOf(resultNumber), fileStepIndex);945 }946 }947 }948949 /***************************************************************************************950 * Description: This method retrieves the simple calculation from a page element,951 * parses that calculation text based on the arguments and performs952 * the intended calculation using long data types and if the expected953 * value is present, compares the calculated value to the expected954 * value and reports the success or failure of that comparison.955 * @param ts - Test Step Object containing all related information956 * for the particular test step.957 * @param fileStepIndex - the file index and the step index.958 ***************************************************************************************/959 private void ParseAndCalculateLongController(TestStep ts, String fileStepIndex) {960 int firstIndex, secondIndex, operatorIndex;961 long firstNumber;962 long secondNumber;963 long resultNumber = 0;964 String delimiter, operator;965 String accessorPersist;966 //https://timesofindia.indiatimes.com/poll.cms967 String [] equation;968 delimiter = GetArgumentValue(ts, 0, " ");969 firstIndex = GetArgumentNumericValue(ts, 1, 0);970 secondIndex= GetArgumentNumericValue(ts, 2, 2);971 operatorIndex = GetArgumentNumericValue(ts, 3, 1);972 accessorPersist = GetArgumentValue(ts, 4, "persist");973974 String actual = GetElementText(ts, fileStepIndex);975 if (actual != null && actual.contains(delimiter)) {976 equation = actual.split(delimiter);977 //region {Debugging code testing how decimals affect long conversion}978// equation[firstIndex] = equation[firstIndex] + ".5";979// equation[secondIndex] = equation[secondIndex] + ".8";980// testHelper.DebugDisplay("delimiter = (" + delimiter + ")");981// testHelper.DebugDisplay("firstNumber = equation[" + firstIndex + "] = " + equation[firstIndex]);982// testHelper.DebugDisplay("secondNumber = equation[" + secondIndex + "] = " + equation[secondIndex]);983// testHelper.DebugDisplay("operatorIndex = equation[" + operatorIndex + "] = " + equation[operatorIndex]);984// testHelper.DebugDisplay("accessorPersist = " + accessorPersist);985 //endregion986 firstNumber = !equation[firstIndex].contains(".") ? Long.parseLong(equation[firstIndex]) : Long.parseLong(equation[firstIndex].substring(0, equation[firstIndex].indexOf(".")));987 secondNumber = !equation[secondIndex].contains(".") ? Long.parseLong(equation[secondIndex]) : Long.parseLong(equation[secondIndex].substring(0, equation[secondIndex].indexOf(".")));988989 operator = equation[operatorIndex];990 if (operator.equals("+")) {991 resultNumber = firstNumber + secondNumber;992 } else if (operator.equals("-")) {993 resultNumber = firstNumber - secondNumber;994 } else if (operator.equals("*")) {995 resultNumber = firstNumber * secondNumber;996 } else if (operator.equals("/")) {997 resultNumber = firstNumber / secondNumber;998 }999 testHelper.UpdateTestResults("Solving equation: " + firstNumber + " " + operator + " " + secondNumber + " = " + resultNumber + " for step " + fileStepIndex, true);10001001 if (ts.get_expectedValue() != null) {1002 double expected = Double.parseDouble(ts.get_expectedValue());1003 if (resultNumber == expected) {1004 testHelper.UpdateTestResults("Successful Parse and Calculate Long Expected: (" + expected + ") Actual: (" + resultNumber + ") for step " + fileStepIndex, true);1005 } else {1006 testHelper.UpdateTestResults("Failed Parse and Calculate Long Expected: (" + expected + ") Actual: (" + resultNumber + ") for step " + fileStepIndex, true);1007 }1008 }10091010 if (accessorPersist.toLowerCase().equals("persist")) {1011 testHelper.CreateSectionHeader(AppConstants.indent5 + "[ Start Persisting Calculated Value ]", "", AppConstants.ANSI_CYAN, true, false, true);1012 testHelper.UpdateTestResults(AppConstants.indent8 + "Persisting Calculated value: (" + resultNumber + ")", true);1013 persistedString = String.valueOf(resultNumber);1014 testHelper.CreateSectionHeader(AppConstants.indent5 + "[ End Persisting Calculated Value, but value persisted and usable until end of test file ]", "", AppConstants.ANSI_CYAN, false, false, true);1015 } else {1016 TestStep testStep = new TestStep();1017 testStep.set_command(AppCommands.SendKeys);1018 testStep.set_crucial(ts.get_crucial());1019 testStep.set_isConditionalBlock(ts.get_isConditionalBlock());1020 testStep.set_accessor(accessorPersist);1021 testStep.set_actionType("write");1022 testStep.set_accessorType(ts.get_accessorType());1023 Argument argument = new Argument();1024 argument.set_parameter(String.valueOf(resultNumber));1025 List<Argument> arguments = new ArrayList<>();1026 arguments.add(argument);1027 testStep.ArgumentList = arguments;1028 PerformAction(testStep, String.valueOf(resultNumber), fileStepIndex);1029 }1030 }1031 }10321033 /******************************************************************************1034 * DESCRIPTION: Control method used to Check the count of a specific element type.1035 * @param ts - Test Step Object containing all related information1036 * for the particular test step.1037 * @param fileStepIndex - the file index and the step index.1038 ******************************************************************************/1039 private void CheckElementCountController(TestStep ts, String fileStepIndex) {1040 String checkItem = GetArgumentValue(ts, 0, null);1041 String url = GetArgumentValue(ts,1,null);1042 url = (url != null && url.contains("!=")) ? null:
...
Source:CourtOrderSuperClass.java
...2175 System.out.println("Report name is matched");2176 String modifiedReport = getReportNamee(NameOfReprt);2177 if (modifiedReport != null)2178 {2179 ModifiedReport rp = Enum.valueOf(ModifiedReport.class,2180 modifiedReport);2181 EnumTestClass enumTestCls = new EnumTestClass();2182 enumTestCls.runTestReport(rp);2183 }2184 }2185 } catch (Throwable t)2186 {2187 System.out.println(t.getMessage().toString());2188 System.out.println(t.getStackTrace().toString());2189 }2190 System.out.println("Exit FetchReport==========");2191 }21922193
...
Source:CommonFunctions.java
...317 Robot robot = new Robot();318 Actions action = new Actions(driver);319 String[] arguments = null;320 arguments = splitfunction(parameters, "->");321 ActionTypes actTypes = ActionTypes.valueOf(arguments[1].trim());322 switch (actTypes) {323 case TAB:324 robot.keyPress(KeyEvent.VK_TAB);325 robot.keyRelease(KeyEvent.VK_TAB);326 status = true;327 break;328 case ENTER:329 robot.keyPress(KeyEvent.VK_ENTER);330 robot.keyRelease(KeyEvent.VK_ENTER);331 status = true;332 break;333 case F12:334 robot.keyPress(KeyEvent.VK_F12);335 robot.keyRelease(KeyEvent.VK_F12);336 status = true;337 break;338 case ESCAPE:339 robot.keyPress(KeyEvent.VK_ESCAPE);340 robot.keyRelease(KeyEvent.VK_ESCAPE);341 status = true;342 break;343 case DOWN:344 robot.keyPress(KeyEvent.VK_DOWN);345 robot.keyRelease(KeyEvent.VK_DOWN);346 status = true;347 break;348 }349 } catch (NumberFormatException e) {350 System.out.println(e.getMessage());351 }352 return status;353 }354 public static Boolean GENERATE_UNIQVALUE(String Parameters) throws InterruptedException, IOException {355 Boolean Status = true;356 String strPrefix = null; // Variable to store prefix value357 String storevalue = null; // Variable to store output358 int strLength = 0;// Variable to store length value359 String strType = null;// Variable to store type(string/int)360 String strStringCase = null; // Variable to case(lower/upper)361 String strvalue1 = null; // Variable to store array after spliting first time362 String strvalue = null;// Variable to store array after spliting second time363 String strrndCode = null; // Variable to store uniq value364 String strcasetype = null; // lower or upper365 int intI; // variable to loop str length366 String Numc = null;367 int targetStringLength = 0;368 int Strprifixlength = 0;369 int uniqlength = 0;370 try {371 String[] arguments1 = splitfunction(Parameters, "->");372 if (arguments1.length == 2) {373 strType = "Alphanumeric";374 strPrefix = "KG_";375 strLength = 10;376 targetStringLength = 10;377 strcasetype = "Lowercase";378 storevalue = arguments1[1];379 } else {380 if (arguments1.length == 3) {381 if (arguments1[1].length() == 1) {382 targetStringLength = Integer.valueOf(arguments1[1]);383 strType = "Alphanumeric";384 strPrefix = "KG_";385 strcasetype = "Lowercase";386 storevalue = arguments1[2];387 } else if (arguments1[1].length() > 1) {388 String[] arguments = splitfunction(arguments1[1], ",");389 if (arguments.length == 2) {390 targetStringLength = Integer.valueOf(arguments[0]);391 strType = arguments[1];392 strPrefix = "KG_";393 strcasetype = "Lowercase";394 storevalue = arguments1[2];395 }396 if (arguments.length == 3) {397 targetStringLength = Integer.valueOf(arguments[0]);398 strType = arguments[1];399 strPrefix = arguments[2];400 strcasetype = "Lowercase";401 storevalue = arguments1[2];402 }403 if (arguments.length == 4) {404 targetStringLength = Integer.valueOf(arguments[0]);405 strType = arguments[1];406 strPrefix = arguments[2];407 strcasetype = arguments[3];408 storevalue = arguments1[2];409 }410 }411 }412 }413 if (targetStringLength != 0 && strType != null && strPrefix != null && strcasetype != null414 && storevalue != null) {415 int leftLimit = 97; // letter 'a'416 int rightLimit = 122; // letter 'z'417 int n = 9;418 int num = 0;419 String SALTCHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";420 StringBuilder salt = new StringBuilder();421 Random random = new Random();422 StringBuilder buffer = new StringBuilder(targetStringLength);423 if (strType.toUpperCase().equalsIgnoreCase("STRING")) {424 for (int i = 0; i < targetStringLength; i++) {425 int randomLimitedInt = leftLimit + (int) (random.nextFloat() * (rightLimit - leftLimit + 1));426 buffer.append((char) randomLimitedInt);427 }428 String generatedString = buffer.toString();429 generatedString = strPrefix + generatedString;430 if (strcasetype.equalsIgnoreCase("uppercase")) {431 System.out.println(generatedString.toUpperCase());432 hmap.put(storevalue, generatedString.toUpperCase());433 } else {434 System.out.println(generatedString.toLowerCase());435 hmap.put(storevalue, generatedString.toLowerCase());436 }437 } else if (strType.toUpperCase().equalsIgnoreCase("number")) {438 for (int i = 0; i < targetStringLength; i++) {439 num = Integer.valueOf(String.valueOf(num) + String.valueOf(n));440 }441 int b = random.nextInt(num) + 1;442 Numc = strPrefix + String.valueOf(b);443 System.out.println(Numc);444 hmap.put(storevalue, Numc);445 } else if (strType.toUpperCase().equalsIgnoreCase("Alphanumeric")) {446 while (salt.length() < targetStringLength) { // length of the random string.447 int index = (int) (random.nextFloat() * SALTCHARS.length());448 salt.append(SALTCHARS.charAt(index));449 }450 String saltStr = salt.toString();451 saltStr = strPrefix + saltStr;452 if (strcasetype.equalsIgnoreCase("uppercase")) {453 System.out.println(saltStr.toUpperCase());454 hmap.put(storevalue, saltStr.toUpperCase());455 } else {456 System.out.println(saltStr.toLowerCase());457 hmap.put(storevalue, saltStr.toLowerCase());458 }459 } else {460 System.out.println("Please select String or Number or Alphanumeric");461 }462 } else {463 System.out.println("one of the input feild is null");464 Status = false;465 }466 } catch (Exception e) {467 System.out.println("exception value : " + e.getMessage());468 Status = false;469 }470 return Status;471 }472 public static void Readenvironmentalfile(String path)473 throws InterruptedException, AWTException, IOException, ClassNotFoundException, SQLException,474 InstantiationException, IllegalAccessException, Exception, StaleElementReferenceException {475 try {476 Sheet envsheet;477 String FilePath = path;478 FileInputStream envfs = new FileInputStream(FilePath);479 Workbook envwb = new XSSFWorkbook(envfs);480 envsheet = envwb.getSheetAt(0);481 // envwb.setMissingCellPolicy(Row.CREATE_NULL_AS_BLANK);482 int envrowcount = envsheet.getLastRowNum();483 int envcolcount = envsheet.getRow(envrowcount).getLastCellNum();484 int Rowval = 1;485 int colval = 1;486 String strenvname = "";487 String strenvvalue = "";488 for (Rowval = 1; Rowval <= envrowcount; Rowval++) {489 Row ro = envsheet.getRow(Rowval);490 if ((ro != null)) {491 Cell cell1 = envsheet.getRow(Rowval).getCell(0);492 Cell cell2 = envsheet.getRow(Rowval).getCell(1);493 strenvname = cell1.getStringCellValue();494 strenvname.trim();495 strenvvalue = cell2.getStringCellValue();496 strenvvalue.trim();497 if (strenvname.contains("#")) {498 Rowval++;499 } else if (strenvname != null && strenvvalue != null) {500 hmap.put(strenvname, strenvvalue);501 }502 } else {503 System.out.println("value is null" + " " + strenvname);504 System.out.println("value is null" + " " + strenvvalue);505 }506 }507 } catch (Exception e) {508 System.out.println("exception value : " + e.getMessage());509 }510 }511 public static void Readtestsuitefile(String path) {512 try {513 String Filepath = path;514 Sheet suiteheet;515 String CellData = null;516 FileInputStream fs = new FileInputStream(Filepath);517 Workbook wb = new XSSFWorkbook(fs);518 suiteheet = wb.getSheetAt(0);519 int rowcount = suiteheet.getLastRowNum();520 int colcount = suiteheet.getRow(rowcount).getLastCellNum();521 int Rowval = 0;522 int colval = 1;523 int finalvalue = 0;524 Boolean Testcasename = false;525 /*526 * Below for loop gets the total rows in test suite file and Stores all527 * environmental variables initially Testcasename sets to false, once it finds528 * Testcasename in loop it turns to true and stores the current rownum in final529 * value if Testcasename equals to true, Initializationscript will be called530 * from next row and starts execution531 */532 for (int i = 0; i <= rowcount; i++) {533 if (Testcasename == true) {534 Cell cell = suiteheet.getRow(finalvalue).getCell(1);535 String spath[] = path.split("\\\\TestSuite");536 Cell status = suiteheet.getRow(finalvalue).getCell(2);537 Cell casename = suiteheet.getRow(finalvalue).getCell(0);538 Cell muldata = suiteheet.getRow(finalvalue).getCell(3);539 muldatastatus = muldata.getStringCellValue();540 if (Tcase == null) {541 Tcase = "Tcase";542 }543 Tcasename = casename.getStringCellValue();544 hmap.put(Tcase, Tcasename);545 SCellData = cell.getStringCellValue();546 String casepath = spath[0] + "\\TestCases\\" + cell.getStringCellValue();547 String cellstatus = status.getStringCellValue();548 int j = 1;549 if (cellstatus.equalsIgnoreCase("Yes"))550 try {551 {552 Tcasecount = Tcasecount + 1;553 TChmap.put(Tcasename, j);554 j = j + 1;555 556 DriverScript.Initializationscript(casepath);557 558 if (i == rowcount - 1) {559 break;560 } else {561 finalvalue = finalvalue + 1;562 }563 }564 } catch (Exception e) {565 // TODO Auto-generated catch block566 e.printStackTrace();567 }568 else {569 if (i == rowcount - 1) {570 break;571 } else {572 finalvalue = finalvalue + 1;573 }574 }575 } else {576 Row ro = suiteheet.getRow(i);577 if (ro != null) {578 Cell cell = suiteheet.getRow(i).getCell(0);579 if (cell == null) {580 // System.out.println("found blank cell");581 } else {582 int cel_Type = cell.getCellType();583 if (cell.getCellType() == Cell.CELL_TYPE_BLANK) {584 // System.out.println("found blank cell");585 } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {586 CellData = cell.getStringCellValue();587 CellData.trim();588 if (cell.getRichStringCellValue().getString().trim().equalsIgnoreCase("Send Mail")) {589 cell = suiteheet.getRow(i).getCell(1);590 if (cell.getRichStringCellValue().getString().trim().equalsIgnoreCase("YES")) {591 sendmail = true;592 }593 }594 if (cell.getRichStringCellValue().getString().trim().equalsIgnoreCase("USER")) {595 cell = suiteheet.getRow(i).getCell(1);596 runsuser = cell.getRichStringCellValue().toString();597 }598 if (cell.getRichStringCellValue().getString().trim().equalsIgnoreCase("Tenant")) {599 cell = suiteheet.getRow(i).getCell(1);600 suitetenant = cell.getRichStringCellValue().toString();601 }602 if (cell.getRichStringCellValue().getString().trim().equalsIgnoreCase("Release Name")) {603 cell = suiteheet.getRow(i).getCell(1);604 releasename = cell.getStringCellValue();605 }606 if (cell.getRichStringCellValue().getString().trim().equalsIgnoreCase("MailGroup")) {607 cell = suiteheet.getRow(i).getCell(1);608 mailgroup = cell.getStringCellValue();609 }610 if (cell.getRichStringCellValue().getString().trim()611 .equalsIgnoreCase("EnvironmentURL")) {612 cell = suiteheet.getRow(i).getCell(1);613 environmentname = cell.getStringCellValue();614 }615 if (cell.getRichStringCellValue().getString().trim().equalsIgnoreCase("Environment")) {616 cell = suiteheet.getRow(i).getCell(1);617 sheetenvironment = cell.getStringCellValue();618 }619 if (cell.getRichStringCellValue().getString().trim().equalsIgnoreCase("SuiteName")) {620 cell = suiteheet.getRow(i).getCell(1);621 sheetsuitename = cell.getStringCellValue();622 }623 if (cell.getRichStringCellValue().getString().trim().equalsIgnoreCase("Customer")) {624 cell = suiteheet.getRow(i).getCell(1);625 Customername = cell.getStringCellValue();626 }627 if (cell.getRichStringCellValue().getString().trim().equalsIgnoreCase("Tyoe of Run")) {628 cell = suiteheet.getRow(i).getCell(1);629 Typeofrun = cell.getStringCellValue();630 }631 if (cell.getRichStringCellValue().getString().trim().equals("Test Case Name")) {632 Row r1 = suiteheet.getRow(i + 1);633 if (r1 != null) {634 cell = suiteheet.getRow(i + 1).getCell(1);635 String spath[] = path.split("\\\\TestSuite");636 String testdata = spath[0] + "\\TestData" + cell.getStringCellValue();637 Cell status = suiteheet.getRow(i + 1).getCell(2);638 Cell casename = suiteheet.getRow(i + 1).getCell(0);639 Cell muldata = suiteheet.getRow(i + 1).getCell(3);640 Tcasename = casename.getStringCellValue();641 if (Tcasename.equalsIgnoreCase("ReadTestData")) {642 Readenvironmentalfile(testdata);643 Testcasename = true;644 storedataflag = false;645 finalvalue = i + 2;646 } else if (Tcasename.equalsIgnoreCase("CreateTestData")) {647 storedataflag = true;648 Testcasename = true;649 finalvalue = i + 2;650 }651 }652 }653 }654 }655 }656 }657 }658 } catch (Exception e) {659 e.printStackTrace();660 System.out.println(e.getMessage());661 } catch (Throwable e) {662 // TODO Auto-generated catch block663 e.printStackTrace();664 }665 }666 public static String[] splitfunction(String keyparameters, String symbol)667 throws InterruptedException, AWTException, IOException, ClassNotFoundException, SQLException,668 InstantiationException, IllegalAccessException, Exception, StaleElementReferenceException {669 String[] parameters = null;670 try {671 if (symbol == "+") {672 symbol = "\\+";673 } else if (symbol == "|") {674 symbol = "\\|";675 } else if (symbol == "*") {676 symbol = "\\*";677 }678 parameters = keyparameters.split(symbol);679 return parameters;680 } catch (Exception e) {681 System.out.println(e.getMessage());682 }683 return parameters;684 }685 public static boolean LAUNCHBROWSER(WebDriver WebDriver, String parameters)686 throws InterruptedException, AWTException, IOException, ClassNotFoundException, SQLException,687 InstantiationException, IllegalAccessException, Exception, StaleElementReferenceException {688 try {689 String workingDirectory = new java.io.File(".").getCanonicalPath();690 String actualurl = null;691 String[] arguments = splitfunction(parameters, "->");692 String[] args = splitfunction(arguments[2], ",");693 String browser = arguments[1];694 if (hmap.containsKey(args[0])) {695 url = hmap.get(args[0]);696 } else {697 url = args[0];698 }699 switch (browser.toUpperCase()) {700 case "IE EXPLORER":701 System.setProperty("webdriver.ie.driver", workingDirectory + "/JavaJarfiles/IEDriverServer.exe");702 driver = new InternetExplorerDriver();703 driver.get(url);704 driver.manage().window().maximize();705 actualurl = driver.getCurrentUrl();706 break;707 case "FIREFOX":708 workingDirectory = new java.io.File(".").getCanonicalPath();709 String dpath = workingDirectory;710 File file = new File(dpath + "\\Savedoutput");711 String[] myFiles;712 if (file.isDirectory()) {713 myFiles = file.list();714 for (int i = 0; i < myFiles.length; i++) {715 File myFile = new File(file, myFiles[i]);716 myFile.delete();717 }718 }719 System.setProperty("webdriver.gecko.driver", workingDirectory + "/JavaJarfiles//geckodriver.exe");720 FirefoxProfile profile = new FirefoxProfile();721 profile.setPreference("browser.download.dir", dpath + "\\Savedoutput");722 profile.setPreference("browser.download.folderList", 2);723 // profile.setPreference("browser.helperApps.alwaysAsk.force", "false");724 profile.setPreference("browser.helperApps.neverAsk.saveToDisk",725 "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/x-excel, application/x-msexcel, application/excel, application/vnd.ms-excel,application/xls;");726 // profile.setPreference("browser.download.manager.showWhenStarting", "false");727 profile.setPreference("pdfjs.disabled", "true");728 driver = new FirefoxDriver((Capabilities) profile);729 driver.get(url);730 driver.manage().window().maximize();731 actualurl = driver.getCurrentUrl();732 break;733 case "CHROME":734 System.setProperty("webdriver.chrome.driver", workingDirectory + "/JavaJarfiles/chromedriver.exe");735 options = new ChromeOptions();736 options.addArguments("disable-infobars");737 DesiredCapabilities caps = DesiredCapabilities.chrome();738 caps.setCapability(ChromeOptions.CAPABILITY, options);739 caps.setCapability("acceptInsecureCerts", caps);740 // options.addArguments("--incognito");741 driver = new ChromeDriver(options);742 driver.get(url);743 // System.out.println("Title of page: -"+ driver.getTitle());744 driver.manage().window().maximize();745 driver.manage().deleteAllCookies();746 driver.navigate().refresh();747 // driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);748 // driver.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS);749 actualurl = driver.getCurrentUrl();750 if (!(driver instanceof WebStorage)) {751 throw new IllegalArgumentException("This test expects the driver to implement WebStorage");752 }753 WebStorage webStorage = (WebStorage) driver;754 webStorage.getSessionStorage().clear();755 webStorage.getLocalStorage().clear();756 break;757 758 case "HEADLESS":759 System.setProperty("webdriver.chrome.driver", workingDirectory + "/JavaJarfiles/chromedriver.exe");760 options = new ChromeOptions();761 options.addArguments("disable-infobars");762 options.setHeadless(true);763 options.addArguments("--window-size=1920,1080");764 options.addArguments("--allow-insecure-localhost");765 options.addArguments("--disable-gpu");766 options.addArguments("--no-sandbox");767 caps = DesiredCapabilities.chrome();768 caps.setCapability(ChromeOptions.CAPABILITY, options);769 caps.setCapability("acceptInsecureCerts", caps);770 driver = new ChromeDriver(options);771 driver.get(url);772 driver.manage().window().maximize();773 driver.manage().deleteAllCookies();774 driver.navigate().refresh();775 actualurl = driver.getCurrentUrl();776 if (!(driver instanceof WebStorage)) {777 throw new IllegalArgumentException("This test expects the driver to implement WebStorage");778 }779 webStorage = (WebStorage) driver;780 webStorage.getSessionStorage().clear();781 webStorage.getLocalStorage().clear();782 break;783 }784 if (url.equals(url)) {785 WAITTIME("waittime->3");786 login(driver, args[1] + "->" + args[2]);787 //ssslogin(driver, args[1] + "->" + args[2]);788 return true;789 } else {790 return false;791 }792 } catch (Exception e) {793 System.out.println(e.getMessage());794 return false;795 }796 }797 public static boolean CLOSEALLBROWSERS(WebDriver WebDriver)798 throws InterruptedException, AWTException, IOException, ClassNotFoundException, SQLException,799 InstantiationException, IllegalAccessException, Exception, StaleElementReferenceException {800 try {801 WebDriver.quit();802 System.out.println("successfully closed all browsers");803 return true;804 } catch (Exception e) {805 System.out.println("unable to find the browser" + " " + e.getMessage());806 return false;807 }808 }809 // ************************************************************************************************************************810 /*811 * Function Name:WAITTIME812 * Stops execution for given time(in secs) 813 * Author: Murali814 * Created On: 13-04-2021 Version:1 Parameters (Keyword, Time) (WAITTIME 3)815 */816//*************************************************************************************************************************817 public static boolean WAITTIME(String parameters)818 throws InterruptedException, AWTException, IOException, ClassNotFoundException, SQLException,819 InstantiationException, IllegalAccessException, Exception, StaleElementReferenceException {820 String[] arguments = null;821 arguments = splitfunction(parameters, "->");822 try {823 int sleepTime = Integer.valueOf(arguments[1].trim()) * 500;824 Thread.sleep(sleepTime);825 return true;826 } catch (Exception e) {827 return false;828 }829 }830 public static boolean WAITFORELEMENT(WebDriver webdriver, String parameters)831 throws InterruptedException, AWTException, IOException, ClassNotFoundException, SQLException,832 InstantiationException, IllegalAccessException, Exception, StaleElementReferenceException {833 boolean status = true;834 String keyvalue = null;835 try {836 int flag = 1;837 String[] arguments = null;838 arguments = splitfunction(parameters, "->");839 String xpath = DriverScript.prop.getProperty(arguments[1]);840 if(xpath.contains("+")) {841 String[] newval = splitfunction(xpath, "+");842 if (hmap.containsKey(newval[1])) {843 keyvalue = hmap.get(newval[1]);844 }845 xpath = xpath.replace(newval[1], keyvalue);846 xpath = xpath.replace("+", "").trim();847 }848 if (xpath != null) {849 timer = 2000;850 do {851 WebElement locator = Getlocator(driver, xpath);852 if (locator == null) {853 timer = timer - 1;854 if (timer == 0) {855 timer = 2001;856 }857 } else {858 if (locator.isDisplayed()) {859 timer = 2001;860 flag = 0;861 System.out.println("Element found" + " " + arguments[1]);862 } else {863 timer = timer - 1;864 if (timer == 0) {865 timer = 2001;866 }867 }868 }869 } while (timer < 2000);870 if (flag == 1) {871 status = false;872 }873 } else {874 System.out.println("unable to find the xpath" + " " + arguments[1]);875 }876 } catch (StaleElementReferenceException e) {877 System.out.println(e.getMessage());878 status = false;879 }880 return status;881 }882 public static boolean CLEARTEXTBOX(WebDriver WebDriver, String parameters)883 throws InterruptedException, AWTException, IOException, ClassNotFoundException, SQLException,884 InstantiationException, IllegalAccessException, Exception, StaleElementReferenceException {885 Boolean Status = true;886 try {887 String[] arguments = null;888 arguments = splitfunction(parameters, "\\->");889 String xpath = DriverScript.prop.getProperty(arguments[1]);890 if (xpath != null) {891 WebElement locator = Getlocator(driver, xpath);892 if (locator.isEnabled()) {893 locator.clear();894 System.out.println("Succesfully cleared the text box");895 } else {896 System.out.println("Text box was disabled");897 Status = false;898 }899 } else {900 System.out.println("unable to find the xpath" + " " + arguments[1]);901 }902 } catch (Exception e) {903 Status = false;904 }905 return Status;906 }907 public static WebElement Getlocator(WebDriver WebDriver, String parameters)908 throws InterruptedException, AWTException, IOException, ClassNotFoundException, SQLException,909 InstantiationException, IllegalAccessException, Exception, StaleElementReferenceException {910 //// RecoveryScenarios();911 WebElement locpath = null;912 try {913 String[] arguments = null;914 boolean b;915 b = parameters.matches(".*:.*");916 if (b) {917 if(parameters.contains("-=")) {918 arguments = splitfunction(parameters, "-="); 919 } else {920 arguments = splitfunction(parameters, ":");921 }922 } else {923 arguments = splitfunction(parameters, "\\|");924 }925 String mode = arguments[0];926 arguments[0].trim();927 locator = arguments[1];928 switch (mode) {929 case "id":930 locpath = driver.findElement(By.id(locator));931 break;932 case "name":933 locpath = driver.findElement(By.name(locator));934 break;935 case "linkText":936 locpath = driver.findElement(By.linkText(locator));937 break;938 case "xpath":939 locpath = driver.findElement(By.xpath(locator));940 break;941 case "cssSelector":942 locpath = driver.findElement(By.cssSelector(locator));943 break;944 case "partialLinkText":945 locpath = driver.findElement(By.partialLinkText(locator));946 break;947 case "className":948 locpath = driver.findElement(By.className(locator));949 break;950 case "tagName":951 locpath = driver.findElement(By.tagName(locator));952 break;953 }954 } catch (Exception e) {955 e.printStackTrace();956 System.out.println("unable to find the locator" + " " + locator);957 }958 return locpath;959 }960 public static boolean ENTERVALUE(WebDriver WebDriver, String parameters)961 throws InterruptedException, AWTException, IOException, ClassNotFoundException, SQLException,962 InstantiationException, IllegalAccessException, Exception, StaleElementReferenceException {963 String[] arguments = null;964 Boolean Status = true;965 String keyvalue = null;966 arguments = splitfunction(parameters, "\\->");967 try {968 String xpath = DriverScript.prop.getProperty(arguments[1]);969 if(xpath.contains("+")) {970 String[] newval = splitfunction(xpath, "+");971 if (hmap.containsKey(newval[1])) {972 keyvalue = hmap.get(newval[1]);973 }974 xpath = xpath.replace(newval[1], keyvalue);975 xpath = xpath.replace("+", "").trim();976 }977 if (xpath != null) {978 WebElement locator = Getlocator(driver, xpath);979 if (locator.isEnabled()) {980 if (arguments[2].toUpperCase().contains("SYSDATE")) {981 String sysdat = Sysdate(arguments[2]);982 locator.click();983 WAITTIME("WAITTIME->2");984 locator.sendKeys(sysdat);985 System.out.println("Succesfully entered the Date" + " " + sysdat);986 } else if (hmap.containsKey(arguments[2])) {987 String value = hmap.get(arguments[2]);988 locator.click();989 WAITTIME("WAITTIME->2");990 locator.sendKeys(value);991 System.out.println("Succesfully entered the value" + " " + value);992 } else {993 locator.click();994 WAITTIME("WAITTIME->2");995 locator.sendKeys(arguments[2]);996 System.out.println("Succesfully entered the value" + " " + arguments[2]);997 }998 } else {999 System.out.println("not able to find" + " " + arguments[2]);1000 Status = false;1001 }1002 } else {1003 System.out.println("unable to find the xpath" + " " + arguments[1]);1004 }1005 } catch (Exception e) {1006 System.out.println(e.getMessage());1007 System.out.println("unable to find the locator" + " " + arguments[1]);1008 Status = false;1009 }1010 return Status;1011 }1012 public static boolean VERIFYVALUE(WebDriver webdriver, String parameters)1013 throws InterruptedException, AWTException, IOException, ClassNotFoundException, SQLException,1014 InstantiationException, IllegalAccessException, Exception, StaleElementReferenceException {1015 flag = 1;1016 String[] arguments = null;1017 String keyvalue = null;1018 arguments = splitfunction(parameters, "->");1019 String value = null;1020 try {1021 if (hmap.containsKey(arguments[2])) {1022 value = hmap.get(arguments[2]);1023 } else {1024 value = arguments[2];1025 }1026 String xpath = DriverScript.prop.getProperty(arguments[1]);1027 if(xpath.contains("+")) {1028 String[] newval = splitfunction(xpath, "+");1029 1030 if (hmap.containsKey(newval[1])) {1031 keyvalue = hmap.get(newval[1]);1032 }1033 xpath = xpath.replace(newval[1], keyvalue);1034 xpath = xpath.replace("+", "").trim();1035 }1036 if (xpath != null) {1037 WebElement locator = Getlocator(driver, xpath);1038 String ovalue = locator.getAttribute("value");1039 if (ovalue == null || ovalue == "") {1040 ovalue = locator.getText();1041 }1042 if (hmap.containsKey(arguments[2])) {1043 value = hmap.get(arguments[2]);1044 } else if (arguments[2].toUpperCase().contains("SYSDATE")) {1045 String sysdat = Sysdate(arguments[2]);1046 value = sysdat;1047 } else if ((arguments[2].contains("+"))) {1048 String[] values = splitfunction(arguments[3], "+");1049 if (values.length > 1) {1050 if ((hmap.containsKey(values[0]))1051 && (hmap.containsKey(values[1]) && (hmap.containsKey(values[2])))) {1052 Float firstval = Float.parseFloat(hmap.get(values[0]));1053 Float Secval = Float.parseFloat(hmap.get(values[1]));1054 Float thirdval = Float.parseFloat(hmap.get(values[2]));1055 value = String.valueOf(firstval + Secval + thirdval);1056 hmap.put(arguments[2], value);1057 } else {1058 if ((hmap.containsKey(values[0])) && (hmap.containsKey(values[1]))) {1059 Float firstval = Float.parseFloat(hmap.get(values[0]));1060 Float Secval = Float.parseFloat(hmap.get(values[1]));1061 value = String.valueOf(firstval + Secval);1062 hmap.put(arguments[2], value);1063 }1064 }1065 } else {1066 }1067 } else if ((arguments[2].contains("*"))) {1068 String[] values = splitfunction(arguments[2], "*");1069 if ((hmap.containsKey(values[0])) && (hmap.containsKey(values[1]))) {1070 Float firstval = Float.parseFloat(hmap.get(values[0]));1071 Float Secval = Float.parseFloat(hmap.get(values[1]));1072 value = String.valueOf(firstval * Secval);1073 } else {1074 }1075 } else {1076 value = arguments[2];1077 }1078 if (value.equalsIgnoreCase("IS NOT NULL")) {1079 int len = ovalue.length();1080 if (len > 0) {1081 } else {1082 flag = 0;1083 }1084 } else {1085 if (ovalue.equalsIgnoreCase(value)) {1086 System.out.println("Both values Matched");1087 } else {1088 System.out.println("Values did not match");1089 flag = 0;1090 }1091 }1092 } else {1093 System.out.println("unable to find the xpath" + " " + arguments[1]);1094 }1095 } catch (Exception e) {1096 System.out.println("exception value : " + e.getMessage());1097 flag = 0;1098 }1099 if (flag == 1) {1100 return true;1101 } else {1102 return false;1103 }1104 }1105 public static String Sysdate(String parameters) throws Exception {1106 boolean flag = false;1107 if (parameters.contains("sysdate,")) {1108 dateformat = split(parameters, ",");1109 } else {1110 dateformat = split(parameters, ",");1111 flag = true;1112 }1113 switch (dateformat[1].toUpperCase()) {1114 case "DD-MM-YYYY":1115 date = Calendar.getInstance().getTime();1116 formatter = new SimpleDateFormat("dd-MM-yyyy");1117 today = formatter.format(date);1118 if (flag == true) {1119 date = Calendar.getInstance().getTime();1120 formatter = new SimpleDateFormat("dd-MM-yyyy");1121 today = formatter.format(date);1122 String[] odate = split(parameters, ",");1123 if (parameters.contains("+")) {1124 String[] addnum = split(odate[0], "+");1125 dat = returndate(addnum[1], today, "-");1126 } else if (parameters.contains("-")) {1127 String[] addnum = split(odate[0], "-");1128 dat = returnbackdate(addnum[1], today, "-");1129 }1130 today = dat;1131 }1132 break;1133 case "MM-DD-YYYY":1134 date = Calendar.getInstance().getTime();1135 formatter = new SimpleDateFormat("MM-dd-yyyy");1136 today = formatter.format(date);1137 if (flag == true) {1138 date = Calendar.getInstance().getTime();1139 formatter = new SimpleDateFormat("dd-MM-yyyy");1140 today = formatter.format(date);1141 String[] odate = split(parameters, ",");1142 if (parameters.contains("+")) {1143 String[] addnum = split(odate[0], "+");1144 dat = returndate(addnum[1], today, "-");1145 } else if (parameters.contains("-")) {1146 String[] addnum = split(odate[0], "-");1147 dat = returnbackdate(addnum[1], today, "-");1148 }1149 String[] odat = split(dat, "-");1150 String len = odat[1];1151 int oval = Integer.parseInt(odat[1]);1152 if ((oval <= 9) && (len.length() == 1)) {1153 odat[1] = "0" + odat[1];1154 }1155 today = odat[1] + "-" + odat[0] + "-" + odat[2];1156 }1157 break;1158 case "DD/MM/YYYY":1159 date = Calendar.getInstance().getTime();1160 formatter = new SimpleDateFormat("dd/MM/yyyy");1161 today = formatter.format(date);1162 if (flag == true) {1163 date = Calendar.getInstance().getTime();1164 formatter = new SimpleDateFormat("dd/MM/yyyy");1165 today = formatter.format(date);1166 String[] odate = split(parameters, ",");1167 if (parameters.contains("+")) {1168 String[] addnum = split(odate[0], "+");1169 dat = returndate(addnum[1], today, "/");1170 } else if (parameters.contains("-")) {1171 String[] addnum = split(odate[0], "-");1172 dat = returnbackdate(addnum[1], today, "/");1173 }1174 today = dat;1175 }1176 break;1177 case "MM/DD/YYYY":1178 date = Calendar.getInstance().getTime();1179 formatter = new SimpleDateFormat("MM/dd/yyyy");1180 today = formatter.format(date);1181 if (flag == true) {1182 date = Calendar.getInstance().getTime();1183 formatter = new SimpleDateFormat("dd-MM-yyyy");1184 today = formatter.format(date);1185 String[] odate = split(parameters, ",");1186 if (parameters.contains("+")) {1187 String[] addnum = split(odate[0], "+");1188 dat = returndate(addnum[1], today, "-");1189 } else if (parameters.contains("-")) {1190 String[] addnum = split(odate[0], "-");1191 dat = returnbackdate(addnum[1], today, "-");1192 }1193 String[] odat = split(dat, "-");1194 String len = odat[1];1195 int oval = Integer.parseInt(odat[1]);1196 if ((oval <= 9) && (len.length() == 1)) {1197 odat[1] = "0" + odat[1];1198 }1199 today = odat[1] + "/" + odat[0] + "/" + odat[2];1200 }1201 break;1202 case "DD-MM-YY":1203 date = Calendar.getInstance().getTime();1204 formatter = new SimpleDateFormat("dd-MM-yy");1205 today = formatter.format(date);1206 if (flag == true) {1207 date = Calendar.getInstance().getTime();1208 formatter = new SimpleDateFormat("dd-MM-yy");1209 today = formatter.format(date);1210 String[] odate = split(parameters, ",");1211 if (parameters.contains("+")) {1212 String[] addnum = split(odate[0], "+");1213 dat = returndate(addnum[1], today, "-");1214 today = dat;1215 } else if (parameters.contains("-")) {1216 String[] addnum = split(odate[0], "-");1217 dat = returnbackdate(addnum[1], today, "-");1218 String[] odat = split(dat, "-");1219 odat[2] = String.valueOf(odat[2]).substring(2);1220 today = odat[0] + "-" + odat[1] + "-" + odat[2];1221 }1222 }1223 break;1224 case "MM-DD-YY":1225 date = Calendar.getInstance().getTime();1226 formatter = new SimpleDateFormat("MM-dd-yy");1227 today = formatter.format(date);1228 if (flag == true) {1229 date = Calendar.getInstance().getTime();1230 formatter = new SimpleDateFormat("dd-MM-yy");1231 today = formatter.format(date);1232 String[] odate = split(parameters, ",");1233 if (parameters.contains("+")) {1234 String[] addnum = split(odate[0], "+");1235 dat = returndate(addnum[1], today, "-");1236 String[] odat = split(dat, "-");1237 today = odat[1] + "-" + odat[0] + "-" + odat[2];1238 } else if (parameters.contains("-")) {1239 String[] addnum = split(odate[0], "-");1240 dat = returnbackdate(addnum[1], today, "-");1241 String[] odat = split(dat, "-");1242 odat[2] = String.valueOf(odat[2]).substring(2);1243 today = odat[1] + "-" + odat[0] + "-" + odat[2];1244 }1245 }1246 break;1247 case "DD/MM/YY":1248 date = Calendar.getInstance().getTime();1249 formatter = new SimpleDateFormat("dd/MM/yy");1250 today = formatter.format(date);1251 if (flag == true) {1252 date = Calendar.getInstance().getTime();1253 formatter = new SimpleDateFormat("dd/MM/yy");1254 today = formatter.format(date);1255 String[] odate = split(parameters, ",");1256 if (parameters.contains("+")) {1257 String[] addnum = split(odate[0], "+");1258 dat = returndate(addnum[1], today, "/");1259 today = dat;1260 } else if (parameters.contains("-")) {1261 String[] addnum = split(odate[0], "-");1262 dat = returnbackdate(addnum[1], today, "/");1263 String[] odat = split(dat, "/");1264 odat[2] = String.valueOf(odat[2]).substring(2);1265 today = odat[0] + "/" + odat[1] + "/" + odat[2];1266 }1267 }1268 break;1269 case "MM/DD/YY":1270 date = Calendar.getInstance().getTime();1271 formatter = new SimpleDateFormat("MM/dd/yy");1272 today = formatter.format(date);1273 if (flag == true) {1274 date = Calendar.getInstance().getTime();1275 formatter = new SimpleDateFormat("dd/MM/yy");1276 today = formatter.format(date);1277 String[] odate = split(parameters, ",");1278 if (parameters.contains("+")) {1279 String[] addnum = split(odate[0], "+");1280 dat = returndate(addnum[1], today, "/");1281 String[] odat = split(dat, "/");1282 today = odat[1] + "/" + odat[0] + "/" + odat[2];1283 } else if (parameters.contains("-")) {1284 String[] addnum = split(odate[0], "-");1285 dat = returnbackdate(addnum[1], today, "/");1286 String[] odat = split(dat, "/");1287 odat[2] = String.valueOf(odat[2]).substring(2);1288 today = odat[1] + "/" + odat[0] + "/" + odat[2];1289 }1290 }1291 break;1292 case "DD-MMM-YYYY":1293 date = Calendar.getInstance().getTime();1294 formatter = new SimpleDateFormat("dd-MMM-yyyy");1295 today = formatter.format(date);1296 if (flag == true) {1297 date = Calendar.getInstance().getTime();1298 formatter = new SimpleDateFormat("dd-MMM-yyyy");1299 today = formatter.format(date);1300 String[] odate = split(parameters, ",");1301 if (parameters.contains("+")) {1302 String[] addnum = split(odate[0], "+");1303 dat = returndate(addnum[1], today, "-");1304 } else if (parameters.contains("-")) {1305 String[] addnum = split(odate[0], "-");1306 dat = returnbackdate(addnum[1], today, "-");1307 }1308 today = dat;1309 }1310 break;1311 case "DD/MMM/YYYY":1312 date = Calendar.getInstance().getTime();1313 formatter = new SimpleDateFormat("dd/MMM/yyyy");1314 today = formatter.format(date);1315 if (flag == true) {1316 date = Calendar.getInstance().getTime();1317 formatter = new SimpleDateFormat("dd/MMM/yyyy");1318 today = formatter.format(date);1319 String[] odate = split(parameters, ",");1320 if (parameters.contains("+")) {1321 String[] addnum = split(odate[0], "+");1322 dat = returndate(addnum[1], today, "/");1323 } else if (parameters.contains("-")) {1324 String[] addnum = split(odate[0], "-");1325 dat = returnbackdate(addnum[1], today, "/");1326 }1327 today = dat;1328 }1329 break;1330 case "YYYY-MM-DD":1331 date = Calendar.getInstance().getTime();1332 formatter = new SimpleDateFormat("YYYY-MM-dd");1333 today = formatter.format(date);1334 if (flag == true) {1335 date = Calendar.getInstance().getTime();1336 formatter = new SimpleDateFormat("dd-MM-yyyy");1337 today = formatter.format(date);1338 String[] odate = split(parameters, ",");1339 if (parameters.contains("+")) {1340 String[] addnum = split(odate[0], "+");1341 dat = returndate(addnum[1], today, "-");1342 String[] odat = split(dat, "-");1343 dat = odat[2] + "-" + odat[1] + "-" + odat[0];1344 } else if (parameters.contains("-")) {1345 String[] addnum = split(odate[0], "-");1346 dat = returnbackdate(addnum[1], today, "-");1347 String[] odat = split(dat, "-");1348 dat = odat[2] + "-" + odat[1] + "-" + odat[0];1349 }1350 today = dat;1351 }1352 break;1353 }1354 System.out.println(today);1355 return today;1356 }1357 public static String returndate(String num, String date, String s) throws Exception {1358 int oyear = 0;1359 int month = 0;1360 String temp = null;1361 Boolean flag = true;1362 try {1363 String[] formats = splitfunction(date, s);1364 temp = formats[1];1365 switch (formats[1].toUpperCase()) {1366 case "JAN":1367 formats[1] = "01";1368 flag = false;1369 break;1370 case "FEB":1371 formats[1] = "02";1372 flag = false;1373 break;1374 case "MAR":1375 formats[1] = "03";1376 flag = false;1377 break;1378 case "APR":1379 formats[1] = "04";1380 flag = false;1381 break;1382 case "MAY":1383 formats[1] = "05";1384 flag = false;1385 break;1386 case "JUN":1387 formats[1] = "06";1388 flag = false;1389 break;1390 case "JUL":1391 formats[1] = "07";1392 flag = false;1393 break;1394 case "AUG":1395 formats[1] = "08";1396 flag = false;1397 break;1398 case "SEP":1399 formats[1] = "09";1400 flag = false;1401 break;1402 case "OCT":1403 formats[1] = "10";1404 flag = false;1405 break;1406 case "NOV":1407 formats[1] = "11";1408 flag = false;1409 break;1410 case "DEC":1411 formats[1] = "12";1412 flag = false;1413 break;1414 }1415 int currdate = Integer.parseInt(num) + Integer.parseInt(formats[0]);1416 if (currdate >= 31) {1417 while (currdate >= 31) {1418 if (formats[1].equalsIgnoreCase("08") || (Integer.parseInt(formats[1]) % 2 != 0)1419 || formats[1].equalsIgnoreCase("02") || formats[1].equalsIgnoreCase("12")) {1420 if (formats[1].equalsIgnoreCase("02")) {1421 currdate = currdate - 28;1422 month = Integer.parseInt(formats[1]) + 1;1423 if (month < 10) {1424 formats[1] = 0 + String.valueOf(month);1425 } else if ((month > 12)) {1426 month = month % 12;1427 oyear = oyear + 1;1428 formats[1] = String.valueOf(month);1429 } else if ((month >= 10) && (month <= 12)) {1430 formats[1] = String.valueOf(month);1431 }1432 } else if (currdate == 31) {1433 currdate = 31;1434 month = Integer.parseInt(formats[1]);1435 break;1436 } else {1437 currdate = currdate - 31;1438 month = Integer.parseInt(formats[1]) + 1;1439 }1440 if (month < 10) {1441 formats[1] = 0 + String.valueOf(month);1442 if (formats[1].equalsIgnoreCase("02")) {1443 if (currdate > 28) {1444 currdate = currdate - 28;1445 month = Integer.parseInt(formats[1]) + 1;1446 formats[1] = String.valueOf(month);1447 }1448 }1449 } else if ((month > 12)) {1450 month = month % 12;1451 formats[1] = String.valueOf(month);1452 oyear = oyear + 1;1453 } else if ((month >= 10) && (month <= 12)) {1454 formats[1] = String.valueOf(month);1455 }1456 } else {1457 currdate = currdate - 30;1458 month = Integer.parseInt(formats[1]) + 1;1459 if (month < 10) {1460 formats[1] = 0 + String.valueOf(month);1461 } else if ((month > 12)) {1462 month = month % 12;1463 formats[1] = String.valueOf(month);1464 oyear = oyear + 1;1465 } else if ((month >= 10) && (month <= 12)) {1466 formats[1] = String.valueOf(month);1467 }1468 }1469 }1470 if (flag == false) {1471 switch (formats[1]) {1472 case "1":1473 formats[1] = "JAN";1474 break;1475 case "2":1476 formats[1] = "FEB";1477 flag = false;1478 break;1479 case "3":1480 formats[1] = "MAR";1481 flag = false;1482 break;1483 case "4":1484 formats[1] = "APR";1485 flag = false;1486 break;1487 case "5":1488 formats[1] = "MAY";1489 flag = false;1490 break;1491 case "6":1492 formats[1] = "JUN";1493 flag = false;1494 break;1495 case "7":1496 formats[1] = "JUL";1497 flag = false;1498 break;1499 case "8":1500 formats[1] = "AUG";1501 flag = false;1502 break;1503 case "9":1504 formats[1] = "SEP";1505 flag = false;1506 break;1507 case "10":1508 formats[1] = "OCT";1509 flag = false;1510 break;1511 case "11":1512 formats[1] = "NOV";1513 flag = false;1514 break;1515 case "12":1516 formats[1] = "DEC";1517 flag = false;1518 break;1519 }1520 }1521 if (oyear == 0) {1522 today = "0" + currdate + s + formats[1] + s + formats[2];1523 } else if (oyear > 0) {1524 int year = Integer.parseInt(formats[2]) + oyear;1525 formats[2] = String.valueOf(year);1526 today = "0" + currdate + s + formats[1] + s + formats[2];1527 }1528 if (currdate < 10) {1529 today = "0" + currdate + s + formats[1] + s + formats[2];1530 } else {1531 today = currdate + s + formats[1] + s + formats[2];1532 }1533 } else {1534 if (flag == false) {1535 formats[1] = temp;1536 }1537 if (currdate < 10) {1538 today = "0" + currdate + s + formats[1] + s + formats[2];1539 } else {1540 today = currdate + s + formats[1] + s + formats[2];1541 }1542 // today = currdate + s + formats[1] + s + formats[2];1543 }1544 } catch (Exception e) {1545 // out.println("unable to find the locator" + " " + e.getMessage());1546 }1547 return today;1548 }1549 public static String returnbackdate(String num, String date, String s) throws Exception {1550 int oyear = 0;1551 int month;1552 Boolean flag = true;1553 String temp;1554 String[] formats = split(date, s);1555 temp = formats[1];1556 switch (formats[1].toUpperCase()) {1557 case "JAN":1558 formats[1] = "01";1559 flag = false;1560 break;1561 case "FEB":1562 formats[1] = "02";1563 flag = false;1564 break;1565 case "MAR":1566 formats[1] = "03";1567 flag = false;1568 break;1569 case "APR":1570 formats[1] = "04";1571 flag = false;1572 break;1573 case "MAY":1574 formats[1] = "05";1575 flag = false;1576 break;1577 case "JUN":1578 formats[1] = "06";1579 flag = false;1580 break;1581 case "JUL":1582 formats[1] = "07";1583 flag = false;1584 break;1585 case "AUG":1586 formats[1] = "08";1587 flag = false;1588 break;1589 case "SEP":1590 formats[1] = "09";1591 flag = false;1592 break;1593 case "OCT":1594 formats[1] = "10";1595 flag = false;1596 break;1597 case "NOV":1598 formats[1] = "11";1599 flag = false;1600 break;1601 case "DEC":1602 formats[1] = "12";1603 flag = false;1604 break;1605 }1606 int currdate = Integer.parseInt(formats[0]) - Integer.parseInt(num);1607 if (currdate >= 1) {1608 today = currdate + s + formats[1] + s + formats[2];1609 } else if (currdate <= 0) {1610 while (currdate <= 0) {1611 month = Integer.parseInt(formats[1]) - 1;1612 if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10)1613 || (month == 12)) {1614 currdate = 31 - Math.abs(currdate);1615 } else if (month == 2) {1616 if (Integer.parseInt(formats[2]) / 4 == 0) {1617 currdate = 29 - Math.abs(currdate);1618 } else {1619 currdate = 28 - Math.abs(currdate);1620 }1621 } else {1622 currdate = 30 - Math.abs(currdate);1623 }1624 if (month == 0) {1625 month = 12;1626 oyear = oyear + 1;1627 }1628 if (month < 10) {1629 formats[1] = 0 + String.valueOf(month);1630 } else {1631 formats[1] = String.valueOf(month);1632 }1633 }1634 }1635 if (flag == false) {1636 switch (formats[1]) {1637 case "1":1638 formats[1] = "JAN";1639 break;1640 case "2":1641 formats[1] = "FEB";1642 flag = false;1643 break;1644 case "3":1645 formats[1] = "MAR";1646 flag = false;1647 break;1648 case "4":1649 formats[1] = "APR";1650 flag = false;1651 break;1652 case "5":1653 formats[1] = "MAY";1654 flag = false;1655 break;1656 case "6":1657 formats[1] = "JUN";1658 flag = false;1659 break;1660 case "7":1661 formats[1] = "JUL";1662 flag = false;1663 break;1664 case "8":1665 formats[1] = "AUG";1666 flag = false;1667 break;1668 case "9":1669 formats[1] = "SEP";1670 flag = false;1671 break;1672 case "10":1673 formats[1] = "OCT";1674 flag = false;1675 break;1676 case "11":1677 formats[1] = "NOV";1678 flag = false;1679 break;1680 case "12":1681 formats[1] = "DEC";1682 flag = false;1683 break;1684 }1685 }1686 int year = Calendar.getInstance().get(Calendar.YEAR) - oyear;1687 formats[2] = String.valueOf(year);1688 if (Math.abs(currdate) < 10) {1689 today = "0" + currdate + s + formats[1] + s + formats[2];1690 } else {1691 today = currdate + s + formats[1] + s + formats[2];1692 }1693 // System.out.println(today);1694 return today;1695 }1696 public static boolean CLICK(WebDriver WebDriver, String parameters)1697 throws InterruptedException, AWTException, IOException, ClassNotFoundException, SQLException,1698 InstantiationException, IllegalAccessException, Exception, StaleElementReferenceException {1699 Boolean Status = true;1700 String[] arguments = null;1701 String keyvalue = null;1702 arguments = splitfunction(parameters, "->");1703 try {1704 WAITFORELEMENT(WebDriver, "WAITFORELEMENT->" + arguments[1]);1705 String xpath = DriverScript.prop.getProperty(arguments[1]);1706 if(xpath.contains("+")) {1707 String[] newval = splitfunction(xpath, "+");1708 if (hmap.containsKey(newval[1])) {1709 keyvalue = hmap.get(newval[1]);1710 }1711 xpath = xpath.replace(newval[1], keyvalue);1712 xpath = xpath.replace("+", "").trim();1713 }1714 if (xpath != null) {1715 WebElement locator = Getlocator(driver, xpath);1716 if (locator.isEnabled()) {1717 String[] args = splitfunction(xpath, ":");1718 WAITTIME("WAITTIME->2");1719 locator.click();1720 WAITTIME("WAITTIME->2");1721 // clickElementUsingJavascriptExecutor(args[1]);1722 System.out.println("Succesfully clicked on" + " " + arguments[1]);1723 } else {1724 System.out.println("unable to find" + " " + arguments[1]);1725 Status = false;1726 }1727 } else {1728 System.out.println("unable to find the xpath" + " " + arguments[1]);1729 }1730 } catch (Exception e) {1731 System.out.println("unable to find the locator" + " " + e.getMessage());1732 Status = false;1733 }1734 return Status;1735 }1736 1737 public static boolean chkBox(WebDriver WebDriver, String parameters)1738 throws InterruptedException, AWTException, IOException, ClassNotFoundException, SQLException,1739 InstantiationException, IllegalAccessException, Exception, StaleElementReferenceException {1740 Boolean Status = true;1741 String[] arguments = null;1742 arguments = splitfunction(parameters, "->");1743 try {1744 WAITFORELEMENT(WebDriver, "WAITFORELEMENT->" + arguments[1]);1745 String xpath = DriverScript.prop.getProperty(arguments[1]);1746 if (xpath != null) {1747 WebElement locator = Getlocator(driver, xpath);1748 if (locator.isEnabled()) {1749 String[] args = splitfunction(xpath, ":");1750 WAITTIME("WAITTIME->2");1751 locator.click();1752 WAITTIME("WAITTIME->2");1753 // clickElementUsingJavascriptExecutor(args[1]);1754 System.out.println("Succesfully clicked on" + " " + arguments[1]);1755 } else {1756 System.out.println("unable to find" + " " + arguments[1]);1757 Status = false;1758 }1759 } else {1760 System.out.println("unable to find the xpath" + " " + arguments[1]);1761 }1762 } catch (Exception e) {1763 System.out.println("unable to find the locator" + " " + e.getMessage());1764 Status = false;1765 }1766 return Status;1767 }1768 1769 1770 public static boolean JSCLICK(WebDriver WebDriver, String parameters)1771 throws InterruptedException, AWTException, IOException, ClassNotFoundException, SQLException,1772 InstantiationException, IllegalAccessException, Exception, StaleElementReferenceException {1773 Boolean Status = true;1774 String[] arguments = null;1775 arguments = splitfunction(parameters, "->");1776 try {1777 String xpath = DriverScript.prop.getProperty(arguments[1]);1778 if (xpath != null) {1779 WebElement locator = Getlocator(driver, xpath);1780 if (locator.isEnabled()) {1781 String[] args = splitfunction(xpath, ":");1782 WAITTIME("WAITTIME->2");1783 clickElementUsingJavascriptExecutor(args[1]);1784 WAITTIME("WAITTIME->2");1785 System.out.println("Succesfully clicked on" + " " + arguments[1]);1786 } else {1787 System.out.println("unable to find" + " " + arguments[1]);1788 Status = false;1789 }1790 } else {1791 System.out.println("unable to find the xpath" + " " + arguments[1]);1792 }1793 } catch (Exception e) {1794 System.out.println("unable to find the locator " +arguments[1]+ " " + e.getMessage());1795 Status = false;1796 }1797 return Status;1798 }1799 public static boolean clickElementUsingJavascriptExecutor(String xpathValue) throws InterruptedException, AWTException, IOException, ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, Exception, StaleElementReferenceException {1800 boolean Status = true;1801 try {1802 WebElement element = driver.findElement(By.xpath(xpathValue.trim()));1803 WAITTIME("waittime->3");1804 ((JavascriptExecutor) driver).executeScript("arguments[0].click();", new Object[]{element});1805 } catch (Exception e) {1806 System.out.println("exception value : " + e.getMessage());1807 Status = false;1808 }1809 return Status;1810 }1811 public static Boolean STOREVALUE(String Parameters) throws Exception {1812 Boolean Status = false;1813 String value;1814 String[] values = null;1815 String[] argum = null;1816 String revalue = null;1817 String revalue1 = null;1818 Boolean flag = true;1819 String newoval = null;1820 Double num1;1821 Double num2;1822 try {1823 String[] arguments = splitfunction(Parameters, "->");1824 if ((arguments[2].contains("+"))) {1825 argum = splitfunction(arguments[2], "+");1826 if (((hmap.containsKey(argum[0]) == true))) {1827 revalue = hmap.get(argum[0]);1828 num1 = Double.parseDouble(String.valueOf(revalue));1829 } else {1830 num1 = Double.parseDouble(String.valueOf(argum[0]));1831 }1832 if (((hmap.containsKey(argum[1]) == true))) {1833 revalue1 = hmap.get(argum[1]);1834 num2 = Double.parseDouble(String.valueOf(revalue1));1835 } else {1836 num2 = Double.parseDouble(String.valueOf(argum[1]));1837 }1838 arguments[2] = String.valueOf(num1 + num2);1839 hmap.put(arguments[1], arguments[2]);1840 Status = true;1841 } else if (arguments[2].contains("*")) {1842 argum = splitfunction(arguments[2], "*");1843 if (((hmap.containsKey(argum[0]) == true))) {1844 revalue = hmap.get(argum[0]);1845 num1 = Double.parseDouble(String.valueOf(revalue));1846 } else {1847 num1 = Double.parseDouble(String.valueOf(argum[0]));1848 }1849 if (((hmap.containsKey(argum[1]) == true))) {1850 revalue1 = hmap.get(argum[1]);1851 num2 = Double.parseDouble(String.valueOf(revalue1));1852 } else {1853 num2 = Double.parseDouble(String.valueOf(argum[1]));1854 }1855 arguments[2] = String.valueOf(num1 * num2);1856 hmap.put(arguments[1], arguments[2]);1857 Status = true;1858 } else if ((arguments[2].contains("minus"))) {1859 argum = splitfunction(arguments[2], "minus");1860 if (((hmap.containsKey(argum[0]) == true))) {1861 revalue = hmap.get(argum[0]);1862 num1 = Double.parseDouble(String.valueOf(revalue));1863 } else {1864 num1 = Double.parseDouble(String.valueOf(argum[0]));1865 }1866 if (((hmap.containsKey(argum[1]) == true))) {1867 revalue1 = hmap.get(argum[1]);1868 num2 = Double.parseDouble(String.valueOf(revalue1));1869 } else {1870 num2 = Double.parseDouble(String.valueOf(argum[1]));1871 }1872 arguments[2] = String.valueOf(num1 - num2);1873 hmap.put(arguments[1], arguments[2]);1874 Status = true;1875 } else {1876 if (hmap.containsKey(arguments[2])) {1877 arguments[2] = hmap.get(arguments[2]);1878 }1879 hmap.put(arguments[1], arguments[2]);1880 Status = true;1881 }1882 } catch (Exception e) {1883 Status = false;1884 }1885 return Status;1886 }...
Source:BaseTestSuite.java
...191 */192193 protected WebDriver getDriver(String tool,String browser) throws IOException, InterruptedException {194 System.out.println("Driver started : " + tool + " and Browser is : "+ browser );195 WebDriver driver = getNewDriver(DriverSupportedBrowsers.valueOf(browser.toUpperCase()), "", "");196 System.out.println("Succesfully instantiated driver :: " + tool +"&"+ browser);197 return driver;198 }199200 /**201 * This Method initializes the driver by taking driver type as the main input.202 * 203 * @param driverType204 * @param browserVersion205 * @param platform206 * @return207 * @throws IOException208 * @throws InterruptedException 209 */
...
valueOf
Using AI Code Generation
1public static void main(String[] args) {2 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Naveen\\Downloads\\chromedriver.exe");3 WebDriver driver = new ChromeDriver();4 String color = driver.findElement(By.id("email")).getCssValue("color");5 color = color.replaceAll("rgba\\(", "").replaceAll("\\)", "");6 String[] colorValues = color.split(",");7 int hexValue = Integer.parseInt(colorValues[0].trim());8 hexValue = Integer.parseInt(colorValues[1].trim());9 hexValue = Integer.parseInt(colorValues[2].trim());10 hexValue = Integer.parseInt(colorValues[3].trim());11 color = Colors.valueOf(hexValue).toString();12 driver.quit();13}
valueOf
Using AI Code Generation
1public enum Colors {2 red, blue, green, yellow, orange, black, white, pink, purple, brown, grey, silver, gold, beige, maroon, navy, aqua, lime, teal, olive, cyan, magenta, transparent, indigo, violet;3}4public static Colors getEnum(String value) {5 return Colors.valueOf(value);6}7public enum Colors {8 red, blue, green, yellow, orange, black, white, pink, purple, brown, grey, silver, gold, beige, maroon, navy, aqua, lime, teal, olive, cyan, magenta, transparent, indigo, violet;9}10public static Colors getEnum(String value) {11 return Colors.valueOf(value);12}13public enum Colors {14 red, blue, green, yellow, orange, black, white, pink, purple, brown, grey, silver, gold, beige, maroon, navy, aqua, lime, teal, olive, cyan, magenta, transparent, indigo, violet;15}16public static Colors getEnum(String value) {17 return Colors.valueOf(value);18}19public enum Colors {20 red, blue, green, yellow, orange, black, white, pink, purple, brown, grey, silver, gold, beige, maroon, navy, aqua, lime, teal, olive, cyan, magenta, transparent, indigo, violet;21}22public static Colors getEnum(String value) {23 return Colors.valueOf(value);24}25public enum Colors {
valueOf
Using AI Code Generation
1package com.automation.selenium.enums;2import org.openqa.selenium.support.Colors;3public class Example1 {4 public static void main(String[] args) {5 System.out.println(Colors.valueOf("RED").asHex());6 System.out.println(Colors.valueOf("GREEN").asHex());7 System.out.println(Colors.valueOf("BLUE").asHex());8 }9}
valueOf
Using AI Code Generation
1package org.openqa.selenium.support;2public enum Colors {3 AQUA("#00ffff"), BLACK("#000000"), BLUE("#0000ff"), FUCHSIA("#ff00ff"),4 GRAY("#808080"), GREEN("#008000"), LIME("#00ff00"), MAROON("#800000"),5 NAVY("#000080"), OLIVE("#808000"), PURPLE("#800080"), RED("#ff0000"),6 SILVER("#c0c0c0"), TEAL("#008080"), WHITE("#ffffff"), YELLOW("#ffff00");7 private String hexValue;8 Colors(String hexValue) {9 this.hexValue = hexValue;10 }11 public String getHexValue() {12 return hexValue;13 }14 public static String getColorName(String hexValue) {15 for (Colors color : Colors.values()) {16 if (color.getHexValue().equalsIgnoreCase(hexValue)) {17 return color.name();18 }19 }20 return null;21 }22}23package org.seleniumhq.selenium;24import org.openqa.selenium.support.Colors;25import org.testng.Assert;26import org.testng.annotations.Test;27public class TestColors {28 public void testColors() {29 Assert.assertEquals(Colors.getColorName("#00ffff"), "AQUA");30 Assert.assertEquals(Colors.getColorName("#000000"), "BLACK");31 Assert.assertEquals(Colors.getColorName("#0000ff"), "BLUE");32 Assert.assertEquals(Colors.getColorName("#ff00ff"), "FUCHSIA");33 Assert.assertEquals(Colors.getColorName("#808080"), "GRAY");34 Assert.assertEquals(Colors.getColorName("#008000"), "GREEN");35 Assert.assertEquals(Colors.getColorName("#00ff00"), "LIME");36 Assert.assertEquals(Colors.getColorName("#800000"), "MAROON");37 Assert.assertEquals(Colors.getColorName("#000080"), "NAVY");38 Assert.assertEquals(Colors.getColorName("#808000"), "OLIVE");39 Assert.assertEquals(Colors.getColorName("#800080"), "PURPLE");40 Assert.assertEquals(Colors.getColorName("#ff0000"), "RED");41 Assert.assertEquals(Colors.getColorName("#c0c0c0"), "SILVER");42 Assert.assertEquals(Colors.getColorName("#008080"), "TEAL");
LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.
Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.
What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.
Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.
Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.
How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.
Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.
Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!