Using Selenium IDE with random values

前端 未结 12 1861
囚心锁ツ
囚心锁ツ 2020-12-04 07:49

Is it possible to create Selenium tests using the Firefox plugin that use randomly generated values to help do regression tests?

The full story: I w

相关标签:
12条回答
  • One more solution, which I've copied and pasted into hundreds of tests :

    <tr>
        <td>store</td>
        <td>javascript{var myDate = new Date(); myDate.getFullYear()+&quot;-&quot;+(myDate.getMonth()+1)+&quot;-&quot;+myDate.getDate()+&quot;-&quot;+myDate.getHours()+myDate.getMinutes()+myDate.getSeconds()+myDate.getMilliseconds();}</td>
        <td>S_Unique</td>
    </tr>
    <tr>
        <td>store</td>
        <td>Selenium Test InternalRefID-${S_Unique}</td>
        <td>UniqueInternalRefID</td>
    </tr>
    <tr>
        <td>store</td>
        <td>Selenium Test Title-${S_Unique}</td>
        <td>UniqueTitle</td>
    </tr>
    <tr>
        <td>store</td>
        <td>SeleniumEmail-${G_Unique}@myURL.com</td>
        <td>UniqueEmailAddress</td>
    </tr>
    

    Each test suite begins by setting a series of variables (if it's a big suite, use a separate file like Set_Variables.html). Those variables can then be used throughout your suite to set, test, and delete test data. And since the variables use the date rather than a random number, you can debug your test suite by looking for the objects which share a date.

    0 讨论(0)
  • 2020-12-04 08:03

    While making sense of RajendraChary's post above, I spent some time writing a new Selenium IDE extension.

    My extension will let the user populate a variable with lorem ipsum text. There are a number of configurable options and it's turned into a nice little command. You can do things like "5 words|wordcaps|nomarks" to generate 5 lorem ipsum words, all capitalized, without punctuation.

    I've thoroughly explained installation and usage as well as provided the full codebase here

    If you take a peek at the code you'll get an idea of how to build similar functionality.

    0 讨论(0)
  • 2020-12-04 08:10

    (Based on Thilo answer) You can mix literals and random numbers like this:

    javascript{"joe+" + Math.floor(Math.random()*11111) + "@gmail.com";}
    

    Gmail makes possible that automatically everything that use aliases, for example, joe+testing@gmail.com will go to your address joe@gmail.com

    Multiplying *11111 to give you more random values than 1 to 9 (in Thilo example)

    0 讨论(0)
  • 2020-12-04 08:12

    Math.random may be "good enough" but, in practice, the Random class is often preferable to Math.random(). Using Math.random , the numbers you get may not actually be completely random. The book "Effective Java Second Edition" covers this in Item #47.

    0 讨论(0)
  • 2020-12-04 08:16

    A one-liner for randomly choosing from a small set of alternatives:

    javascript{['brie','cheddar','swiss'][Math.floor(Math.random()*3)]}
    
    0 讨论(0)
  • 2020-12-04 08:17

    I made a little improvment to the function generateRandomString. When FF crashes, it's good to be able to use the same random number again.

    Basically, it will ask you to enter a string yourself. If you don't enter anything, it will generate it.

    function generateRandomString( length, chars ) { var string=prompt("Please today's random string",''); if (string == '') {for ( var i = 0 ; i < length ; i++ ) string += chars[ Math.floor( Math.random() * chars.length ) ]; return string;} else { return string;} }

    0 讨论(0)
提交回复
热议问题