第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

CodeceptJS / Puppeteer 無法識別“if”語句

CodeceptJS / Puppeteer 無法識別“if”語句

慕無忌1623718 2021-11-25 19:29:17
不太熟悉 js/node.js。使用 codeceptjs/puppeteer 進(jìn)行一些自動化測試?,F(xiàn)在正在嘗試編輯測試中的描述。但有時沒有描述——因此“編輯描述”按鈕不存在——而是有一個“添加描述”按鈕。所以我寫了一個 if 語句,指定 . 但代碼只是滾動它。語句是什么并不重要,它只是移動到下一行。當(dāng)前if (desc)和if(!desc)兩者都執(zhí)行相同的功能 - 它轉(zhuǎn)到 if 語句中的下一行。這會導(dǎo)致錯誤,因為已經(jīng)有描述,因此“添加描述”按鈕不可用。我不確定發(fā)生了什么。Scenario('test something', (I, userLoginPage, FBPagePage) => {    userLoginPage.validate();    I.click('//*[@id="card_611"]');       // clicks the card    var desc = '//*[@id="show_card_description"]/section/button';    // add description button    // tried 'Add description' but the result was the same    if (desc){     // this is where the error happens. it simply looks for the add description button     // no matter what button is there it decides to click the 'add description' button        I.click('//*[@id="show_card_description"]/section/button');    // click add desc button        I.fillField('//*[@id="description_editor_container"]/div[2]/div[1]',        'not admin user created this description thanks to automated testing');    // types this stuff         I.click('//*[@id="description_editor_container"]/button[1]');    // saves it         I.wait(1);}    I.click('//*[@id="show_card_description"]/section/h5/a');    // click edit desc button if a description already exists    I.fillField('//*[@id="description_editor_container"]/div[2]/div[1]', 'not admin user edited this description thanks to automated testing');    I.click('//*[@id="description_editor_container"]/button[1]');I.say('success!')});
查看完整描述

2 回答

?
Cats萌萌

TA貢獻(xiàn)1805條經(jīng)驗 獲得超9個贊

為您提供正確的上下文:您首先問的是 Node.js 問題,而不是 CodeceptJS 或 Puppeteer。


desc總是true因為你將它聲明為一個字符串,所以不管里面的代碼是什么if都會運行,正如你已經(jīng)發(fā)現(xiàn)的那樣。


您可以使用執(zhí)行以下操作:


const numOfElements = await I.grabNumberOfVisibleElements('#show_card_description section button'); // Use CSS locator instead of Xpath for easier readability


console.log(numOfElements); // Debug


if(numOfElements === 1) {

   …

}

另見https://codecept.io/helpers/Puppeteer#grabnumberofvisibleelements


查看完整回答
反對 回復(fù) 2021-11-25
?
喵喔喔

TA貢獻(xiàn)1735條經(jīng)驗 獲得超5個贊

維護(hù)人員不支持在場景函數(shù)中使用常規(guī)功能文件的 if 語句,將其作為由于意外結(jié)果進(jìn)行測試的不良做法,而是您必須在自定義幫助文件中執(zhí)行它們,如下所示:


   /**

   * Checks the specified locator for existance, if it exists, return true

   * If it is not found log a warning and return false.

   */


  async checkElement(locator) 

  {

    let driver = this.helpers["Appium"].browser;

    let elementResult = await driver.$$(locator);

    if (elementResult === undefined || elementResult.length == 0) 

    {

      //console.log("Locator: " + locator + " Not Found");

      return false;

    } 

    else if (elementResult[0].elementId) 

    {

      //console.log("Locator: " + locator + " Found");

      return true;

    }

  }

參考 - https://codecept.io/helpers/


查看完整回答
反對 回復(fù) 2021-11-25
  • 2 回答
  • 0 關(guān)注
  • 251 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號