We have a problem with my team for several weeks.
We currently have a test in MSTest v1 and Selenium 3.11 that is dedicated to upload a photo when filling out a profile.
In local works perfectly (hehehe), but in remote (RemoteWebdriver) the server of Build & Releases (VSTS) throws an error just in the step where I interact with this window, of the Access Denied type.
It is not really Selenium who acts there, but the System.Windows.Forms library and the SendWait method of the SendKeys class that gives the error when it is launched remotely.
Screenshot of the element in question >>> UploadFile
Example code:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Windows.Forms;
using OpenQA.Selenium;
using System.IO;
//...
public class EditarFotoUsuarioAdministrador
{
public static void Execute(IWebDriver driver, string foto)
{
driver.FindElement(By.XPath("//button[#id='upload']")).Click();
System.Threading.Thread.Sleep(2000);
SendKeys.SendWait(Directory.GetCurrentDirectory() + foto);
SendKeys.SendWait(#"{Enter}");
System.Threading.Thread.Sleep(2000);
driver.FindElement(By.XPath("//button[#id='save']")).Click();
System.Threading.Thread.Sleep(500);
}
}
As I said, this in local works perfectly, but when it runs on the remote server, the whole test goes well until it reaches the SendKeys line:
AccessIsDenied
Hopefully someone has an answer, thank you very much !!
The agent need to be running as interactive mode.
I've fixed it using AutoIT3.
Loading the nuget and using its methods to send the path of the file, you can perfectly interact with any pop-up browser window.
And best of all, the remote server does it too.
Thank you very much to all !
AutoIT3 or AutoItX.Dotnet ?
can you please send the code snippet. i used below code
` AutoItX.WinActivate("Open");
AutoItX.ControlGetFocus("Open");
AutoItX.Send(file);
System.Threading.Thread.Sleep(2000);
AutoItX.ControlClick("Open", " ", "Button1");`
It works fine in local but not in remote
Related
Currently, I'm trying to use a DLL in a Web Forms ASP.NET environment. This DLL is used to control a hardware using a UDP connection. My problem is: the first time I use the command, it seems work. If I click on the button again, it shows the error "Could not bind the socket. The address and port is already in use".
I already did some applications using Windows Forms and everything worked fine. I can use the command many times and not get this problem. Below, the code I'm using to do this:
using MyDLL;
string teste;
int result;
CommandClient UDPcmd = new CommandClient();
result = UDPcmd.PulseDoor("192.168.1.100", 2003, 0, out teste);
Resultado.Text = teste;
Any help? The problem only happens in web platform. Windows Forms work properly.
A friend help me and give me the command below. It worked properly.
System.Runtime.InteropServices.Marshal.ReleaseComObject(UDPcmd);
Thank you everybody for your help!!
Regards.
Need to download a zipball from given link in C#
YES! I searched the net and stackoverflow and been trying to accomplish this seemingly impossible task for hours...
Ironically, in Curl it's single line and works like charm..
curl -L https://api.github.com/repos/username/reponame/zipball > repo.zip
I want to do in C# same thing curl does above...
Tried WebClient.DownloadFile()
Gives
forbidden (403)
Tried async method too
Gives
0 bye file (no error/exception)
Tried HttpClient Datadownload and File stream writer, give same errors as above. Seams like streamwirter is not invoked at all so it's failing to access the server that's the main part of my problem
I have Octokit.NET installed but it lacks documentation so I'm not even sure where to start doing this (probably it's WebClient version but I did try that in .NET libs)
Found this answer but didn't really understand it (Cannot get repository contents as .zip file (zipball) in Octokit.net)
Even tried to run .sh script in C# but it gives me exception that it can't run this kind of shell on this OS
When I tried this with WebClient, I didn't get a 403, but an exception:
System.Net.WebException: The server committed a protocol violation. Section=ResponseStatusLine
Looking up other questions with the same error, I found that the GitHub API server requires a user agent to be set. After that, it was trivial:
using System;
using System.Net;
class Test
{
static void Main()
{
using (var client = new WebClient())
{
client.Headers.Add("user-agent", "Anything");
client.DownloadFile(
"https://api.github.com/repos/nodatime/nodatime/zipball",
"nodatime.zip");
}
}
}
... that worked fine. I've tried it for a user repo instead of an organization, and that was fine too.
You definitely wouldn't want to do anything with a StreamWriter, as that's for text data - and a zip file isn't text data.
You haven't shown what you did with the async version - my guess is that you started downloading but didn't wait until it had completed before disposing the client.
I have a WP8 Cordova app that has one page locally and then it redirects to a server for further functionality. Both pages have the cordova JS API's available and things work well.
Except that when I want to go to the local start page again. Any anchors to it (pointing to x-wmapp0:www/index.html) do not work on the HTML side.
In addition, any tricks with plugins and invocations of CordovaBrowser.Navigate() result in UnauthorizedAccessException errors.
The fallback has been for me to try to go back in browser history like this:
window.history.go(-window.history.length + 1);
But this doesn't do anything if I spend any time in the remote pages at all. So this isn't applicable either!
Is there a decent way to get to the starting page? With help from C# or otherwise?
So the UnauthorizedAccessException stuff came from thread issues. (The VS Express for WP can sometimes hide the details of an exception pretty well.)
This is a complete plugin that performs the redirection with neatest elegance available.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WPCordovaClassLib.Cordova;
using WPCordovaClassLib.Cordova.Commands;
namespace Cordova.Extension.Commands
{
public class Jumper : BaseCommand
{
/** Instruct the browser component to go to beginning. */
public void goHome(string unused)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
var webview = WebViewHandler.getInstance().webView;
webview.CordovaBrowser.Navigate(webview.StartPageUri);
});
}
}
}
The WebViewHandler is a singleton for sharing the Cordova WebView to plugins, described in another SO answer (thanks #MikeBryant!).
Trying to write a WMI class function to mount a network drive on any computer (remote or local) using the credentials of the logged in computer.
This is a class for a larger project that I wrote for help desk staff to do first line fixes on remote PC's. The tech types in the the machine name or ip address and the app connects to it and allows to tech to click a couple of buttons and fix some basic items without having to remote(VNC) into the PC.
I've read all over the internet that it is much easier ways than WMI, but due to the remote nature of the app I would rather not use local API calls, nor do I want to worry about uploading script and executing it though a process start. Also other functions are already in WMI so I'd like to keep the code base the same.
The basic idea is to mount H: to //fileserver.example.com/$username
NetFixer is already in production use so I'm trying to keep my code nice and neat
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
namespace WMIcontrols
{
public class Remote
{
public string target;
//Some code skipped here for simplicity sake...
public bool MountNetDrive(string DriveLetter, string MountLocation)
{
try
{
//Mount the network drive
return true;
}
catch
{
//Mount Failed
return false;
}
}
}
}
This is not using WMI but will accomplish what you want and is very simple
System.Diagnostics.Process.Start("cmd", "/c net use x: \\fileserver.example.com /user:Username Password");
I'm trying to create a simple application that does a HTTP
request/response on a button click. Here's the entire code which I got
from a reference book:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
namespace emulator2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
Uri l_Uri = new Uri("http://www.testing.com");
HttpWebRequest l_WebReq = (HttpWebRequest)WebRequest.Create(l_Uri);
HttpWebResponse l_WebResponse =
(HttpWebResponse)l_WebReq.GetResponse();
Stream l_responseStream = l_WebResponse.GetResponseStream();
StreamReader l_SReader = new StreamReader(l_responseStream);
string resultstring = l_SReader.ReadToEnd();
Console.WriteLine(resultstring);
}
}
}
The thing that puzzles me is that when I shift the entire chunk of code
to a Windows Application, it works fine. But when I use it on a Device
Application, it just throws me an error. Here are the details of the
error:
System.Net.WebException was unhandled Message="Could not establish
connection to network." StackTrace: at
System.Net.HttpWebRequest.finishGetResponse() at
System.Net.HttpWebRequest.GetResponse() at
emulator2.Form1.button1_Click() at
System.Windows.Forms.Control.OnClick() at
System.Windows.Forms.Button.OnClick() at
System.Windows.Forms.ButtonBase.WnProc() at
System.Windows.Forms.Control._InternalWnProc() at
Microsoft.AGL.Forms.EVL.EnterMainLoop() at
System.Windows.Forms.Application.Run() at emulator2.Program.Main()
The error points at this line:
HttpWebResponse l_WebResponse = (HttpWebResponse)l_WebReq.GetResponse();
Does anyone have any idea on how to solve this? I need to get this
solved real quick..so any help given is greatly appreciated! Thanks!
My guess is that the emulator doesn't have proper network connectivity. It can be a pain (and hit-and-miss in my experience) getting networking up and running on the old Windows Mobile emulators. (It's easy in Windows Phone 7.)
Load up Internet Explorer and see if that can make a connection to the same URL...
Additionally, you're not disposing of any of your resources (and if this code is really in a reference book exactly as you wrote it, that's a significant black mark against the book). For example, you should be disposing of the web response:
using (HttpWebResponse response = ...)
{
}
Likewise I would personally dispose of the response stream and the stream reader, just on general principle. I suspect that when the response is disposed, the stream will be too - but it makes sense to dispose of all streams etc unless you know you need to leave them undisposed.
If you're running in the emulator you'll ned to "cradle" the emulator and then create a partnership with ActiveSync (Win XP) or Windows Mobile Device Center (Vista or 7).
This will allow the emulator to share the network connection with the PC. You also need to do this even if you want to connect from the emulator to the PC.
As Jon mentions, in WP7 you don't need to make a connection in this way, the WP7 emulator automatically shares the network connection of the host PC.
Use IE Mobile (on the emulator) to check that the device can connect to the site.
Edit
To cradle the emulator, in VS2008 select "Device Emulator Manager" from the Tools menu. Select the emulator that's running, right click and select "Cradle".
Mobile Device Center should start automatically and ask if you want to create a partnership, just as if you'd connected a real device.