[英]How can I mask the summary of an EditTextPreference when it is a masked password field?
[英]Can I verify that an input field is masked or shows the text?
使用 Java 和 webdriver,我試圖設置一個測試來驗證我輸入的密碼是否被屏蔽。 使用我的工具,我們有一個設置,允許您屏蔽密碼或顯示文本。 我想知道是否有人曾經用 Selenium 驗證過這樣的事情。
這是我想要檢查的設置 OFF - 在輸入字段中鍵入並驗證是否顯示文本 設置 ON - 在輸入字段中鍵入並驗證我的輸入是否被屏蔽
我相信瀏覽器會處理屏蔽,所以我不確定我是否可以做這個測試。 輸入字段的元素沒有任何關於掩碼的屬性。
謝謝你的幫助
如果輸入,請檢查type
屬性,如果是text
則文本未被屏蔽,如果是password
,則被屏蔽。
所以假設你的輸入字段如下
<input id="pw" type="password" blah>
您可以通過執行檢查該字段是否被屏蔽
WebElement password = driver.findElement(By.id("pwd"));
if (password.getAttribute("type") == "password"){
// if it is, do something
}else {
// not masked
}
(我的 GitHub 頁面正在花時間更新)這是您可以嘗試的 HTML:
<input type="text" id="regular" />
<input type="password" id="masked" />
並且使用Selenium框架入門,您的測試將看起來像這樣以驗證以確保該字段確實被屏蔽。
@Config(browser = Browser.CHROME, url = "http://ddavison.github.io/tests/maskedtextbox.htm")
public class MaskedText extends AutomationTest {
@Test
public void testMasked() {
// validate that the regular text box is not masked.
setText (By.id("regular"), "Unmasked")
.validateText (By.id("regular"), "Unmasked") // validate that this isn't masked.
.setText (By.id("masked"), "Masked")
.validateTextNot(By.id("masked"), "Masked") // validate that the text is not "Masked" if it is, then it isn't masking correctly.
;
}
}
當調用validateTextNot
,它將獲取該字段的文本,並返回******
並且Masked
不.equal
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.