appium測試代碼nullpoint

來源:互聯網
上載者:User

標籤:log   程式   orm   phone   this   imp   參考   mit   字元   

     今天寫了個簡單向上滑動,執行到向上滑動操作,報nullpoint異常,經過各種亂碰終於解決了,現記錄一下過程,以備以後參考!

      環境背景:java+testng+appium

      在@Test下調用 direct_slide_f("up");  這個方法的時候,最初成員變數up我是沒有初始化的,只是簡單聲明了一下,然後在調用的的時候,沒有傳“up”,居然傳了變數up;

      且    if(direct.equals(this.getUp())){     這句代碼之前是   if(direct.equals(up)){  這樣寫的,所以就報了nullpoint。

      原因就是direct_slide_f 接收的應該是一個具體的字串參數,而我傳了一個沒有初始化的變數 up,所以程式就不知道用什麼去與   up 進行比較的,當然這個時候 up本身也沒有值,

      其實就等於拿自己和自己做對比,然後就報nullpoint了!

     修改方案:將變數up初始化,然後調用方法direct_slide_f的時候,傳入字串“up”,而非變數up,執行就不報nullpoint了!

     總結:如果在新添加一段代碼後,代碼報nullpoint,首先檢查下新添加代碼中變數和方法的關係!
public class Login extends KeyClass implements BaseExecuteInterface{
    public Login(){}
    private boolean isInstall = false;
    public static AndroidDriver driver;
    public  final String up = "up";


    @Test
    public void login_f_tmp() throws Exception{
        String username="18576816231";
        String passwd="123456";
        driver.findElement(By.id("com.jiubei.shop:id/telephoneEt")).sendKeys(username);
        Thread.sleep(2000);
        driver.findElement(By.id("com.jiubei.shop:id/ed_pwd")).sendKeys(passwd);
        Thread.sleep(2000);
        //System.out.println("test");
        //key();
        driver.findElement(By.id("com.jiubei.shop:id/submitTv")).click();
        System.out.println("test2");
        //已進入到APP首頁
        Thread.sleep(4000);
        driver.findElement(By.name("我的")).click();
        sleep(1);
      direct_slide_f("up");
    }
    // 調用出null 指標,現在已修複
    public  void direct_slide_f(String direct){

        TouchAction touchAction =new TouchAction(driver);
        if(direct.equals(this.getUp())){    
            touchAction.longPress(360, 720).moveTo(360, 600).release().perform();
            System.out.println(up);
            sleep(3);
        }else if(direct.equals((this.getDown())){
            touchAction.longPress(360, 600).moveTo(360, 720).release().perform();
            sleep(3);
        }else {
            System.out.println("參數錯誤");
            sleep(3);
        }
    }

    唉,測試代碼能力一般,總是出各種白菜錯誤,各位請隨便噴!哈哈哈哈!

appium測試代碼nullpoint

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.