Cypress Uploading - testing

describe ('Upload Test' , function(){
it('Upload Test' , function(){
cy.visit('https://document.online-convert.com/convert/csv-to-excel')
cy.get('#fileUploadButton').click()
const catalogue ='../integration/Example.csv';
cy.get('#file').attachFile(catalogue);
cy.get('#multifile-submit-button-main').click()
})
})
i tried to upload the csv file and click on convert it, At cypress test result it shows that the file have been uploaded but actually its not.
enter image description here

I hope you're using cypress-file-upload. Your file seems to be in the integration folder. I would suggest putting all the files required for Cypress tests inside cypress/fixtures folder and calling them as fixtures.

I would also higly suggest to use cypress-file-upload.
With it you can do it like that:
First, you get your input field for the file. Then you can use .attachFile to declare the source and give it a name
cy.get('.FileInput input[type=file]')
.attachFile({filePath: 'Example.csv', fileName});

There are a couple of events attached to the input that need to be fired after you attach the file.
The user will click the "Choose file" and the OS opens a file selection dialog. Since Cypress can't control that dialog, you are effective replacing that step with .attachFile(...).
As soon as the file is attached, the upload begins automatically and when complete, the file name appears in the file list element.
The element we need to attach to is <input id="fileUploadInput" type="file">.
If you inspect this element, and look at it's event listeners there's a change event and a custom event fileuploadsubmit that look useful
This is the code that works for me
const catalogue = "../fixtures/example.csv";
cy.get('#fileUploadInput')
.attachFile(catalogue)
// this just confirms the internal file property of the element
// i.e confirm the attachFile worked
// You can leave it out, it does not affect the process
cy.get('#fileUploadInput')
.its('0.files')
.its('0')
.its('name')
.should('eq', 'example.csv')
// Now trigger the change event
cy.get('#fileUploadInput')
.trigger('change', {force:true}) // force because the input is hidden
// And the fileuploadsubmit event
// Note that after change event, the input is detached from DOM
// so we need to re-query for the id
cy.get('#fileUploadInput')
.trigger('fileuploadsubmit', {force:true})
// Confirm the file is in the file list
// if it's a large file, allow enough time with a timeout option
cy.contains('span', 'example.csv', {timeout: 10000})
// Now start the conversion
cy.get('#multifile-submit-button-main').click()

Related

Change text by Command with VS-Code-Extension

I want to implement a second code formatting. This formatting should be executable by an additional command.
I have already registered a DocumentFormattingEditProvider and that is fine.
vscode.languages.registerDocumentFormattingEditProvider({ language: 'sosse' }, {
provideDocumentFormattingEdits(document: vscode.TextDocument) {
return formattingAction(document);
},
});
But in my case I need a second formatting action for one-liners, which is executed by an command.
I thought about using:
vscode.commands.registerCommand(command, callback)
But I don't know how to access and change the document.
But I don't know how to access and change the document.
There's a special variant of registerCommand() that I think is exactly what you're looking for: registerTextEditorCommand(). From the API docs:
Text editor commands are different from ordinary commands as they only execute when there is an active editor when the command is called. Also, the command handler of an editor command has access to the active editor and to an edit-builder.
That means the callback gets passed an instance of a TextEditor as well as a TextEditorEdit.

The selenium got the different html source from my local pc

I fetched http://book.flypeach.com/default.aspx?ao=B2CZHTW&ori=TPE&des=KIX&dep=2015-06-12-undefined-undefined&adt=1&chd=0&inf=0&langculture=zh-TW&bLFF=false by driver.current_url
However I got timeout error by this code
wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
wait.until { #driver.find_element(:css => "div.WrapperFlightDate") }
But I can see the css attributes div.WrapperFlightDate was truly exsiting in the page_source,
How could it happen ?
When I opened given link and trying to see given class in source code(ctrl + u),I didn't find given class.May be page was not loaded properly.
I refreshed page and right click on page -> View Page Source option then got this class in source code.Even I also ran this successfully in FF.
I also surprised why I didn't see correct source code first time.
You also try same,hope so you also get correct code now :).

File download control - delete file without validation?

Hello XPages programmers.
I work on a simple XPages File Library.
To achieve that i use FileUpload control with FileDownload control.
When i create a new file, i enter its name, and select a file.
I set that uploading a file won't activate a validation, so i can attach a file without a specified name. Additionally i set it to do fullrefresh, so uploading a file takes place in an instant and a file is visible in FileDownload control.
Problem occurs, when i want to delete that attachment using garbage icon of FileDownload - i can't set it to run without walidation.
Is there any workaround avaiable?
Any help will be appreciated.
I used the workaround Mark Leusink suggested - created a simmilar button (used image from filedownload control) and then set it for full refresh with process data without validation property.
Code in JSSS
function deleteAttachments()
{
var attList = dDocument.getAttachmentList("Document_Attachment");
for(var i=0; i<attList.size(); i++)
{
var att:String = attList[i];
dDocument.removeAttachment("Document_Attachment", att.getName() );
}
}
Surely it can be used for delete a specific attachment by getting attachment name from rowdata in a repeater and use DATASOURCE.removeAttachment method.
Thanks for your support!

