piątek, 11 listopada 2011

RANDOM NAMES AND SURNAMES


Continuing work on our script – it’s still just a rough prototype and needs improvement.



























We commenced works on artificial lover. At the moment it’s just a rough prototype.

Cen-sor-ed.





Reminder: our script searches for eastwood in every label, if there are results it saves screenshot…

What to improve? Maybe it would be more realistic if script will test Ebay categories using not just one surname but random surnames of famous actors.

Generating random surnames is almost as easy as generating random number.

In Selenium IDE you can create your own commands in separate javascript files.

Open notepad, save the file wherever you want with “.js” extension. I’ll save it as surnames.js. Write these words:

Selenium.prototype means that file will create new Selenium command. Name this command, e.g. “storeRandomSurname”:
  
Notice: add “do” before command name and remember to write first letter of command in capital, although in Selenium first letter of this command will appear as small.

Our “storeRandomSurname” command will return value of function, let's call it SURNAME:
Now we have to create an array of surnames:

“row = new Array” is defining that this is an array. It’s your choice how many surnames will be in the file. In our example there are three.

Generating random surname is done by generating random number. Our random number is called “randno” and it can have value 0, 1 or 2:

Last thing is to assign random number to the appropriate row and surname:

Speaking in general names used in file (including name of the file) are up to you. Below there is whole file where I marked words/ names which are freely to choose but have to be exactly the same in whole file.

Notice for Polish users: sadly obtaining words from external javascript file doesn’t support polish letters. Instead of: ć ą you will get: æ ê etc.

Once file with surnames is ready you must install it in Selenium. Open Selenium and “options”:

Add path to your file in “Selenium Core extensions”:


Click OK, close Selenium, and open it again. There should be two new commands:
storeRandomSurname
storeRandomSurnameAndWait

We can use freshly created command in our Ebay script. storeRandomSurname command stores random surname to variable called, for example, “surname”. Then script puts this variable in a textbox instead of eastwood.

If you want to generate random surnames, names, street names etc. you don’t have to create many files. You can keep all of them in one file, e.g.:


easy to copy version:
Selenium.prototype.doStoreRandomSurname = function(SURNAME){

row = new Array
row[0]="eastwood"
row[1]="belluci"
row[2]="schwarzenegger"

randno = (Math.round((Math.random()*2)));

storedVars[SURNAME] = row[randno];
}



Selenium.prototype.doStoreRandomName = function(NAME){

actors = new Array
actors[0]="arnold"
actors[1]="monica"
actors[2]="clint"
actors[3]="sandra"

randomnumber = (Math.round((Math.random()*3)));

storedVars[NAME] = actors[randomnumber];
}














Because we used four names, string generating random number also changed, now it generates numbers form 0 to 3.

Now this file will create in Selenium these commands:
storeRandomSurname
storeRandomName

(+ of course “…AndWait” commands)

If you improve your file in that way remember to use different names for function, random number, array etc.

If you move your file to a different location remember to delete it from Selenium options and add it again.

Brak komentarzy:

Prześlij komentarz