how to write data for excel file in cypress? - automated-tests

I'm new to Cypress, I want to know how to write data to xlsx file, I tried writing this way but it can't open xlsx file.
cy.writeFile('cypress/fixtures/DataTest/login_result.xlsx', '\nUsername : ' + Username + '\n' + '\nPassword : ' + Password + '\n' + '\nExpectedResult : ' + ExpectedResult + '\n' + '\nActualResult : ' + Asresult + '\n' + '\nResult :' + result + '\n').as('writeXlsxFile')

Consider the extension of the Excel file as xls. For example, in the code below, the word Hello is written in the Excel file
cy.writeFile('cypress/fixtures/Test.xls', 'Hello','UTF-8')

Related

Trying to Run Grunt But Getting Errors and not sure how to fix them

I'm currently reading a book on Learning to Program by Steven Foote. The book is currently talking about automation and is detailing how to use grunt.
I just installed grunt using npm install -g grunt-cli succesfully, however I am now running into a error that I'm not familiar with.
When I run grunt I get the following errors:
users-mbp:kittenbook user$ grunt
Running "jshint:files" (jshint) task
Linting js/prompt.js ...ERROR
[L3:C21] E031: Bad assignment.
'<p>' + projectName = ' ' _ versionNumber +
Linting js/prompt.js ...ERROR
[L3:C22] W033: Missing semicolon.
'<p>' + projectName = ' ' _ versionNumber +
Linting js/prompt.js ...ERROR
[L3:C23] W030: Expected an assignment or function call and instead saw an expression.
'<p>' + projectName = ' ' _ versionNumber +
Linting js/prompt.js ...ERROR
[L3:C26] W033: Missing semicolon.
'<p>' + projectName = ' ' _ versionNumber +
Linting js/prompt.js ...ERROR
[L3:C27] W030: Expected an assignment or function call and instead saw an expression.
'<p>' + projectName = ' ' _ versionNumber +
Linting js/prompt.js ...ERROR
[L3:C28] W033: Missing semicolon.
'<p>' + projectName = ' ' _ versionNumber +
Linting js/prompt.js ...ERROR
[L4:C31] E031: Bad assignment.
'accessed on: ' + currentTime = '</p>';
Linting js/prompt.js ...ERROR
[L4:C31] W030: Expected an assignment or function call and instead saw an expression.
'accessed on: ' + currentTime = '</p>';
Linting js/prompt.js ...ERROR
[L4:C32] W033: Missing semicolon.
'accessed on: ' + currentTime = '</p>';
Linting js/prompt.js ...ERROR
[L4:C33] W030: Expected an assignment or function call and instead saw an expression.
'accessed on: ' + currentTime = '</p>';
Warning: Task "jshint:files" failed. Use --force to continue.
prompt.js contains:
var userName = prompt('Hello what\'s your name?');
document.body.innerHTML = '<h1>Hello, ' + userName + '!</h1>' +
'<p>' + projectName = ' ' _ versionNumber +
'accessed on: ' + currentTime = '</p>';
I'm fairly new to grunt so I'm not sure what to do to fix the errors. Any help would be appreciated.
You just have a few wrong assignations in prompt.js. In a few places you used = instead of + to concatenate the string.
Replace with the following:
var userName = prompt('Hello what\'s your name?');
document.body.innerHTML = '<h1>Hello, ' + userName + '!</h1>' +
'<p>' + projectName + ' ' + versionNumber +
'accessed on: ' + currentTime + '</p>';

Opening Excel file Using ClosedXML Error

I am trying to open a 6MB Excel file in ASP.NET using ClosedXML but I am getting an error saying "Error in implicit conversion. Cannot convert null object."
Here's my code:
Dim temppath = Path.GetTempPath()
Dim filenamestr As String = Path.GetFileNameWithoutExtension(Path.GetRandomFileName())
Dim tempfilename As String = Path.Combine(temppath, filenamestr + ".xlsx")
Using fs = New FileStream(tempfilename, FileMode.Create, FileAccess.Write)
xlStream.WriteTo(fs)
End Using
Dim xlwb = New XLWorkbook(tempfilename) 'The part having the error
Source: "DocumentFormat.OpenXml"
I also tried opening an existing Excel file, it still results to this error. Also tried putting the file in different directories thinking it's just because of the permission of my drives, no luck at all. Thanks in advance.
Below is the real time working code used to get excel file in closed xml
private void workbookProcessing(string workbookname)
{
SqlDatabase objdb = new SqlDatabase ( OSMC.constring_Property );
//Below the boqserverfilepath refers the folder where excel files stored EX: "~/Uploaded_Boq/";
string fullfilename = System.Web.HttpContext.Current.Server.MapPath ( OneStopMethods_Common.boqserverfilepath + workbookname );
XLWorkbook theWorkBook = new XLWorkbook ( fullfilename );
int worksheetcount = theWorkBook.Worksheets.Count;
foreach(IXLWorksheet theWorkSheet in theWorkBook.Worksheets)
{
foreach(IXLRow therow in theWorkSheet.Rows())
{
foreach(IXLCell thecell in therow.Cells())
{
int tenderid = 1001;
int Activity_Section_objseq = tenderosm.generateNextTenderObjSequenceNo ( tenderid, "tender_boq_activity_section" );
string boqactivitysectionInsquery = " insert into tender_boq_activity_section(fk_tender_id,obj_seq_no,parent_obj_seq_no,activity_section_no,workbook_name,worksheet_name,row_index,cell_reference,element_type,element_description) values(" + tenderid + "," + Activity_Section_objseq + ",' 10 ','20','" + workbookname + "','" + theWorkSheet.Name + "'," + therow.RowNumber ( ) + ",'"+thecell.Address+"','activity','" + thecell.Value + "');";
objdb.ExecuteNonQuery ( CommandType.Text, boqactivitysectionInsquery );
}
}
}
}
You take the values as per your requirement and insert the values in the database.
Hope the above information will be useful. Kindly let me know your thoughts.
thanks
karthik

