0

單擊離子側面菜單按鈕,我試圖寫一個驗收測試,通過打開側面菜單,點擊退出按鈕進行登錄用戶。黑猩猩正在抱怨,Uncaught Error: element not visible。下面是我的測試:不能在黑猩猩驗收測試

it('user can log out @watch', function() { 
    //navigates to login form, fills in the form and submits, verifies that we see the hamburger (sidemenu) button. 
    loginUser(ROLE_TYPE_ADMIN); 

    //click the hamburger menu to slide open (reveal) the side menu 
    browser.click("button.ion-navicon"); 

    //wait for animation to finish 
    browser.pause(500); 

    //wait for my login button to be recognized 
    browser.waitForVisible('.mes-chimp-logout'); 

    //click the logout button (never gets this far – Uncaught Error: element not visible) 
    browser.click('.mes-chimp-logout'); 
}); 

很奇怪,我認爲,如果我拿出browser.click線,它成功,因爲這將意味着它是可見的,但下面的行抱怨說,它是不可見的。

其他一些見解:

  • 如果我參加了側面菜單按鈕,並把它貼在前臺的內容,側邊菜單之外,我可以得到它可以點擊
  • 外的前景內容側面菜單是ion-pane。它幻燈片揭示使用translate3d風格的側面菜單

我該如何克服這個錯誤,並單擊註銷(或任何側面菜單)按鈕?

+0

你能分享'waitForVisible'方法代碼? –

+0

@SaurabhGaur它的存在,browser.waitForVisible –

+0

所以看看那裏,可能它等待的知名度和返回WebElement以及因此沒有必要再次找到只做爲'browser.waitForVisible(「 MES-黑猩猩-註銷」)。點擊();'... :) –

回答

1

事實證明,即使我只打算與我選擇一個元素,實際上有兩個。在運行時,Ionic Framework似乎做了一些與離子菜單有關的重複工作,也許出於動畫目的,我不確定。在所有重複的元素中,一個永遠不可見或填充(角度模板未填充)。在控制檯中執行$('.mes-chimp-logout')時,會看到兩個元素出現。當你將鼠標懸停在好的上面時,它會突出顯示UI中的按鈕。當你將鼠標懸停在另外一個,沒有什麼亮點所以它從DOM或關閉屏幕爲分離/看不見的地方(這就是爲什麼WebDriverIO認爲這是不可見的 - 一個是,一個不是)。我結束了這樣做:

//get access to the element id of the second (index 1) copy of the element, the one I know is the visible, populated one. 
const logoutBtnElementID = browser.elements('.mes-chimp-logout').value[1].ELEMENT; 

//click it, using the target ID 
browser.elementIdClick(logoutBtnElementID);