Функция нажатия Appium не щелкает - PullRequest
0 голосов
/ 01 ноября 2019

Я автоматизирую приложение для Android. Сценарий похож на логин пользователя и заходит на страницу. Все предыдущие клики работают. Но когда скрипт автоматизации попадает на страницу. Он не щелкает элемент и даже не выдает ошибку и переключается на следующий оператор. Я не знаю, в чем проблема, или заявление не выполняется, или что еще проблема будет. У меня есть 3 класса. Один - это тестовый класс, имеющий методы тестирования, а два других - объекты страницы.

Это мой тестовый класс:

public class AppTest{

String appiumPort ="4723";
String serverIp ="0.0.0.0";
LoginPage lPage;
 //static IOSDriver<IOSElement> driver;
public  AppiumDriver<MobileElement> driver;
ProgrammesPage p_page=null;

 public static URL url;


 @Test(priority=1)

    public void verify() throws MalformedURLException,SocketException  {

     DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability("deviceName", "sALMAN");
        cap.setCapability("udid", "FFY5T18423051220");  
        cap.setCapability("platformName", "Android");   
        cap.setCapability("automationName","UiAutomator2");
        cap.setCapability("platformVersion", "8.0");
        cap.setCapability("appPackage", "uk.org.humanfocus.hfi");   
        cap.setCapability("appActivity", "uk.org.humanfocus.hfi.Home.MainActivity");
        cap.setCapability("autoGrantPermissions", "true");
        URL url = new URL("http://127.0.0.1:4723/wd/hub");

        driver = new AppiumDriver<MobileElement>(url,cap);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

         lPage=new LoginPage(driver);
         lPage.validateLoginpage();
          boolean check= lPage.validateLoginpage();

             // = lPage.loginTestCase();

             Assert.assertTrue(check); 

    }


 @Test(priority=2)
 public void verify2()throws SocketException
 {
      lPage=new LoginPage(driver);

        boolean check1=lPage.TestdoLoginWIthValues();

        Assert.assertTrue(check1==true);
 }

 @Test(priority=3)

 public void test3() throws SocketException
    {
        lPage=new LoginPage(driver);

        boolean check1=lPage.loginTestCase();

        Assert.assertTrue(check1==true);

    }

 @Test(priority=4)

 public void test4() throws SocketException
    {
        lPage=new LoginPage(driver);

        boolean check1=lPage.TestGotoHomePage();

        Assert.assertTrue(check1==true);

    }

 @Test(priority=5)

     public void test5() throws InterruptedException, SocketException 
        {
            lPage=new LoginPage(driver);


            boolean check1=lPage.goToTrainings();

            Assert.assertTrue(check1);

        }





 @Test(priority=7)
// @Order(7)
// @DisplayName("Verify that the continue button is not clickable at the first time to start a training")
 public void test7() 
    {
        p_page=new ProgrammesPage(driver);
        boolean check1=p_page.verifyContinueBtnDisable();

        Assert.assertTrue(check1);

    }

 @Test(priority=8)
// @Order(8)
// @DisplayName("Verify that after starting a training the Next button is by default disable in the first section")
 public void test8() 
    {
        p_page=new ProgrammesPage(driver);
        boolean check1=p_page.verifyVideoNextBtnDIsable();
        Assert.assertTrue(check1);

    }

}