')' or operator expected on LinqDataSource where clause

Where="((ProgModelID == #ProgModelID) || (#ProgModelID == #ShowAll)) && (((FirstName + ' ' + MiddleName + ' ' + LastName) LIKE '%' + #Name + '%') || ((FirstName + ' ' + LastName) LIKE '%' + #Name + '%'))"
I need to concatenate the full name together when comparing against a TextBox in order to filter a GridView, but this error comes up when I try to run it. The error changes to Expression expected when I place [] around each FirstName, MiddleName and LastName.
Update
I have a textbox which a user can type a name into to filter a GridView's results. the GridView has a LinqDataSource. The problem is the name is divided in the database into 3 parts: first, middle, last. I want to be able to filter by first+last name, as well as first+middle+last name. The areas related to ProgModel are for a DropDownList and already function if the sections related to #Name are removed.
I figured out how to avoid this error, and a probable cause for it. I added computed columns to the view the LinqDataSource was pulling rows from for FullName (first, middle, last) and Name (first, last).
I then changed LIKE to .Contains() and received a no applicable method 'contains' exists in type 'string' error. What happened was I forgot to add ConvertEmptyStringToNull="false" to the ControlParameter for the TextBox (I found out this solution from the link here). That managed to fix everything.
You need just one more ) at the end is all..This will complete the wrap after your &&
Try this:
Where="((ProgModelID == #ProgModelID) || (#ProgModelID == #ShowAll)) &&
(((FirstName + ' ' + MiddleName + ' ' + LastName) LIKE '%' + #Name + '%')
|| ((FirstName + ' ' + LastName) LIKE '%' + #Name + '%')))"
Or - to make it a little easier to read and still get the same result, remove one of the ( before FirstName + ' ' - like:
Where="((ProgModelID == #ProgModelID) || (#ProgModelID == #ShowAll)) &&
((FirstName + ' ' + MiddleName + ' ' + LastName) LIKE '%' + #Name + '%')
|| ((FirstName + ' ' + LastName) LIKE '%' + #Name + '%'))"
Ultimately the error message says it all :)

embed image to body in html email in asp.net

How shall i write the code to embed image to email body? whats wrong?
mMailMessage.Body += Server.MapPath(#"<img src=""/Styles/Images/logo.png""");
.
You are mapping a path to a file called "<img src=""/Styles/Images/logo.png"""!
What you want to do is something like this:
mMailMessage.Body += "<img src=\"" + Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port + #"/Styles/Images/logo.png" + "\"/>";

ASP.NET - Download File When File Name Contain Spaces

I want to download the files from server. When downloading i want to change the file name.
But I can't change the file name totally when the filename contains spaces.
My Code is as Below
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
This lets the user save the file to their computer.
But when i save the file, only the first word of the filename is saved.
eg. I want to give the file name as ("CCNA Q&A.pdf") but the file save as ("CCNA")
I want to know how to save the filename with spaces.
in firefox: Server.UrlEncode() will replace space with %20
just put the filename between double quotes filename = "\"" + filename + "\"";
Have you tried Server.UrlEncode()?
Or you can omit all non alphabetic characters (' ', -, etc) whith _-s (regular expression replace).
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
I was having the same problem as I was trying to download a text file having spaces in its name. I have solved this using UrlDecode function. As browser converts spaces to '+' symbol, using decode function one need to convert these '+' to spaces.
fileName = Server.UrlDecode(fileName);
Response.AddHeader("content-disposition", "attachment; filename=\"" + fileName + "\"");
You'll have to wrap it in additional quotes:
Response.AddHeader("content-disposition", "attachment; filename=\"" + fileName + "\"");

Resources