Commit 86016f77 authored by Nandy Limachi's avatar Nandy Limachi

Script Selenium para Riot

parent 41e8d63d
var webdriver = require('selenium-webdriver');
var webdriver = require( 'selenium-webdriver' );
var until = webdriver.until;
var by = webdriver.By;
var fs = require( 'fs' );
var assert = require( 'assert' ),
test = require( 'selenium-webdriver/testing' );
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.firefox()).build();
test.describe( 'Testing', function() {
this.timeout( 50000 );
var driver;
driver.get('https://riot.im/app/#/login');
var doc = fs.readFileSync( 'room', 'utf-8' ).toString( );
driver.wait(until.elementLocated(by.name('username')), 10000, 'Could not locate the child element within the time specified');
var array = doc.split( '\n' );
driver.findElement(by.name('username')).sendKeys('example');
driver.findElement(by.name('password')).sendKeys('password456');
driver.findElement(by.id('advanced')).click();
driver.findElement(by.id('hsurl')).clear();
driver.findElement(by.id('hsurl')).sendKeys('https://matrix.agetic.gob.bo');
var user = array[ 0 ].substring( 10, array[ 0 ].length);
var pass = array[ 1 ].substring( 10, array[ 1 ].length);
var room = array[ 2 ].substring( 19, array[ 2 ].length);
driver.sleep(4000);
test.before( function() {
driver = new webdriver.Builder().withCapabilities( webdriver.Capabilities.chrome( ) ).build( );
});
driver.findElement(by.className('mx_Login_submit')).click();
test.it( 'Cargando Riot', function( ) {
driver.get( 'https://riot.im/app/#/login' );
driver.manage( ).window( ).maximize( );
driver.wait( until.titleIs(' Riot '), 20000 );
driver.sleep( 10000 );
});
driver.sleep(20000);
\ No newline at end of file
test.it( 'Ingresando', function( ) {
driver.wait(until.elementLocated( by.name( 'username' ) ), 10000, 'Could not locate the child element within the time specified' );
driver.findElement( by.name( 'username' ) ).sendKeys( user );
driver.findElement( by.name( 'password' ) ).sendKeys( pass );
driver.findElement( by.id( 'advanced' ) ).click( );
driver.findElement( by.id( 'hsurl' ) ).clear( );
driver.findElement( by.id( 'hsurl' ) ).sendKeys( 'https://matrix.agetic.gob.bo' );
driver.sleep( 5000 );
driver.wait(until.elementLocated( by.className( 'mx_Login_submit' ) ), 10000, 'Could not locate the child element within the time specified' );
driver.findElement( by.className( 'mx_Login_submit' ) ).click( );
driver.sleep( 20000 );
});
test.it( 'Comparando Salas', function( ) {
driver.wait( until.elementLocated( by.className( 'mx_RoomSubList' ) ), 10000, 'Could not locate the child element within the time specified' );
driver.findElement( by.xpath( '//*[@id="matrixchat"]/div/div[2]/aside[1]/div[2]/div[3]/div/div[3]/div[1]/div' ) ).click( );
driver.sleep(3000);
driver.findElement(by.xpath('//*[@id="matrixchat"]/div/div[2]/aside[1]/div[2]/div[3]/div/div[4]/div[1]/div/div[1]')).getAttribute('textContent').
then(function(number){
var sw = 0;
var i = 1;
for (var j = 1; j <= number; j++) {
driver.findElement(
by.xpath('//*[@id="matrixchat"]/div/div[2]/aside[1]/div[2]/div[3]/div/div[4]/div[2]/div['+ j +']/div/div[2]/div[1]')).
getAttribute('title').then(function(sala){
//Compara el nombre de las salas
if(room === sala){
sw = 1;
return sw;
}else{
sw = 0;
i ++;
return sw;
}
}).then(function(sw){
//Controla si se encontro la sala
driver.sleep(3000);
if( sw === 1 ){
return driver.findElement(
by.xpath('//*[@id="matrixchat"]/div/div[2]/aside[1]/div[2]/div[3]/div/div[4]/div[2]/div['+ i +']/div/div[2]/div[1]')).click();
}
else{
if( i > number ){
driver.findElement(by.xpath('//*[@id="matrixchat"]/div/div[2]/aside[1]/div[3]/div/div[4]/div')).click();
driver.findElement(by.xpath('//*[@id="mx_Dialog_Container"]/div/div[1]/div/div[3]/div[2]/input')).sendKeys(room);
return driver.findElement(by.xpath('//*[@id="mx_Dialog_Container"]/div/div[1]/div/div[4]/button[2]')).click();
}
}
});
}
return driver.sleep(5000);
});
});
test.it('Añadiendo Miembros a la Sala', function(){
var i = 4;
while (i < array.length && array[i]!='') {
var nmiembro = array[i].substring(2, array[i].length);
driver.wait(until.elementLocated(by.xpath('//*[@id="matrixchat"]/div/div[2]/aside[2]/div[3]/div')),10000);
driver.findElement(by.xpath('//*[@id="matrixchat"]/div/div[2]/aside[2]/div[3]/div')).click();
driver.sleep(5000);
driver.findElement(by.xpath('html/body/div/div/div[1]/div/div[4]/div[1]/textarea')).sendKeys(nmiembro);
driver.sleep(5000);
driver.findElement(by.xpath('//*[@id="mx_Dialog_Container"]/div/div[1]/div/div[5]/button')).click();
i++;
}
driver.findElement(by.xpath('//*[@id="matrixchat"]/div/div[2]/aside/div[3]/div/div[1]')).click();
driver.sleep(5000);
});
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment