Как написать условие для перехода из одной строки в другую в Excel в зависимости от условия использования Java? - PullRequest
1 голос
/ 01 июня 2019

Мой лист Excel введите описание изображения здесь

Я работаю над автоматизацией мобильных приложений с использованием селена, гибридной среды (на основе ключевых слов и структуры на основе данных) и Junit.

Мой фреймворк содержит:

  1. Класс функциональной библиотеки: содержит все универсальные методы, такие как click, sendkeys, валидация и т. Д.
  2. Класс Driverscript: он сочетает в себе как функциональную библиотеку, так и Excelutils.

Я создал лист Excel с заголовком, содержащим описание, Test_Enable, тип локатора, значение локатора и статус.В Test_Enable для каждой опции меню я упоминаю Yes, а для других я упоминаю No.

Например, у меня есть 5 меню на экране, и если какое-либо меню отключено, оно должно перейти к следующему меню и перейти между шагами и продолжить выполнение.Поскольку мой лист Excel содержит все этапы тестирования, включая меню и другие действия, он должен перейти с одного Yes на другое Yes, если меню отключено.

Файл сценария драйвера

public class DriverScript {

    AppiumDriver driver;
    ExtentReports report;
    ExtentTest logger;

    public void startTest() throws Throwable
    {
        ExcelFileUtil excel = new ExcelFileUtil();

        for(int i=1;i<=excel.rowcount("MasterTestCases");i++)
        {
            String Modulestatus="";
             if (excel.getData("MasterTestCases", i, 3).equalsIgnoreCase("Y"))
            {
                String TCModule = excel.getData("MasterTestCases",i, 1);
                //Generate Extent Reports

                report = new ExtentReports("C:\\Users\\dnandan\\appiumtesting\\Rcm\\src\\Reports\\"+TCModule+".html"+"_"+ FunctionLibrary.generateDate());
                logger = report.startTest(TCModule);

                int row_count = excel.rowcount(TCModule);
                List<Integer> allLinks = new ArrayList<Integer>();
                int count = 0;
                for(int k=1;k<=row_count;k++){
                    String Test_Enable = excel.getData(TCModule, k, 1);
                    if(StringUtils.equalsIgnoreCase(Test_Enable, "Y"))
                    {
                        allLinks.add(k);
                    }

                }
                //Corresponding sheets

                for(int j=1;j<=row_count;j++)
                {
                    String Description = excel.getData(TCModule, j, 0);
                    String Test_Enable = excel.getData(TCModule, j, 1);
                    String Object_Type = excel.getData(TCModule, j, 2);
                    String Locator_Type = excel.getData(TCModule, j, 3);
                    String Locator_Value = excel.getData(TCModule, j, 4);
                    String Locator_Value1 = excel.getData(TCModule, j, 5);
                    String Locator_Value2 = excel.getData(TCModule, j, 6);
                    String Test_Data = excel.getData(TCModule, j, 7);
                    String Test_Data1 = excel.getData(TCModule, j, 8);



                    if (Test_Enable.equalsIgnoreCase("N"))
                    {
                        try {
                            if (Object_Type.equalsIgnoreCase("appInstall")) {
                                FunctionLibrary.appInstall();
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("launchApp")) {
                                driver = FunctionLibrary.launchApp(driver);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("uninstallApp")) {
                                FunctionLibrary.uninstallApp(driver);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("openApplication")) {
                                FunctionLibrary.openApplication(driver);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("waitForElement")) {
                                FunctionLibrary.waitForElement(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("typeAction")) {
                                FunctionLibrary.typeAction(driver, Locator_Type, Locator_Value, Test_Data);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("multipletypeAction")) {
                                FunctionLibrary.multipletypeAction(driver, Locator_Type, Locator_Value, Test_Data, Test_Data1);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("clickAction")) {
                                FunctionLibrary.clickAction(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("closeApplication")) {
                                FunctionLibrary.closeApplication(driver);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("getText")) {
                                FunctionLibrary.getText(driver, Locator_Type, Locator_Value, Test_Data);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("mouseOveractions")) {
                                FunctionLibrary.mouseOveractions(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("titleValidation")) {
                                FunctionLibrary.titleValidation(driver, Test_Data);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("touch")) {
                                FunctionLibrary.touch(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("Ifdisplayed")) {
                                FunctionLibrary.Ifdisplayed(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("validations")) {
                                FunctionLibrary.validations(driver, Locator_Type, Locator_Value, Test_Data);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("ifExistsTaponElement")) {
                                FunctionLibrary.ifExistsTaponElement(driver, Locator_Type, Locator_Value, Locator_Value1);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("frameFunction")) {
                                FunctionLibrary.frameFunciton(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("generateDate")) {
                                FunctionLibrary.generateDate();
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("mobilebackButton")) {
                                FunctionLibrary.mobilebackButton(driver);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("webdriver_wait")) {
                                FunctionLibrary.webdriver_wait(driver);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("explicitWait")) {
                                FunctionLibrary.explicitWait(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("termsandconditions")) {
                                FunctionLibrary.termsandconditions(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("scrolldown")) {
                                FunctionLibrary.scrolldown(driver);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("scrollup")) {
                                FunctionLibrary.scrollup(driver);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("scrollLeft")) {
                                FunctionLibrary.scrollLeft(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("scrollRight")) {
                                FunctionLibrary.scrollRight(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("swipeLeft")) {
                                FunctionLibrary.swipeLeft(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("swipeRight")) {
                                FunctionLibrary.swipeRight(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("waitfewseconds")) {
                                FunctionLibrary.waitfewseconds(driver);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("cellData")) {
                                FunctionLibrary.cellData(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("backloopingbutton")) {
                                FunctionLibrary.backloopingbutton(driver);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("tapelementmultipletimes")) {
                                FunctionLibrary.tapelementmultipletimes(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("multiplesendkeys")) {
                                FunctionLibrary.multiplesendkeys(driver, Locator_Type, Locator_Value, Locator_Value1, Test_Data, Test_Data1);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("taponthreedots")) {
                                FunctionLibrary.taponthreedots(driver, Locator_Type, Locator_Value, Locator_Value1);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("clickIfEnabled")) {
                                FunctionLibrary.clickIfEnabled(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("checkEnable")) {
                                FunctionLibrary.checkEnable(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("taporskip")) {
                                FunctionLibrary.taporskip(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("checkDisabled")) {
                                FunctionLibrary.checkDisabled(driver, Locator_Type, Locator_Value);
                                logger.log(LogStatus.INFO, Description);
                            }
                            if (Object_Type.equalsIgnoreCase("isdisabled")) {
                                FunctionLibrary.isdisabled(driver, Locator_Value,Locator_Value1,Test_Data);
                                logger.log(LogStatus.INFO, Description);
                            }
                       /* if(Object_Type.equalsIgnoreCase("sukiliscreen"))
                        {
                            FunctionLibrary.sukiliscreen(Locator_Value,Test_Data);
                            logger.log(LogStatus.INFO,Description);
                        }*/
                            excel.setData(TCModule, j, 9, "Pass");
                            Modulestatus = "true";
                            logger.log(LogStatus.PASS, Description + " Pass ");

                        } catch (Exception e) {
                            excel.setData(TCModule, j, 9, "Fail");
                            Modulestatus = "false";
                            logger.log(LogStatus.FAIL, Description + " Fail ");
                            //Generating Screenshots

                            File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
                            FileHandler.copy(scrFile, new File("C:\\Users\\dnandan\\appiumtesting\\Rcm\\src\\Screenshots\\" + Description + "_" + FunctionLibrary.generateDate() + ".jpg"));

                            break;
                        } catch (AssertionError e) {
                            excel.setData(TCModule, j, 9, "Fail");
                            Modulestatus = "false";

                            logger.log(LogStatus.FAIL, Description + " Fail ");
                            //Generating Screenshots

                            File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
                            FileHandler.copy(scrFile, new File("C:\\Users\\dnandan\\appiumtesting\\Rcm\\src\\Screenshots\\" + Description + "_" + FunctionLibrary.generateDate() + ".jpg"));

                            break;
                        }

                    }
                    else if(Test_Enable.equalsIgnoreCase("Y"))
                    {

                        if (Object_Type.equalsIgnoreCase("isdisabled"))
                        {

                            FunctionLibrary.isdisabled(driver, Locator_Value, Locator_Value1, Test_Data);
                            excel.setData(TCModule, j, 9, "Pass");
                            logger.log(LogStatus.PASS, Description+ " Pass ");
                            System.out.println("Test enable passed");
                            for(int l = allLinks.get(count); l <= row_count; l++)
                            {
                                if(Test_Enable.equalsIgnoreCase("Y"))
                                {
                                    if(Object_Type.equalsIgnoreCase("isdisabled"))
                                    {
                                        FunctionLibrary.isdisabled(driver, Locator_Value, Locator_Value1, Test_Data);

                                    }
                                    break;
                                }
                                count++;
                            }


                            /*List<String> allLinks = Collections.singletonList(excel.getData(TCModule, i, 2));
                            Iterator itr = allLinks.iterator();
                            while (itr.hasNext())
                            {

                                if(Test_Enable.equalsIgnoreCase("Yes"))
                                {

                                    if (Object_Type.equalsIgnoreCase("clickAction"))
                                    {
                                        FunctionLibrary.clickAction(driver, Locator_Type, Locator_Value);
                                        excel.setData(TCModule, j, 9, "Skip");
                                        logger.log(LogStatus.SKIP, Description);
                                    }
                                }
                            }*/
                        }
                    }
                }

                if(Modulestatus.equalsIgnoreCase("true"))
                {
                    excel.setData("MasterTestCases", i, 4, "Pass");
                }
                else if(Modulestatus.equalsIgnoreCase("false"))
                {
                    excel.setData("MasterTestCases", i, 4, "Fail");
                }
                else
                {
                    excel.setData("MasterTestCases", i, 4, "Skip");
                }

            }
            else
            {
                excel.setData("MasterTestCases", i, 4, "Not Executed");
            }

            report.endTest(logger);
            report.flush();

        }

    }

}

isdisabled method from Functionallibrary class:

 public static void isdisabled(AppiumDriver driver,String locatorValue,String locatorValue1,String data) throws Throwable {

        try {
            if (driver.findElement(By.xpath(locatorValue)).isDisplayed()) {
                boolean trew = driver.findElement(By.xpath(locatorValue)).isEnabled();
                System.out.println(trew);
                Thread.sleep(5000);
                if (trew) {
    /*String menu= driver.findElement(By.xpath(locatorValue)).getText();
    System.out.println(menu);
    driver.findElement(By.xpath(locatorValue)).click();*/
                    String Title = driver.findElement(By.xpath(locatorValue)).getText();
                    System.out.println(Title);
                    // locatorvalue  = //android.widget.LinearLayout[1]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.widget.TextView
                    driver.findElement(By.xpath(locatorValue)).click();
                    Thread.sleep(5000);
                    String titlexx = driver.findElement(By.xpath(locatorValue1)).getText();
                    if (titlexx.equalsIgnoreCase(data)) {
                        String expected_tile = driver.findElement(By.xpath(locatorValue1)).getText();
                        System.out.println(expected_tile);
                    } else {
                        driver.findElement(By.xpath(locatorValue)).click();
                        System.out.println("page is not displayed");
                    }
                }
            } else {
                System.out.println("no element found due to disable");
            }

        }
        catch(Exception e)
        {
            System.out.println("Exception caught");

        }
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...