I already created a test class, simple test class, but I cant give data to it, Somebody can explain me a little please here is my code, when i Run the test the cover is 14 % and I dont know how to give data, for exceptions and made it at leas the 75 %
public void cargaPacientes () {
lMSD = new List<Enrollee__c>();
bLista = true;
String strCredencial = '';
String strPoliza = '';
String strCertificado = '';
String strRfc = '';
String fNacimiento = '';
String nombres = '';
String Aseguradora = '';
String Contratante = '';
String query = '';
Boolean correcto = true;
integer cuentacriterios = 0;
string producto = '';
if (proveedor.Tipo_de_Proveedor__c == 'Dentista' || proveedor.Tipo_de_Proveedor__c == 'Clínica' || proveedor.Tipo_de_Proveedor__c == 'Hospital'){
producto = 'Dental';
}else if (proveedor.Tipo_de_Proveedor__c == 'Óptica'){
producto = 'Visión';
}
if((msd.DENTEGRA_ID_Number__c != null) && (msd.DENTEGRA_ID_Number__c != '')) {
strCredencial = ' and DENTEGRA_ID_Number__c like \'' + msd.DENTEGRA_ID_Number__c + '\'';
System.debug(':::: strCredencial = ' + strCredencial);
cuentacriterios = cuentacriterios + 1;
}
if((msd.Family_Number__c != null) && (msd.Family_Number__c != '')){
strCertificado = ' and Family_Number__c like \'' + msd.Family_Number__c + '\'';
System.debug(':::: strCertificado = ' + strCertificado);
cuentacriterios = cuentacriterios + 1;
}
if((msd.RFC__c != null) && (msd.RFC__c != '')){
strRfc = ' and RFC__c like \'%' + msd.RFC__c + '%\'';
System.debug(':::: strRfc = ' + strRfc);
cuentacriterios = cuentacriterios + 1;
}
if((msd.Policy_Number__c != null) && (msd.Policy_Number__c != '')){
strPoliza = ' and Policy_Number__c like \'%' + msd.Policy_Number__c + '%\' ';
System.debug(':::: strPoliza = ' + strPoliza);
cuentacriterios = cuentacriterios + 1;
}
if(msd.Birth_Date__c != null) {
fNacimiento = ' and Birth_Date__c = ' + String.valueOf(msd.Birth_Date__c);
System.debug(':::: fNacimiento = ' + fNacimiento);
cuentacriterios = cuentacriterios + 1;
}
if(msd.Name != null) {
nombres = ' and Name like \'%' + msd.Name + '%\' ';
System.debug(':::: nombres = ' + nombres);
cuentacriterios = cuentacriterios + 1;
}
if(msd.Contratante__c != null) {
Contratante = ' and Contratante__c like \'%' + msd.Contratante__c + '%\' ';
System.debug(':::: Contratante = ' + Contratante);
cuentacriterios = cuentacriterios + 1;
}
if(msd.Aseguradora__c != null) {
Aseguradora = ' and Aseguradora__c like \'%' + msd.Aseguradora__c + '%\' ';
System.debug(':::: Aseguradora = ' + Aseguradora);
cuentacriterios = cuentacriterios + 1;
}
//if(strCredencial != '' || strCertificado != '' || strRfc != '' || strPoliza != '' || fNacimiento != '' || nombres != '') {
if(cuentacriterios>1){
//query = 'Select e.Contact__c, e.Id, e.Name, e.Policy_Number__c, e.Family_Number__c, e.RFC__c, e.Birth_Date__c from Enrollee__c e where Cve_tipo_registro__c = \'Elegibilidad\' and OwnerId = \'' + userID + '\'' + strCredencial + strCertificado + strRfc + strPoliza + fNacimiento;
query = 'Select e.Contact__c, e.Id, e.Name, e.Policy_Number__c, e.Family_Number__c, e.RFC__c, e.Birth_Date__c, e.Plan__c,Product__c from Enrollee__c e where Cve_tipo_registro__c = \'Elegibilidad\' and Enrollee_Status__c = \'Elegible\' and Product__c = \'' + producto + '\'' + strCredencial + strCertificado + strRfc + strPoliza + fNacimiento + nombres + Contratante + Aseguradora;
System.debug(':::: query concatenado = ' + query);
lMSD = Database.query(query);
cuentacriterios = 0;
} else {
System.debug(':::: Sin criterios');
bLista = false;
correcto = false;
cuentacriterios = 0;
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'Debe filtrar al menos por dos criterios.'));
}
if(lMSD.size() == 0 && correcto == true) {
bLista = false;
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'No se obtuvieron resultados basado en sus criterios de búsqueda. Utilice un criterio diferente o comuníquese al Centro de Contacto para confirmar elegibilidad.'));
msd = new Enrollee__c();
}
if(lMSD.size() > 0) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Se encontraron ' + lMSD.size() + ' registros. Favor de seleccionar el registro que corresponda con el nombre de su paciente.'));
msd = new Enrollee__c();
}
here is My test Class
private static void cargaPacientesTesting(){
Test.startTest();
PortalProveedoresController obj = new PortalProveedoresController();
obj.cargaPacientes();
Test.stopTest();
}
Thank you Im stuck with this, thanks
Related
I want use the following function in pug, I tried so many thing but it won't run.
var a = ['','one ','two ','three ','four ', 'five ','six ','seven ','eight ','nine ','ten ','eleven ','twelve ','thirteen ','fourteen ','fifteen ','sixteen ','seventeen ','eighteen ','nineteen '];
var b = ['', '', 'twenty','thirty','forty','fifty', 'sixty','seventy','eighty','ninety'];
function inWords (num) {
if ((num = num.toString()).length > 9) return 'overflow';
n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
if (!n) return; var str = '';
str += (n[1] != 0) ? (a[Number(n[1])] || b[n[1][0]] + ' ' + a[n[1][1]]) + 'crore ' : '';
str += (n[2] != 0) ? (a[Number(n[2])] || b[n[2][0]] + ' ' + a[n[2][1]]) + 'lakh ' : '';
str += (n[3] != 0) ? (a[Number(n[3])] || b[n[3][0]] + ' ' + a[n[3][1]]) + 'thousand ' : '';
str += (n[4] != 0) ? (a[Number(n[4])] || b[n[4][0]] + ' ' + a[n[4][1]]) + 'hundred ' : '';
str += (n[5] != 0) ? ((str != '') ? 'and ' : '') + (a[Number(n[5])] || b[n[5][0]] + ' ' + a[n[5][1]]) + 'only ' : '';
return str;
}
I need to convert amount in words. For example, the amount I will get it from service is 9876, I need to display in a table "Nine Thousand Eight Hundred and Seventy Six" in a table.
I need to do this using angularjs. Please help me how can I do this.
JSFIDDLE
function convertNumberToWords(amount) {
var words = new Array();
words[0] = '';
words[1] = 'One';
words[2] = 'Two';
words[3] = 'Three';
words[4] = 'Four';
words[5] = 'Five';
words[6] = 'Six';
words[7] = 'Seven';
words[8] = 'Eight';
words[9] = 'Nine';
words[10] = 'Ten';
words[11] = 'Eleven';
words[12] = 'Twelve';
words[13] = 'Thirteen';
words[14] = 'Fourteen';
words[15] = 'Fifteen';
words[16] = 'Sixteen';
words[17] = 'Seventeen';
words[18] = 'Eighteen';
words[19] = 'Nineteen';
words[20] = 'Twenty';
words[30] = 'Thirty';
words[40] = 'Forty';
words[50] = 'Fifty';
words[60] = 'Sixty';
words[70] = 'Seventy';
words[80] = 'Eighty';
words[90] = 'Ninety';
amount = amount.toString();
var atemp = amount.split(".");
var number = atemp[0].split(",").join("");
var n_length = number.length;
var words_string = "";
if (n_length <= 9) {
var n_array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
var received_n_array = new Array();
for (var i = 0; i < n_length; i++) {
received_n_array[i] = number.substr(i, 1);
}
for (var i = 9 - n_length, j = 0; i < 9; i++, j++) {
n_array[i] = received_n_array[j];
}
for (var i = 0, j = 1; i < 9; i++, j++) {
if (i == 0 || i == 2 || i == 4 || i == 7) {
if (n_array[i] == 1) {
n_array[j] = 10 + parseInt(n_array[j]);
n_array[i] = 0;
}
}
}
value = "";
for (var i = 0; i < 9; i++) {
if (i == 0 || i == 2 || i == 4 || i == 7) {
value = n_array[i] * 10;
} else {
value = n_array[i];
}
if (value != 0) {
words_string += words[value] + " ";
}
if ((i == 1 && value != 0) || (i == 0 && value != 0 && n_array[i + 1] == 0)) {
words_string += "Crores ";
}
if ((i == 3 && value != 0) || (i == 2 && value != 0 && n_array[i + 1] == 0)) {
words_string += "Lakhs ";
}
if ((i == 5 && value != 0) || (i == 4 && value != 0 && n_array[i + 1] == 0)) {
words_string += "Thousand ";
}
if (i == 6 && value != 0 && (n_array[i + 1] != 0 && n_array[i + 2] != 0)) {
words_string += "Hundred and ";
} else if (i == 6 && value != 0) {
words_string += "Hundred ";
}
}
words_string = words_string.split(" ").join(" ");
}
return words_string;
}
<input type="text" name="number" placeholder="Number OR Amount" onkeyup="word.innerHTML=convertNumberToWords(this.value)" />
<div id="word"></div>
I refered this javascript fiddle. But I want to it in a angularjs.
I used this for Angular 8.
Input : 123456789.09 Output : twelve crore thirty four lakh fifty six thousand seven eighty nine point zero nine
n: string;
a = ['zero ', 'one ', 'two ', 'three ', 'four ', 'five ', 'six ', 'seven ', 'eight ', 'nine ', 'ten ', 'eleven ', 'twelve ', 'thirteen ', 'fourteen ', 'fifteen ', 'sixteen ', 'seventeen ', 'eighteen ', 'nineteen '];
b = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];
ngOnInit(): void {
console.log(this.inWords(123456789.09));
}
inWords (num): string {
num = Math.floor(num * 100);
if ((num = num.toString()).length > 11) { return 'overflow'; }
let n;
n = ('00000000' + num).substr(-11).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})(\d{1})(\d{1})$/);
if (!n) { return; } let str = '';
// tslint:disable-next-line:triple-equals
str += (n[1] != 0) ? (this.a[Number(n[1])] || this.b[n[1][0]] + ' ' + this.a[n[1][1]]) + 'crore ' : '';
// tslint:disable-next-line:triple-equals
str += (n[2] != 0) ? (this.a[Number(n[2])] || this.b[n[2][0]] + ' ' + this.a[n[2][1]]) + 'lakh ' : '';
// tslint:disable-next-line:triple-equals
str += (n[3] != 0) ? (this.a[Number(n[3])] || this.b[n[3][0]] + ' ' + this.a[n[3][1]]) + 'thousand ' : '';
// tslint:disable-next-line:triple-equals
str += (n[4] != 0) ? (this.a[Number(n[4])] || this.b[n[4][0]] + ' ' + this.a[n[4][1]]) : 'hundred';
// tslint:disable-next-line:triple-equals
str += (n[5]) ? (this.a[Number(n[5])] || this.b[n[5][0]] + ' ' + this.a[n[5][1]]) : '';
// tslint:disable-next-line:triple-equals
str += (n[6]) ? ((str != '') ? 'point ' : '') + (this.a[Number(n[6])] || this.b[n[6][0]] + ' ' + this.a[n[6][1]]) : '';
// tslint:disable-next-line:triple-equals
str += (n[7] != 0) ? (this.a[Number(n[7])] || this.b[n[7][0]] + ' ' + this.a[n[7][1]]) : '';
return str;
}
Define a filter to convert number to word such as following code:
angular.module('myModuleName')
.filter('convertToWord', function() {
return function(amount) {
var words = new Array();
words[0] = '';
words[1] = 'One';
words[2] = 'Two';
words[3] = 'Three';
words[4] = 'Four';
words[5] = 'Five';
words[6] = 'Six';
words[7] = 'Seven';
words[8] = 'Eight';
words[9] = 'Nine';
words[10] = 'Ten';
words[11] = 'Eleven';
words[12] = 'Twelve';
words[13] = 'Thirteen';
words[14] = 'Fourteen';
words[15] = 'Fifteen';
words[16] = 'Sixteen';
words[17] = 'Seventeen';
words[18] = 'Eighteen';
words[19] = 'Nineteen';
words[20] = 'Twenty';
words[30] = 'Thirty';
words[40] = 'Forty';
words[50] = 'Fifty';
words[60] = 'Sixty';
words[70] = 'Seventy';
words[80] = 'Eighty';
words[90] = 'Ninety';
amount = amount.toString();
var atemp = amount.split(".");
var number = atemp[0].split(",").join("");
var n_length = number.length;
var words_string = "";
if (n_length <= 9) {
var n_array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
var received_n_array = new Array();
for (var i = 0; i < n_length; i++) {
received_n_array[i] = number.substr(i, 1);
}
for (var i = 9 - n_length, j = 0; i < 9; i++, j++) {
n_array[i] = received_n_array[j];
}
for (var i = 0, j = 1; i < 9; i++, j++) {
if (i == 0 || i == 2 || i == 4 || i == 7) {
if (n_array[i] == 1) {
n_array[j] = 10 + parseInt(n_array[j]);
n_array[i] = 0;
}
}
}
value = "";
for (var i = 0; i < 9; i++) {
if (i == 0 || i == 2 || i == 4 || i == 7) {
value = n_array[i] * 10;
} else {
value = n_array[i];
}
if (value != 0) {
words_string += words[value] + " ";
}
if ((i == 1 && value != 0) || (i == 0 && value != 0 && n_array[i + 1] == 0)) {
words_string += "Crores ";
}
if ((i == 3 && value != 0) || (i == 2 && value != 0 && n_array[i + 1] == 0)) {
words_string += "Lakhs ";
}
if ((i == 5 && value != 0) || (i == 4 && value != 0 && n_array[i + 1] == 0)) {
words_string += "Thousand ";
}
if (i == 6 && value != 0 && (n_array[i + 1] != 0 && n_array[i + 2] != 0)) {
words_string += "Hundred and ";
} else if (i == 6 && value != 0) {
words_string += "Hundred ";
}
}
words_string = words_string.split(" ").join(" ");
}
return words_string;
};
});
Then in your templates (views) use this filter as follow:
{{amount | converToWord}}
For example to show inserted value in an input field:
<input type="text" name="number" placeholder="Number OR Amount" ng-model="myValue" />
<div id="word">{{myValue | convertToWord}}</div>
I want to convert number into words. Like 234 in word would be 2 hundred thirty-four. Similarly 1000 will be one thousand. Similarly 100 means one hundred.
Is there any library for this in angularjs. If then how we will write in angularjs directive/service so that we can use it again..
Create a words filter.
I got the "toWords" algorithm from this blog post: http://ravindersinghdang.blogspot.com/2013/04/convert-numbers-into-words-using.html
var app = angular.module('app',[]);
app.filter('words', function() {
function isInteger(x) {
return x % 1 === 0;
}
return function(value) {
if (value && isInteger(value))
return toWords(value);
return value;
};
});
var th = ['','thousand','million', 'billion','trillion'];
var dg = ['zero','one','two','three','four', 'five','six','seven','eight','nine'];
var tn = ['ten','eleven','twelve','thirteen', 'fourteen','fifteen','sixteen', 'seventeen','eighteen','nineteen'];
var tw = ['twenty','thirty','forty','fifty', 'sixty','seventy','eighty','ninety'];
function toWords(s)
{
s = s.toString();
s = s.replace(/[\, ]/g,'');
if (s != parseFloat(s)) return 'not a number';
var x = s.indexOf('.');
if (x == -1) x = s.length;
if (x > 15) return 'too big';
var n = s.split('');
var str = '';
var sk = 0;
for (var i=0; i < x; i++)
{
if ((x-i)%3==2)
{
if (n[i] == '1')
{
str += tn[Number(n[i+1])] + ' ';
i++;
sk=1;
}
else if (n[i]!=0)
{
str += tw[n[i]-2] + ' ';
sk=1;
}
}
else if (n[i]!=0)
{
str += dg[n[i]] +' ';
if ((x-i)%3==0) str += 'hundred ';
sk=1;
}
if ((x-i)%3==1)
{
if (sk) str += th[(x-i-1)/3] + ' ';
sk=0;
}
}
if (x != s.length)
{
var y = s.length;
str += 'point ';
for (var i=x+1; i<y; i++) str += dg[n[i]] +' ';
}
return str.replace(/\s+/g,' ');
}
window.toWords = toWords;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.js"></script>
<div ng-app="app">
<input type="text" ng-model="name" /> {{name | words}}
</div>
I have done this for Angular 8.
It also works for float/double numbers.
I'm trying to loop through a table, using Protractor, to see if a row contains a select element. Then select 1 of two particular options. Thus far the test 'passes' but nothing is actually being selected. My latest attempts are below.
it('should loop through table and select an option if listbox is available',
function () {
var table= element(by.xpath("//table[#id='tableID']"));
var count = table.length;
var currentType = "";
for (var i = 1; i <= count; i++) {
tableSelect(i);
}
function tableSelect(i) {
it('should loop through this table and associate', function () {
expect(table.isDisplayed()).toBe(true);
if (element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]")).isDisplayed()) {
if (element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]//select[matches(#ng-change,'listChange()')]")).isDisplayed()) {
var varOne = element(by.xpath("//table[#id='tableID']/" +
"tbody/tr[" + i + "]/td[4]/div/span/span")).getText();
if (currentType != "Moretext" || varOne.Length < 6) {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i +
"]/td[6]/div/span/div/select")).
element(by.cssContainingText('option',
'This is option A')).click();
}
else {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[6]/div/span/div/select")).element(by.cssContainingText('option', 'This is option B')).click();
}
}
else if (element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[1]/div/span/span")).isDisplayed()) {
currentType = element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[1]/div/span/span")).getText();
}
}
});
}
var saveBtn = elem(by.id('saveButton'));
expect(associateBtn.isDisplayed()).toBe(true);
expect(associateBtn.isEnabled()).toBe(true);
saveBtn.click();
});
This is attempt #2:
element.all(by.repeater('row in datarows')).then(function(rows) {
for (var i = 1; i <= rows.length; ++i) {
if (element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]//select[matches(#ng-change,'listChange()')]")).isDisplayed()) {
var varOne = element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[4]/div/span/span")).getText();
if (currentType != "MoreText" && varOne.Length < 6) {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[6]/div/span/div/select")).element(by.cssContainingText('option', 'This is option A')).click();
}
else {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[6]/div/span/div/select")).element(by.cssContainingText('option', 'This is option B')).click();
}
}
else if (element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[1]/div/span/span")).isDisplayed()) {
currentType = element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[1]/div/span/span")).getText();
}
}
});
This is the latest attempt:
var varOne = "";
var varTwo = "";
element.all(by.xpath("//table[#id='tableID']/tbody/tr")).then(function (rows) {
for (var i = 1; i < (rows.length); i++) {
console.log('rowcount = ' + i);
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]")).isDisplayed().then(function (visible) {
if (visible) {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]//select[#ng-change='listChange()']")).isDisplayed().then(function (visible) {
if (visible) {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[4]/div/span/span")).getText().then(function (monthText) {
varTwo = monthText;
console.log(varTwo);
});
if (varOne != "Revolving" || varTwo.length < 6) {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[6]/div/span/div/select")).element(by.cssContainingText('option', 'Exclude: Duplicate Account')).click();
}
else {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[6]/div/span/div/select")).element(by.cssContainingText('option', 'Include in Ratios')).click();
}
}
else {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[1]/div/span/span")).isDisplayed().then(function (visible) {
if (visible) {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[1]/div/span/span")).getText().then(function (currText) {
varOne = currText;
console.log(varOne);
});
}
});
}
});
}
});
}
});
Code like
if (element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]")).isDisplayed()) {
Won't work because that always evaluate to true since the promise Object is truthy per Javascript booleans.
You need to follow the promise:
var elm = element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]"));
elm.isDisplayed().then(function(visible) {
if (visible) {
// logic here
}
});
Assuming the element is Present, if not present then isDisplayed will fail at webdriver level, so you may test for isPresent instead of isDisplayed
here's what I used to finally get it to work. I put a call to a function inside of a for loop, and inside of the function is the code that does the heavy lifting.
it('should loop through table and select an option from each listbox available', function() {
var varOne = "";
var varTwo = "";
element.all(by.xpath("//table[#id='tableID']/tbody/tr")).then(function (rows) {
for (var i = 1; i < (rows.length); i++) {
console.log('count = ' + i);
selectWithinTable(i);
}
function selectWithinTable(i) {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]")).isDisplayed().then(function(visible) {
if (visible) {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]//select[#ng-change='listChange()']")).isDisplayed().then(function(visible) {
if (visible) {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[4]/div/span/span")).getText().then(function(someText) {
varTwo = someText;
console.log(varTwo);
console.log(varTwo.length);
});
if (varOne != "Revolving" || varTwo === "") {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[6]/div/span/div/select")).element(by.cssContainingText('option', 'This is option A')).click();
}
else {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[6]/div/span/div/select")).element(by.cssContainingText('option', 'This is option B')).click();
}
}
else {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[1]/div/span/span")).isDisplayed().then(function(visible) {
if (visible) {
element(by.xpath("//table[#id='tableID']/tbody/tr[" + i + "]/td[1]/div/span/span")).getText().then(function (moreText) {
varOne = moreText;
console.log(varOne);
});
}
});
}
});
}
});
}
});
element(by.id('buttonID')).isDisplayed().then(function(visible) {
if(visible) {
element(by.id('buttonID')).isEnabled().then(function(enabled) {
if (enabled) {
element(by.id('buttonID')).click();
}
});
}
});
});
//below code working for me to traverse to the particular rows and cells in the table
async colRowIterate() {
this.rowsTblValue.each(async (rowsValues: any) => {
let cells = rowsValues.$$('td');
cells.get(0).getText().then(async (cellvalues: any) => {
await browser.sleep(10000);
if (cellvalues == 'Harry') {
cells.get(4).$('button').click();
}
});
});
I have a problem that doesn't appear always, but it do it most of the times. In my huge java forecast class I have some ResultSets, and when I execute the routine I get:
com.microsoft.sqlserver.jdbc.SQLServerException: El nombre de columna DistanciaMision no es vßlido.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.findColumn(SQLServerResultSet.java:626)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getString(SQLServerResultSet.java:2301)
at es.csic.iiia.udt.itim.iInformation.WebData.Forecast.etaMSR(Forecast.java:1109)
at es.csic.iiia.udt.itim.iInformation.WebData.Forecast.phase2(Forecast.java:662)
at es.csic.iiia.udt.itim.iInformation.WebData.Forecast.setData(Forecast.java:166)
at es.csic.iiia.udt.itim.iInformation.WebData.Forecast.main(Forecast.java:81)
at es.csic.iiia.udt.itim.iInformation.WebData.Forecast.execute(Forecast.java:71)
at org.quartz.core.JobRunShell.run(JobRunShell.java:199)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:546)
The column exists, so I don't know what is the problem...
The code line is this one:
Float distancia_restante = (float) ( Integer.parseInt(rs.getString("DistanciaMision")) - (myodometer - initialodometer));
The same problem appears on other columns but it usually crash here.
Thank you!
Edit: ok, this is the whole method:
private static void etaMSR() throws Exception, SQLException {
/**
*
* Calculem ETAN MSR - Mision - Seguimiento - Restricciones conductor
*
*
**/
System.out
.print("Get data from iTIM forecast&forecastAUX DDBB ....... ");
myStatement = MSSQLServerAccess.connection();
// Distancia mision, ruta, hora mision anterior, hora
rs = getTable("SELECT dbo.WebForecast.IdConductor, dbo.WebForecast.IdMision, dbo.WebForecast.IdMisionAnterior, dbo.WebForecast.DistanciaMision, "
+ " WebForecast_1.HoraIniMis AS himanterior, dbo.WebForecast.HoraFiMis AS hfmactual, WebForecast_1.Ciudad AS CiudadOrigen,"
+ " dbo.WebForecast.Ciudad AS CiudadDestino, dbo.Distancias.Ruta, dbo.WebForecast.HoraDistancia AS HoraDistancia"
+ " FROM dbo.WebForecast AS WebForecast_1 INNER JOIN"
+ " dbo.Distancias ON WebForecast_1.Ciudad = dbo.Distancias.Origen RIGHT OUTER JOIN"
+ " dbo.WebForecast ON WebForecast_1.IdMision = dbo.WebForecast.IdMisionAnterior AND dbo.Distancias.Destino = dbo.WebForecast.Ciudad"
+ " WHERE (dbo.WebForecast.IdConductor <> '') AND (CONVERT(datetime, '"
+ df.format(fechaDia)
+ "') <= dbo.WebForecast.HoraFiMis) "
+ " AND WebForecast_1.HoraIniMis <= CONVERT(datetime, '"
+ df.format(fechaDia) + "') ");
System.out.println("[ok]");
while (rs.next() && (rs.getString("IdConductor") != "") && org.apache.commons.lang.StringUtils.isNumeric(rs.getString("IdConductor"))) {
int initialodometer = 0;
String start = null;
if (rs.getString("HoraDistancia") != null) {
start = rs.getString("HoraDistancia");
}
if (rs.getString("himanterior") != null) {
start = rs.getString("himanterior");
}
if (start != null) {
ResultSet myrs = null;
Timestamp tobjetivo = rs.getTimestamp("himanterior");
long boundtime = 7200000; // 3600000 = 60m = 1h
Timestamp tini = (Timestamp) rs.getTimestamp("himanterior")
.clone();
Timestamp tfin = (Timestamp) rs.getTimestamp("himanterior")
.clone();
tini.setTime(tini.getTime() - boundtime);
tfin.setTime(tfin.getTime() + boundtime);
int contador = 0;
long bestdiff = 0;
myStatement = MSSQLServerAccess.connection();
myrs = getTable("SELECT DISTINCT Odometer, DT "
+ "FROM DriverEvents "
+ "WHERE (DT BETWEEN CONVERT(datetime, '"
+ df.format(tini) + "') " + "AND CONVERT(datetime, '"
+ df.format(tfin) + "')) " + "AND (CardId = '"
+ Integer.parseInt(rs.getString("IdConductor")) + "')");
int j = 0;
while (!myrs.next() && (j < 20)) {
// En caso de no encontrar en las 2h antes y despues nada:
tini.setTime(tini.getTime() - boundtime);
tfin.setTime(tfin.getTime() + boundtime);
myrs.close();
myStatement = MSSQLServerAccess.connection();
myrs = getTable("SELECT DISTINCT Odometer, DT "
+ "FROM DriverEvents "
+ "WHERE (DT BETWEEN CONVERT(datetime, '"
+ df.format(tini) + "') "
+ "AND CONVERT(datetime, '" + df.format(tfin)
+ "')) " + "AND (CardId = '"
+ Integer.parseInt(rs.getString("IdConductor"))
+ "')");
j++;
}
if (myrs.next()) {
initialodometer = myrs.getInt("Odometer");
bestdiff = Math.abs(tobjetivo.getTime()
- myrs.getTimestamp("DT").getTime());
contador++;
while (myrs.next()) {
long pretendiente = Math.abs(tobjetivo.getTime()
- myrs.getTimestamp("DT").getTime());
if (pretendiente <= bestdiff) {
bestdiff = pretendiente;
initialodometer = myrs.getInt("Odometer");
}
contador++;
}
}
myrs.close();
}
// Get Odometer distance at the moment
if (!rs.getString("IdConductor").isEmpty() && !rs.getString("IdConductor").equals("") ) {
ResultSet myrs = null;
int myodometer = 0;
myStatement = MSSQLServerAccess.connection();
myrs = getTable("SELECT MAX(DT) AS DT, MAX(Odometer) AS Odometer"
+ " FROM dbo.DriverEvents"
+ " WHERE (CardId = '"
+ Integer.parseInt(rs.getString("IdConductor"))
+ "') AND (DT > CONVERT(datetime, '"
+ df.format(fechaDatos) + "')) ");
if (myrs.next()) {
myodometer = myrs.getInt("Odometer");
if (initialodometer == 0)
initialodometer = myodometer;
Float distancia_restante = (float) ( Integer.parseInt(rs.getString("DistanciaMision")) - (myodometer - initialodometer));
if (distancia_restante < 0)
distancia_restante = (float) 0;
Timestamp ETAN = null;
Calendar cal = Calendar.getInstance();
if (rs.getTimestamp("himanterior") != null && rs.getTimestamp("himanterior").toString() != "") {
cal.setTimeInMillis(rs.getTimestamp("himanterior")
.getTime());
if (cal.after(Calendar.getInstance())) {
cal.setTimeInMillis(rs.getTimestamp("himanterior")
.getTime());
}
if (cal.before(Calendar.getInstance())) {
cal = Calendar.getInstance();
}
} else {
if (rs.getTimestamp("HoraDistancia") != null)
cal.setTimeInMillis(rs
.getTimestamp("HoraDistancia").getTime());
}
myStatement = MSSQLServerAccess.connection();
rs2 = getTable("SELECT TOP (100) PERCENT CardId, DT"
+ " FROM dbo.DriverEvents"
+ " GROUP BY CardId, DT"
+ " HAVING (CardId = '"
+ Integer.parseInt(rs.getString("IdConductor"))
+ "') AND (DT > CONVERT(datetime, '"
+ df.format(fechaDatos) + "'))");
if (rs2.next()) {
ETAN = getETAN(rs, distancia_restante, cal);
} else {
ETAN = getETA(rs, distancia_restante, cal, 1);
Statement myStatement2 = MSSQLServerAccess.connection();
myStatement2.executeUpdate("UPDATE WebForecast "
+ "SET ETAmsr = '" + df.format(ETAN)
+ "', KmsDiff = '" + distancia_restante.intValue()
+ "' " + "WHERE IdMision = '"
+ rs.getString("IdMision") + "'");
} else {
}
}
}
rs.close();
}
And the statement, maybe i'm doing something wrong?:
private static Statement conStatement(Properties properties){
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // Load the JDBC driver
String dbURL = "jdbc:sqlserver://"
+ properties.getProperty("qualcomm.action.JDBC.MSSQLServerAccess.ddbbserverIP")
+ ";DatabaseName="
+ properties.getProperty("qualcomm.action.JDBC.MSSQLServerAccess.ddbbName")
+ ";SelectMethod=Cursor;"; // Connect to a server and database
String userName = properties.getProperty("qualcomm.action.JDBC.MSSQLServerAccess.userName");
String userPwd = properties.getProperty("qualcomm.action.JDBC.MSSQLServerAccess.userPwd");
Connection dbConn;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
//log.info("Connection Successful!");
Statement myst = dbConn.createStatement();
return myst;
} catch (Exception e) {
log.error(e);
System.out.println(e);
return null;
}
}
Thanks guys :) Could be something wrong with the statement?
remember that Java is case-sensitive and so can be your table on SQL depending on the way you created them, actually depending on the collation on your DB. If your database is created with a Case Sensitive collation then all object names will be Case Sensitive.
try to check the exact columns name of the column on SQL and access it using [] and the exact case