Override the upload function of a file upload control

I want to override the upload function of a file upload control in order to add the functionality that I need. I am trying to adapt the code from the following link to my case
Auto-save doc after delete of attachment in File Download control?
by changing the type of the second parameter to com.ibm.xsp.component.xp.XSPFileUpload, i.e.:
function rekOverrideFileDownloadAction( component:javax.faces.component.UIOutput, fDownload:com.ibm.xsp.component.xp.XSPFileUpload ){
and the code in the MethodBinding mBinding and by using the name of my file upload control, i.e.:
var mBinding = facesContext.getApplication().createMethodBinding("#{javascript:print('Uploaded');}", null );
overrideFileDownloadAction( getComponent( 'fileUpload1' ) );
Unfortunately, a javax.faces.FacesException occurs.
Can anyone help me to modify this code in order to just print this message when the user uploads a file?
Stack Trace:
javax.faces.FacesException
javax.faces.FacesException.<init>(FacesException.java:97)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:86)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:96)
com.ibm.xsp.controller.FacesControllerImpl.execute(FacesControllerImpl.java:250)
com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:209)
com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:204)
com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)
com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)
com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1281)
com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:847)
com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796)
com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)
com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1265)
com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:653)
com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:476)
com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:341)
com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:297)
com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)
java.lang.NullPointerException
com.ibm.xsp.actions.ActionGroup.invoke(ActionGroup.java:135)
com.ibm.xsp.actions.ActionGroup.invoke(ActionGroup.java:135)
com.ibm.xsp.application.ActionListenerImpl.processAction(ActionListenerImpl.java:60)
javax.faces.component.UICommand.broadcast(UICommand.java:324)
com.ibm.xsp.component.UIEventHandler.broadcast(UIEventHandler.java:366)
com.ibm.xsp.component.UIViewRootEx.broadcast(UIViewRootEx.java:1535)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:307)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:428)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:94)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:96)
com.ibm.xsp.controller.FacesControllerImpl.execute(FacesControllerImpl.java:250)
com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:209)
com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:204)
com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)
com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)
com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1281)
com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:847)
com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796)
com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)
com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1265)
com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:653)
com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:476)
com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:341)
com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:297)
com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)
I also noticed that if I add a script to an event, e.g. onChange, so that an event handler is created no exception occurs. So I think the exception is thrown because there is no event handler and that leads to a null pointer. For now I have added the functionality I need to the onChange event and it is ok, but it would be nice if someone could tell me if there is a way to override it.
Thank you in advance!
What are you trying to do? I think that it is not possibile with the snippet (it overwrites an event handler of the download link which is available for an Upload Control only).
Maybe this snippet can help you: http://openntf.org/XSnippets.nsf/snippet.xsp?id=replace-attachment-when-uploading-a-new-attachment

Change ItemFileWriteStore URL, get data and refresh Grid

I have an EnhancedGrid with ItemFileWriteStore. After calling startup() on the grid, I hide the same by using following code:
dojo.style(grid.domNode, 'display', 'none');
And then on the click of a button, I change the URL of store for this grid and try to refresh the store and show the grid by using following code:
store.save();
store.close();
store.url='AjaxPopulate.json?os_type='+dijit.byId('osType').get('value');
store.save();
store.fetch({query:{id: '*'}});
dojo.style(grid.domNode, 'display', '');
grid.store.close();
grid.setStore(store);
The above code works fine with Firefox and Chrome but not on IE8 and IE9. I simply get "Object Error" message in IE Developer tools console.
Pls. help me identify any issues with the above code.
Howto reload store
If using the 'data' property to populate store initially (via constructor), you should set clearOnClose: true as well.
Use of .save() is only for a ItemFileWriteStore that has some settings changed (isDirty) and needs to propagate these to server. That said, you dont need .save on a closed store (allthough url has changed, no fetch has been run and definately no items has changed).
Try the following code, you'd only need the grid component to do it as calling .render() on the grid will get it to reload it's data.
// save if dirty, otherwise we cannot close a store unless its reset
grid.store.save();
// close store, this should clear data
grid.store.close();
// set new URL
grid.store.url = '??';
// rerun fetch XHR
// reload grid data with new items (no need to setStore as its same object reused)
grid.store.fetch({query:{id: '*'}, onComplete: function() {grid.render}});
Problem was that I had invalid JSON coming from server with one extra comma.
IE is very specific on these things.
Thanks everyone who viewed and tried to reply.