Upload file in new window cypress - file-upload

Try to automate upload file in new window. Use the script below. After uploading file I need to click Close button, then the file appear in my field. Close button unclickable after uploading file. Window like froze Use Firefox
enter image description here
enter image description here
`cy.get('#cgcontent').within(()=>{
cy.get('[name="x_gs_org_link_id"]').invoke('attr','value').then((key)=>{
cy.window().then((win) =>{
cy.stub(win, 'open', url => {
win.location.href = `${Cypress.env('api_root')}/lot/fam/${key}`
}).as('newWindow')
})
})
cy.get('.formRowCG1212453 > .large-8 > .formButton').click( {force:true} )
cy.get('#newWindow').should("be.called")
})
cy.get('#xfileupload').attachFile('sample.pdf' , {subjectType:'drag-n-drop'}) // upload
cy.get('#primaryAction').click( {force:true} ) // upload file button
cy.wait(2000)
cy.get('.stack-for-small > :nth-child(2) > .formButton').click() // close button`

Related

How to close the specfic editor in the vscode programmatically?

I'm the developer for the vscode extension.
When the debugger activated, I opened a specific file in the right column editor to show the other related file for the current debug file using the below command.
vscode.commands.executeCommand('vscode.open', vscode.Uri.file('/main.c.dbgasm'), 2);
Now I want to close it. But I have no idea to close the right column editor. There are some close editor commands but they do not fit my needs which shown below.
workbench.action.closeActiveEditor
workbench.action.closeAllEditors
workbench.action.closeAllGroups
workbench.action.closeEditorsInGroup
workbench.action.closeOtherEditors
workbench.action.closeUnmodifiedEditors
Can anyone have idea about it?
You can use the window.tabGroups.close() method.
// the 'all' array is 0-based, so this is the second editor group
const sourceGroup = vscode.window.tabGroups.all[1];
// this would get the first tab in the second editor group
// if you don't know where in the editor group the file you want to close is
// you can filter the tabs by label,url or path, see below
const myTab = sourceGroup.tabs[0];
await vscode.window.tabGroups.close(myTab, false);
To filter the tabs in an editor group by their path, try this:
const sourceGroup = vscode.window.tabGroups.all[0]; // 'all' array is 0-based
// note small "c" to match how Uri.fsPath looks
const myPath = "c:\\Users\\Mark\\OneDrive\\Test Bed\\howdy.js";
const foundTab = sourceGroup.tabs.filter(tab =>
(tab.input instanceof vscode.TabInputText) && (tab.input.uri.fsPath === myPath)
);
// close() takes an array or a single tab
if (foundTab?.length === 1) await vscode.window.tabGroups.close(foundTab, false);

Allow file explorer in Microsoft.Web.WebView2.WinForms.WebView2

I have a Winforms app with a webview but the file explorer do not open when fired inside the webview (works fine on browser) i alredy tried the following :
Dim oEnvironment As Microsoft.Web.WebView2.Core.CoreWebView2Environment
Dim opts As CoreWebView2EnvironmentOptions = New CoreWebView2EnvironmentOptions()
'opts.AdditionalBrowserArguments = "--allow-file-access-from-files"
opts.AdditionalBrowserArguments = "--disable-web-security"
oEnvironment = Await Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateAsync(String.Empty, System.IO.Path.GetTempPath(), opts)
Await browser.EnsureCoreWebView2Async(environment:=oEnvironment)
The page do nor return any error.
How can i give permissions to open that?
Update:
I have a file picker like this below, if i drag and drop the files it works, if i click "Browse" nothing appen in the webview (on browser all woks fine)

Selenide can't download PDF

I had some trouble using Selenide's download function. This is my flow:
click on button
button opens new tab which shows pdf file and url is:
blob:https://hostname.apps.something.else/9365b3ab-f0ad-45e9-85d2-db7e2fb5fd2e
So basically the new tab is opened in Chrome PDF Viewer.
I tried to click on the hidden download button in the new tab but no luck.
My thinking got me to the idea of when I click that button, this new tab shouldn't open, the download should start. That would mean settings some Configuration preferences like I did below:
Configuration.browserCapabilities = new DesiredCapabilities();
Configuration.browserSize = "1920x1080";
Configuration.fileDownload = FileDownloadMode.FOLDER;
Configuration.downloadsFolder = "./src/pdfs";
Configuration.proxyHost = "30.40.34.82";
Configuration.proxyPort = 8080;
Configuration.proxyEnabled = true;
Configuration.fileDownload = FileDownloadMode.PROXY;
Configuration.browserCapabilities.setCapability("plugins.always_open_pdf_externally", true);
Configuration.browserCapabilities.setCapability("download.prompt_for_download", false);
Configuration.browserCapabilities.setCapability("pdfjs.disabled", true);
The problem is that, this still opens new tab, and I get no such element found
File file = applicationList.printButton.download(30000);
Why do you first set Configuration.fileDownload to FOLDER and then to PROXY? No need to set it twice.
I think you cannot download the file via PROXY because links of type blob: don't fetch file content from the server.
I think you can just remove all these lines:
Configuration.proxyHost = "30.40.34.82";
Configuration.proxyPort = 8080;
Configuration.proxyEnabled = true;
Configuration.fileDownload = FileDownloadMode.PROXY;
Configuration.browserCapabilities.setCapability("plugins.always_open_pdf_externally", true);
Configuration.browserCapabilities.setCapability("download.prompt_for_download", false);
Configuration.browserCapabilities.setCapability("pdfjs.disabled", true);
Selenide method FOLDER should download the file without all these tricky settings.
Try it
System.setProperty("chromeoptions.prefs", "plugins.always_open_pdf_externally=true")

How to handle a file upload button using selenium?

I am trying to access the file upload element from a webpage and handle it to upload a file and click on submit for processing. Please tell me how to handle the file upload dialog boxes? Also when using the code, it got struck-ed in the find element module itself. What can i do for that?
driver.findElement(By.id("SWFUpload_0")).click();
Robot r = new Robot();
r.keyPress(KeyEvent.VK_C); // C
r.keyRelease(KeyEvent.VK_C);
r.keyPress(KeyEvent.VK_COLON); // : (colon)
r.keyRelease(KeyEvent.VK_COLON);
r.keyPress(KeyEvent.VK_SLASH); // / (slash)
r.keyRelease(KeyEvent.VK_SLASH);
// etc. for the whole file path
r.keyPress(KeyEvent.VK_ENTER); // confirm by pressing Enter in the end
r.keyRelease(KeyEvent.VK_ENTER);

Handle download dialog box in SlimerJS

I have written a script that clicks on a link which can download a mp3 file. The problem I am facing is when the script simulates the click on that link, a download dialog box pops up like this:
Download Dialog Box
Now, I want to save this file to some path of my choice and automate this whole process. I am clueless on how to handle this dialog box.
Here's a script adapted from this blog post to download a file.
In SlimerJS it is possible to use response.body inside the onResourceReceived handler. However to prevent using too much memory it does not get anything by default. You have to first set page.captureContent to say what you want. You assign an array of regexes to page.captureContent to say which files to receive. The regex is applied to the mime-type. In the example code below I use /.*/ to mean "get everything". Using [/^image/.+$/] should just get images, etc.
var fs=require('fs');
var page = require('webpage').create();
fs.makeTree('contents');
page.captureContent = [ /.*/ ];
page.onResourceReceived = function(response) {
if(response.stage!="end" || !response.bodySize)
{
return;
}
var matches = response.url.match(/[/]([^/]+)$/);
var fname = "contents/"+matches[1];
console.log("Saving "+response.bodySize+" bytes to "+fname);
fs.write(fname,response.body);
phantom.exit();
};
page.onResourceRequested = function(requestData, networkRequest) {
//console.log('Request (#' + requestData.id + '): ' + JSON.stringify(requestData));
};
page.open("http://....mp3", function(){
});
You can't control a dialog box. SlimerJS doesn't have API for this action.
Firefox generates a temp "downloadfile.extension.part" file which contains the content. Just simply rename the file ex. myfile.csv.part > myfile.csv
locally if working on a mac you should find the .part file in the downloads directory, on linux /temp/ folder
Not the most elegant solution but should do the trick