2017-01-16 120 views
0

在付款Webview中,我試圖通過Espresso測試選擇月份和/或年份(微調)。當我使用「webclick」時,沒有任何附加內容。Android Espresso:在webview中從微調器中選擇一個項目

web視圖部分:

<form method="post" action="https://mercanet.bnpparibas.net/cgis-payment-mercanet/demo/callresource?rsc=creditcard" name="DATA_CAPTURE"> 
<span id="span_sips_card_number_title" class="sips_card_number_title"> N° de carte : </span> 
<select name="CARD_VAL_MONTH" size="1" class="sips_expiry_month_card_input"> 
<option value="01" selected="selected"> 01-Janvier</option> 
<option value="02"> 02-Février</option> 
<option value="03"> 03-Mars</option> 
<option value="04"> 04-Avril</option> 
<option value="05"> 05-Mai</option> 
<option value="06"> 06-Juin</option> 
<option value="07"> 07-Juillet</option> 
<option value="08"> 08-Août</option> 
<option value="09"> 09-Septembre</option> 
<option value="10"> 10-Octobre</option> 
<option value="11"> 11-Novembre</option> 
<option value="12"> 12-Décembre</option></select> 
<input size="20" maxlength="19" autocomplete="off" name="CARD_NUMBER" id="CARD_NUMBER" class="sips_card_number_input" value="" type="text"> 
<span id="ID_EXPIRE_FIN" class="sips_expiry_date_card_title"> Expire fin : </span> 
<span id="ID_SLASH" class="sips_expiry_date_card_title">/</span> 
<select name="CARD_VAL_YEAR" size="1" class="sips_expiry_year_card_input"> 
<option value="17" selected="selected"> 2017</option> 
<option value="18"> 2018</option> 
<option value="19"> 2019</option> 
<option value="20"> 2020</option> 
<option value="21"> 2021</option> 
<option value="22"> 2022</option> 
<option value="23"> 2023</option> 
<option value="24"> 2024</option> 
<option value="25"> 2025</option> 
<option value="26"> 2026</option> 
<option value="27"> 2027</option> 
</select><br><script type="text/javascript"> 
<!-- 
function InfoCvv() { 
window.open('/images/logo_serveur/commun/cryptogramme_light.fr.html','A1','width=700,height=450, status=no, directories=no, toolbar=no, location=no, menubar=no,scrollbars=no, resizable=no') 
} 
// --> 
</script> 
<a href="javascript:InfoCvv()" onmouseover="window.status='N° de contrôle au dos de la carte'" class="sips_cryptogram_example"> <span id="span_sips_popup_message" class="sips_popup_message">N° de contrôle au dos de la carte</span> </a>&nbsp;:&nbsp;<input size="3" maxlength="3" autocomplete="off" name="CVV_KEY" id="CVV_KEY" class="sips_cryptogram_code_input" value="" type="text"><div class="sips_bloc_info_cvv"></div><br><br> 
<span id="span_sips_submit_message" class="sips_submit_message"> Vous avez complété correctement le formulaire, vous pouvez </span> 
<input name="USER" id="USER" value="[email protected]" type="hidden"> 
<input name="MERCHANT_ID" id="MERCHANT_ID" value="082584341411111" type="hidden"> 
<input name="MERCHANT_COUNTRY" id="MERCHANT_COUNTRY" value="fr" type="hidden"> 
<input name="CARD_TYPE" id="CARD_TYPE" value="CB" type="hidden"> 
<input name="CARD_MODE" id="CARD_MODE" value="CARTE" type="hidden"> 
<input name="CUSTOMER_COUNTRY" id="CUSTOMER_COUNTRY" value="" type="hidden"> 
<input name="PAIEMENT" value="VALIDER" class="sips_submit_button" type="submit"></form> 

我用:

onWebView(withId(R.id.webview_payment)).forceJavascriptEnabled(); 

,並嘗試模擬在每月的點擊和/或一年,這兩種方法:

onWebView(withId(R.id.webview_payment)) 
.withElement(findElement(Locator.CLASS_NAME,"sips_expiry_year_card_input")) 
.perform(webClick()); 

onWebView(withId(R.id.webview_payment)) 
.withElement(findElement(Locator.NAME,"CARD_VAL_MONTH")) 
.perform(webClick()); 

這些方法都不起作用(沒有下拉菜單)。我進入調試模式的迴應:

brandNew = false 
result = Evaluation: status: 0 value: null hasMessage: false message: null 

你知道爲什麼這不起作用嗎?

回答

0

發現有什麼問題。網頁點擊作品(選中字段),但沒有顯示下拉菜單。然後我們必須選擇Locator.XPATH的選項。

因此,在這種情況下,解決方案選擇其他月份和年份是:

onWebView(withId(R.id.webview_payment)) 
      .withElement(findElement(Locator.NAME,"CARD_VAL_MONTH")) 
      .perform(webClick()); 

    onWebView(withId(R.id.webview_payment)) 
      .withElement(findElement(Locator.XPATH,"//option[@value='02']")) 
      .perform(webClick()); 


    onWebView(withId(R.id.webview_payment)) 
      .withElement(findElement(Locator.NAME,"CARD_VAL_YEAR")) 
      .perform(webClick()); 

    onWebView(withId(R.id.webview_payment)) 
      .withElement(findElement(Locator.XPATH,"//option[@value='18']")) 
      .perform(webClick()); 
相關問題