А это мой класс programmepage, имеющий идентификаторы элементов для страницы.

 public class ProgrammesPage {
    //constructor to initialize ProgrammesPage Class with IOSDriver with 
    pageFactory design pattern
   AppiumDriver<MobileElement> driver;
   public ProgrammesPage(AppiumDriver<MobileElement> driver) {
       this.driver = driver;
      // PageFactory.initElements(new AppiumFieldDecorator(driver), this);
       PageFactory.initElements(new AppiumFieldDecorator(driver), this);
   }




    //this method verifies that continue button is disabled for the first time 
    public boolean verifyContinueBtnDisable()
    {
        System.out.println("verify methed starts");





        MobileElement el1 = (MobileElement) driver.findElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.ListView/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.TextView");
        el1.click();


        //driver.findElementById("uk.org.humanfocus.hfi:id/textView_select_code").click();
        //program_code.click();


        System.out.println("Clicked");
        boolean verify=continue_btn.isEnabled();

        if(verify==false)
        {
            verify=true;
        }
        else
        {
            verify=false;
        }
        return verify;

    }

    //@SuppressWarnings("deprecation")
    public boolean verifyVideoNextBtnDIsable()
    {
        program_start_btn.click();
        boolean isElementPresent;
        isElementPresent = video_next_btn.isEnabled();

        if(isElementPresent==false)
        {
            return true;
        }
        else
        {
            return false;
        }
    }



     /**
        * All elements of this Page are identified below with their respective element locators 
        * element locator like-> by.name , by,xpath, by.id etc
        */


        @FindBy(id = "uk.org.humanfocus.hfi:id/textView_select_code") 
        public MobileElement program_code;

        @FindBy(id = "uk.org.humanfocus.hfi:id/btn_continue")
        public MobileElement continue_btn;


        @FindBy(id = "uk.org.humanfocus.hfi:id/textView_select_title") 
        public MobileElement programme_title;

        @FindBy(xpath = "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.support.v7.widget.LinearLayoutCompat/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.TextView[2]")
        public MobileElement program_code_match;

        @FindBy(id = "uk.org.humanfocus.hfi:id/tv_programme_title")
        public MobileElement programme_title_match;

        @FindBy(id = "uk.org.humanfocus.hfi:id/btn_start")
        public MobileElement program_start_btn;

        @FindBy(xpath = "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup[1]/android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ImageView[1]")
        public MobileElement video_click_btn;

        @FindBy(id = "uk.org.humanfocus.hfi:id/btn_next")
        public MobileElement video_next_btn;

        @FindBy(name = "Next")
        public MobileElement document_next_btn;





        @FindBy(name = "Yes")
        public MobileElement exit_yes_btn;

        @FindBy(name = "Next")
        public MobileElement question_next_btn;

        //question1
        @FindBy(name = "one way")
        public MobileElement first_question_option_1;

        @FindBy(name = "two way")
        public MobileElement first_question_option_2;

        @FindBy(name = "three way")
        public MobileElement first_question_option_3;


        //questions2 
        @FindBy(name = "Kashif")
        public MobileElement second_question_option_1;

        @FindBy(name = "Murtaza")
        public MobileElement second_question_option_2;

        @FindBy(name = "Bravo")
        public MobileElement second_question_option_3;


        //question3
        @FindBy(name = "this way")
        public MobileElement third_question_option_1;

        @FindBy(name = "that")
        public MobileElement third_question_option_2;

        @FindBy(name = "not now")
        public MobileElement third_question_option_3;

        @FindBy(name = "next day")
        public MobileElement third_question_option_4;




        @FindBy(name = "3")
        public MobileElement total_questions;

        @FindBy(name = "0")
        public MobileElement correct_questions_0;

        @FindBy(name = "1")
        public MobileElement correct_questions_1;

        @FindBy(name = "2")
        public MobileElement correct_questions_2;

        @FindBy(name = "3")
        public MobileElement correct_questions_3;



        @FindBy(name = "Fail")
        public MobileElement fail;

        @FindBy(name = "Pass")
        public MobileElement pass;

        @FindBy(name = "Retake Training")
        public MobileElement retake_training_btn;


   }

1 Ответ

0 голосов
/ 02 ноября 2019

Сначала отладьте код и проверьте, выполняется ли соответствующая строка или нет. Если во время отладки ваш код работает, вам нужно использовать статическое или динамическое ожидание. Также в appium вам нужно использовать класс «TouchAction» для различных жестов вместо обычной функции щелчка.

...