How to upload attachments in browser tests using Appium? - google-chrome

I am trying to automate a test case in Chrome where I would like to upload an attachment to an email. I use desiredCaps['browserName'] = 'Chrome'. While clicking attachments in email, it opens the Documents in the phone, but I am unable to detect the elements in the Documents screen.

Try this.If you are using ruby
This basically goes into the directory called screenshots and finds the second picture or the document that is visible inside the directory
find_element(id: "screenshots").find_element(class: "android.widget.ImageView[2]").click
end
This captures the first document/picture visible in the gallery
find_element(id: "").find_element(class: "android.widget.ImageView").click
You can modify it as per your requirement

You shoud change context to from Chromium to 'NATIVE_APP' appium doc about it (http://appium.io/docs/en/writing-running-appium/web/hybrid/) and use Touch Actions for choose you file

In Java, you can use the below code to switch context.
Set<String> contextNames = driver.getContextHandles();
for (final String contextName : contextNames) {
if (contextName.contains("NATIVE")) {
driver.context(contextName);
System.out.println("Switched to Native Context");
}
}
in Python you can try something like this
contextNames = driver.contexts
for aContext in contextNames
if "NATIVE" in aContext:
driver.switch_to.context(aContext)

Related

HTML Filepicker without sending file itself - only filepath [duplicate]

How can I create a directory chooser in html page.
If I use input file element I can select file only, but I need to select directory instead.
I need to do this beacause the user should select a right path inside his computer.
Any solutions ?
Try this, I think it will work for you:
<input type="file" webkitdirectory directory multiple/>
You can find the demo of this at https://plus.google.com/+AddyOsmani/posts/Dk5UhZ6zfF3 ,
and if you need further information you can find it
here.
Can't be done in pure HTML/JavaScript for security reasons.
Selecting a file for upload is the best you can do, and even then you won't get its full original path in modern browsers.
You may be able to put something together using Java or Flash (e.g. using SWFUpload as a basis), but it's a lot of work and brings additional compatibility issues.
Another thought would be opening an iframe showing the user's C: drive (or whatever) but even if that's possible nowadays (could be blocked for security reasons, haven't tried in a long time) it will be impossible for your web site to communicate with the iframe (again for security reasons).
What do you need this for?
As of 2022 there is now a directory picker API:
https://developer.mozilla.org/en-US/docs/Web/API/Window/showDirectoryPicker
async function getDir() {
const dirHandle = await window.showDirectoryPicker();
// run code for dirHandle
}
In case if you are the server and the user (e.g. you are creating an app which works via browser and you need to choose a folder) then try to call JFileChooser from the server when some button is clicked in the browser
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle("select folder");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
This code snipped is from here
This is my solution. It is the same as the above answers but you should notice that webkitdirectory = "true".
<input id="design" type="file" webkitdirectory = "true" directory/>
I did a work around. I had a hidden textbox to hold the value. Then, on form_onsubmit,
I copied the path value, less the file name to the hidden folder. Then, set the fileInput box to "". That way, no file is uploaded.
I don't recall the event of the fileUpload control. Maybe onchange. It's been a while. If there's a value, I parse off the file name and put the folder back to the box. Of, course you'd validate that the file as a valid file.
This would give you the clients workstation folder.
However, if you want to reflect server paths, that requires a whole different coding approach.
This isn't provided by HTML because of the security risk. <input type='file' /> is closest, but not what you are looking for.
If you're still using IE11 on Windows 10, you may try this example that uses an ActiveX control to achieve what you want.
Again if the OS is Windows, you can use VB scripts to access the core control files to browse for a folder.
If you do not have too many folders then I suggest you use if statements to choose an upload folder depending on the user input details.
E.g.
String user= request.getParameter("username");
if (user=="Alfred"){
//Path A;
}
if (user=="other"){
//Path B;
}

Display HTML page stored in SharePoint documents folder

I'm working on a SharePoint web part that displays a number of different reports in different divs on the page. In one of these divs, I need to display the HTML from a page we have stored in the 'Documents' container within SharePoint. The info in the HTML page is retrieved from several different parts of the application, and is displayed differently, so basically we're using it as the source data. I'm trying to figure out how to access the page from within the app and hopefully store the link to the file as a configurable setting so I can set it up for our dev/test/prod environments.
I've loaded the HTML file into the 'Documents' folder, and if I browse to it manually it displays fine but if I use the following:
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (System.Net.WebClient client = new System.Net.WebClient())
{
string htmlCode = client.DownloadString(url);
}
}
I get a 403 error and in the response header the message, "Before opening files from this location you must first browse to the website and select the option to login automatically".
I thought the RunWithElevatedPriveleges would pass the credentials through but I'm pretty new to SharePoint. Not sure if I'm using the right approach, any help is appreciated.
Put the pages into a standard document library, then use the page viewer web part. The site asset library is used for other customization purposes. You don't even need SharePoint Designer. Page viewer should be set as a "Web Page" because the web page viewer becomes essentially an IFRAME.
If still trouble... it may be a setting at the Web Application level thats causing issues with non-Microsoft files
Go to Central Admin > Manage Web Applications. I then chose my Web Application and clicked on the "General Settings" button. I then changed the Browser File Handling from "Strict" to "Permissive" and that fixed my issue. I've included an attachment of the setting so you can read the text associated with it.
Figured it out. There were a number of permissions problems but once those were sorted this code worked:
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb web = site.OpenWeb())
{
SPFolder folder = web.GetFolder("MainFolder/Lists/MainFolderDocs");
if (folder.Exists)
{
SPFile file = web.GetFile("/MainFolder/Lists/MainFolderDocs/Mainlist.html");
if (file.Exists)
{
using (System.IO.StreamReader reader = new System.IO.StreamReader(file.OpenBinaryStream()))
{
string htmlCode = reader.ReadToEnd();
lChecklist.Text = htmlCode;
}
}
}
}
}

