简体   繁体   English

令人难忘的信息写作测试-随机字符(从10中选择3)

[英]Writing test for memorable information - random characters (selection off 3 from 10)

I'm trying to write a script to login to an application that requires authentication via a memorable word, however the word is 10 digits long and 3 characters are selected at random as per the following: 我正在尝试编写一个脚本来登录需要通过一个难忘的单词进行身份验证的应用程序,但是该单词的长度为10位,并且根据以下内容随机选择了3个字符:

Please enter characters 1, 2 and 8 from your memorable information then click on the continue button.


Character 1 :
Character 2 :
Character 8 :

Below is code for the label: 以下是标签的代码:

<label for="frmentermemorableinformation1:strEnterMemorableInformation_memInfo1">Character 1 </label>

Using selenium WebDriver JAVA, how could this be achieved? 使用Selenium WebDriver JAVA,如何实现?

So,need a IF label = 1 then select A from the dropdown. 因此,需要IF标签= 1,然后从下拉列表中选择A。 I know the password, just not what characters will be asked on page load, as these will change each time, so need logic added. 我知道密码,只是不知道在页面加载时会问什么字符,因为这些字符每次都会更改,因此需要添加逻辑。

Thanks a lot. 非常感谢。

Maybe you don't have control over this page but generally sites use a password instead of this ... odd way of verifying security. 也许您无法控制此页面,但通常站点使用密码而不是此密码...验证安全性的奇怪方法。 If you can enter the entire password, there's no need to identify individual characters from the entire "memorable word." 如果您可以输入整个密码,则无需从整个“难忘的单词”中识别出各个字符。 Anyway... 无论如何...

I would do something like the below. 我会做类似下面的事情。 You know the memorable word and you can find the indices from the labels like "Character 1", "Character 2", and "Character 8".. which in this case are 1, 2, 8. Now you get characters 1, 2, and 8 from the memorable word and place them into the relevant dropdowns. 您知道这个令人难忘的单词,并且可以从“ Character 1”,“ Character 2”和“ Character 8”之类的标签中找到索引。在这种情况下,它们是1、2、8。现在您将获得字符1、2 ,然后从难忘的单词中选择8,并将其放入相关的下拉菜单中。

public class Sample
{
    public static void main(String[] args)
    {
        WebDriver driver = new FirefoxDriver();
        String memorableWord = "memorable1";

        // set up the locators for the labels that contain the information on which characters will be needed from the memorable word
        By char1 = By.cssSelector("label[for='frmentermemorableinformation1:strEnterMemorableInformation_memInfo1']");
        By char2 = By.cssSelector("label[for='frmentermemorableinformation2:strEnterMemorableInformation_memInfo2']");
        By char3 = By.cssSelector("label[for='frmentermemorableinformation3:strEnterMemorableInformation_memInfo3']");

        // get the indices from the labels
        int index1 = getNumber(driver.findElement(char1).getText().trim());
        int index2 = getNumber(driver.findElement(char2).getText().trim());
        int index3 = getNumber(driver.findElement(char3).getText().trim());

        // from your description, it sounds like the letters are being chosen from a SELECT so I used that in the code below
        // I don't know how to find the SELECT since that HTML was not provided so I've used sample locators below
        // basically it grabs the SELECT and then chooses the letter based on it's position in the memorable word
        new Select(driver.findElement(By.id("test1"))).selectByVisibleText(memorableWord.substring(index1, index1 + 1));
        new Select(driver.findElement(By.id("test2"))).selectByVisibleText(memorableWord.substring(index2, index2 + 1));
        new Select(driver.findElement(By.id("test3"))).selectByVisibleText(memorableWord.substring(index3, index3 + 1));
    }

    public static int getNumber(String label)
    {
        // takes "Character 1", splits it into two parts, takes the second part (the number) and converts it to an int and returns it
        return Integer.valueOf(label.split(" ")[1]);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM