Funções do Selenium IDE

De MSTECH wiki
Ir para: navegação, pesquisa

Introdução

Este documento tem o objetivo de listas as funções mais úteis para utilização no Selenium IDE.

Funções

Digita CPF válido e Assert CPF

 1 Selenium.prototype.doDigitaCPFValido = function(localizador, comPontuacao){
 2 
 3     var n1,n2,n3,n4,n5,n6,n7,n8,n9,d1,d2 = 0;
 4     var elemento = this.page().findElement(localizador);
 5     n1 = Math.round(Math.random() * 9);
 6     n2 = Math.round(Math.random() * 9);
 7     n3 = Math.round(Math.random() * 9);
 8     n4 = Math.round(Math.random() * 9);
 9     n5 = Math.round(Math.random() * 9);
10     n6 = Math.round(Math.random() * 9);
11     n7 = Math.round(Math.random() * 9);
12     n8 = Math.round(Math.random() * 9);
13     n9 = Math.round(Math.random() * 9);
14 
15     d1 = n9*2+n8*3+n7*4+n6*5+n5*6+n4*7+n3*8+n2*9+n1*10;
16     d1 = Math.round(d1 - (Math.floor(d1/11)*11));
17     d1 = 11 - d1;
18     if (d1>=10) d1 = 0;
19     d2 = d1*2+n9*3+n8*4+n7*5+n6*6+n5*7+n4*8+n3*9+n2*10+n1*11;
20     d2 = Math.round(d2 - (Math.floor(d2/11)*11));
21     d2 = 11 - d2;
22     if (d2>=10) d2 = 0;
23     var cpf='erro';
24 
25     if (comPontuacao=='true'){
26         cpf = ''+n1+n2+n3+'.'+n4+n5+n6+'.'+n7+n8+n9+'-'+d1+d2;
27     } else {
28         cpf = ''+n1+n2+n3+n4+n5+n6+n7+n8+n9+d1+d2;
29     }
30     this.page().replaceText(elemento, cpf);
31 }
32 
33  Selenium.prototype.assertCPFValido = function(localizador) {
34     var soma=0;
35     var resto=0;
36     var elemento = this.page().findElement(localizador);
37     var cpf = ""+elemento.value;
38     var resultado = true;
39     cpf = cpf.replace(".","");
40     cpf = cpf.replace(".","");
41     cpf = cpf.replace("-","");
42     if (cpf.length<11) resultado = false;
43     if (isNaN(cpf)) resultado = false;
44     if (cpf == "00000000000") resultado = false;
45 
46     for (i=1; i<=9; i++) {
47         soma = soma + parseInt(cpf.substring(i-1, i)) * (11 - i);
48     }
49 
50     resto = (soma * 10) % 11;
51     if ((resto == 10) || (resto == 11)) resto = 0;
52     if (resto != parseInt(cpf.substring(9, 10)) ) resultado = false;
53     soma = 0;
54 
55     for (i = 1; i <= 10; i++) {
56         soma = soma + parseInt(cpf.substring(i-1, i)) * (12 - i);
57     }
58 
59     resto = (soma * 10) % 11;
60     if ((resto == 10) || (resto == 11)) resto = 0;
61     if (resto != parseInt(cpf.substring(10, 11))) resultado = false;
62     Assert.matches("true",""+resultado);
63 }
64 <\syntaxhighlight>