Windows RT/ Universal app, Webview offline html file

( creating a universal app, currently working one windows phone 8.1) I am trying to get the webview to work with an offline html file but i cant really figure it out. I can get it to work with a weblink but not with an html file which is located on the shared folder.
I'm using switch statement to switch through different options. Here is a sample one with the code i use
case "Test":
ActualLoad = "Test.html";
break;
Here is the one that has a link:
case "OnlineTest":
ActualLoad = "https:www.google.com";
break;
The second one works but not the first one.
Check out the Remarks in this MSDN page.
Basically, you have to use something like this: <WebView Source="ms-appx-web:///Test.html"/>
This will work only if your Test.html file exists in your app package.

Excel file downloads instead of displaying in iframe

I have this in my controller class:
public ActionResult ExcelDoc()
{
var doc = Server.MapPath("~/Content/Sheet1.xlsx");
return File(doc, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
And in my view:
<iframe src="/Centres/ExcelDoc"></iframe>
It simply DOES NOT display the file in the iframe. Instead, it begins downloading sheet1.xlsx as ExcelDoc.xlsx. Very frustrating as previous questions have helped me to develop this solution to my previous problem of trying to display a dynamically generated excel file in an iframe. I am using Google Chrome, if that is relevant.
Returning a file makes your browser try to download it, that's expected behaviour. I think it's not possible to display an excel file as-is in your browser window, unless you use something like a plug-in.

Widget object is undefined in Dashcode

I'm using Dashcode for a mobile Safari web application and from the documentation (https://developer.apple.com/library/archive/documentation/AppleApplications/Conceptual/Dashcode_UserGuide/Contents/Resources/en.lproj/MakingaWidgetwithDashcode/MakingaWidgetwithDashcode.html), it appears that I should be able to access an object called "widget".
However, when I tried, I get the error message saying that widget is undefined. I've also tried "window.widget" and it gives me the same error.
What's going on?
I'd like to make a text in my application a clickable link to open a URL using openURL (like the example given at the URL above).
You use widget.xxx to access things inside and outside you widget.
So to access curl and the Mac and get some data from Yahoo you do as follows
var yahoorate = widget.system("/usr/bin/curl 'http://download.finance.yahoo.com/d/quotes.csv?s=EUR" + interim0 + "=X&f=l1'", null).outputString;
to get a preference key value, stored in the widgets plist when you install on a mac
globalPreferenceValue = widget.preferenceForKey(null, "your-key");
i think in the question ask (below) we are checking to see if we are in a widget and then preparing a transition to the back of the widget.
if (window.widget) {
widget.prepareForTransition("ToBack");
}
this is how i set a preference so it is stored between system reboots (you use a get preference to retrieve them)
widget.setPreferenceForKey(2,"ratePrecision");
and this is how you create a link to open in a browser not the widget
<a onclick=" + "widget.openURL('http://www.wf.com/private/?ID=636');" + "><span id=company-info>click here</span></a>
These are all rel working examples from widgets i have built. Hope it helps. I found it useful to download widgets that performed similar functions to ones i wanted and then as well as installing them opening them as projects, you can import, and then you can see all the code.
Ok, this worked...hope it will help someone else...
window.location = "http://www.apple.com";