I am having an issue with Chromedriver failing to send simulated inputs (Control + P ) on a server. The inputs that I am sending with InputSimulator (http://inputsimulator.codeplex.com/). Using Selenium and Firefox, the tests execute perfectly; however when I change over to use Chromedriver, I am encountering failures from my input simulator not properly firing on the page. That is the only difference taking place.
If I perform the test on my local machine instead of on the server, it executes flawlessly. Since InputSimulator just simulates they keys being pressed, it never reports a failure.
The servers that I am running on Windows Server 2008 R2 64 Bit.
Why would Selenium(Firefox) not have any issue and changing to Chromedriver now causes them to never send only one the servers? The only section of code changing is the driver settings.
Selenium (firefox)
FirefoxProfile profile = new FirefoxProfile(#"path/to/profile");
using (IWebDriver driver= new FirefoxDriver(profile))
{
//Navigate to URL
driver.Navigate().GoToURL(#"http://google.com");
//Wait for the page to load
Thread.Sleep(2000);
InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_P);
Thread.Sleep(2000);
InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
//Now I have the dialog to send my save path.
}
Chromedriver
var options = new ChromeOptionsWithPrefs();
options.prefs = new Dictionary<string, object>
{
{ "printing.print_preview_sticky_settings.appState","{\"version\":2,\"isGcpPromoDismissed\":false,\"selectedDestinationId\":\"Save as PDF\",\"selectedDestinationOrigin\":\"local\",\"customMargins\":null}" }};
options.AddArgument("--disable-extensions");
options.AddArgument("-incognito");
options.AddArgument("-start-maximized");
options.AddArgument("--renderer-print-preview");
using (IWebDriver driver= new ChromeDriver(#"C:/Chromedriver/path", options))
{
//Navigate to URL
driver.Navigate().GoToURL(#"http://google.com");
//Wait for the page to load
Thread.Sleep(2000);
InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_P);
//Code never fires on the servers; does fire on my local machine.
Thread.Sleep(2000);
}
InputSimulator does not work in Windows Server 2008 R2 and Windows 7 if Aero is off (I have not tested with other versions, yet).
For Windows 7, switch to an Aero theme and it will start working again.
For Windows Server 2008 R2, you will need to install Workstation Theme for Aero:
Run this command in command prompt:
ServerManagerCmd -i Desktop-Experience
Restart the server.
Go to services.msc and start the Themes service.
Go to Windows Display settings, select Personalize, Pick an Aero Theme.
Related
im creating a console application in C# to open and connect with my Windows Desktop Application, in my computer its working but when i installed it in the cliente idk why doesnt open the application, in some post i saw that if the console application its running in other monitor (what is the client case) gets error but we noticed that if the app iVMS-4200 (its a security camera software) is open the winAppDriver does not work.
//Appium Driver URL it works like a windows Service on your PC
string appiumDriverURI = "http://127.0.0.1:4723";
//Application Key of your UWA
//U can use any .Exe file as well for open a windows Application
string calApp = #"C:\Safesmart Plus\SmartCard.exe";
AppiumOptions opt = new AppiumOptions();
opt.AddAdditionalCapability("app", calApp);
opt.AddAdditionalCapability("deviceName", "SmartCard");
WindowsDriver<WindowsElement> calSession = new WindowsDriver<WindowsElement>(new Uri(appiumDriverURI), opt);
we are trying to use Selenium for testing our MVC application. On localhost in VS2017 , it´s running correct, the tests open IE, run the test and then close the IE.
On TFS build server, the tests start IE somehow on background (in Task manager I see two iexplorer.exe processes), but the window of IE is not visible. The tests find elements, but they are not able to write text in textbox, always get error like "Element cannot be interacted with via the keyboard because it is not focusable"
Localy I run Win10 and IE11, TFS build server run Windows Server 2012 R2 and IE11 .
//initialize driver in test constructor
InternetExplorerOptions options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
options.RequireWindowFocus = true;
driver = new InternetExplorerDriver(options);
driver.Manage().Window.Maximize();
//test itself
driver.Navigate().GoToUrl(appURL);
var x = driver.FindElement(By.Id("FiltrADuvodDotazu_DuvodDotazu"));
x.SendKeys("Automatizovaný test"); //here I get error
Is there way to run IE visibly, so the tests can interact with it?
I guess your agent run as a service and this is the reason the tests run on "headless mode" (and IE not supports it, like mentioned in the comments).
To solve it you need to configure the agent as an interactive process with auto-logon enabled.
When configuring the agent, select 'No' when prompted to run as a service. subsequent steps then allow you to configure the agent with auto-logon.
More info you can find here.
Meta -
OS: Windows 10, Server 2012
Browser: Chrome
Version: 65.0.3325.181 (Official Build) (64-bit)
Web driver: 2.36
Dotnet Framework: 4.6
Expected Behavior -
In my application I'm using window AD for authentication. Whenever I open application in chrome browser it ask for authentication and a login pop-up window(attached screenshot) gets open. In the pop-up window, I enter my credential and click on login button. Once successfully logged-in I'm able access my application. Expecting same behavior in automation.
Actual Behavior -
Same thing i have automated with the help of selenium driver. I had used selenium web driver 2.34 for Chrome and Chrome version was 64, with this combination login functionality was working fine. Now recently I have upgraded web driver to 2.36 and Chrome to 65, post this upgrade login functionality is not working. Now in application when login pop-up window opens and application wait for user inputs
i'm using auto hot key "WindowsAuthenticationChrome" to enter the credentials, now application gets hang at driver.url="some url" thread gets blocked and unable to launch auto hotkey and after some time it throw command timeout exception. and when i manually enter credentials or close the popup thread get released and execute next line of code.
This issue is coming after version upgrade.
Steps to reproduce -
Created sample console application
class Program
{
static void Main(string[] args)
{
string[] arguments = new string[] { "no-sandbox", "test-type", "ignore-certificate-errors", "disable-popup-blocking" } ;
var chromeOptions = new ChromeOptions() { BinaryLocation = #"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" };
chromeOptions.AddArguments(arguments);
var chromedriver = new ChromeDriver(#"C:\TestCases\Drivers", chromeOptions, new System.TimeSpan(0, 10, 0));
//chromedriver.Url = "actual url" login pop-up window come;
chromedriver.Url = "https://www.google.co.in/";
}
}
In sample code i'm creating object of web driver with some capabilities, when i'm trying to open my application url where login pop-up window come code gets hang after some time it throw command timeout exception however when i'm trying to open simple page ("https://www.google.co.in") where popup window is not coming code is working fine.
Any help would be grateful!
Currently, I'm trying to run my Selenium tests on Safari using Selenium Grid and RemoteWebDriver. This is my setup:
Mac OS Sierra 10.12.6 as a machine for running tests.
Selenium server 3.5.3.
Safari 11.
C# Selenium WebDriver and Selenium Support (latest version).
I'm using port forwarding on my host OS (Windows 10) to forward requests to Mac, running on my Virtual Machine. On my Mac I have Selenium Grid hub, which I run like this:
java -jar selenium-server-standalone-3.5.3.jar -role hub -port 4723
Also, there is a node:
java -jar selenium-server-standalone-3.5.3.jar -role node -hub http://10.0.2.15:4723/grid/register
In code, I start my driver like this:
SafariOprions options = new SafariOptions();
IWebDriver driver = new RemoteWebDriver(new Uri(hubURL), options.ToCapabilities());
My tests are running fine with current setup. But when it comes to clicking a link with attribute target='_blank' I'm starting to face some troubles. For other drivers, which I run locally, I can switch tab without any trouble: I'm getting driver.WindowHandles before I click a link, then I click a link and again retrieve Window Handles to compare with previous handles. After that I use driver.SwitchTo().Window(newHandle) and everything is ok.
But when it comes to RemoteWebDriver (or SafariDriver from Apple, I cannot say more precisely) I'm always getting only one Window Handle, even if the new tab is opened and i can see it.
I'm trying to avoid switching tab with "Command + T" as one of solutions suggested, because my tests are meant to be run on all browsers (Chrome, Firefox, Opera, Edge, Safari) and this wont work.
UPDATE: I've tried running Chrome and other browsers in Selenium Grid via RemoteWebDriver and I can say that this is not an issue of RemoteWebDriver. Next, I've installed Visual Studio for Mac and rewrite several things to run my tests without Selenium Grid, just using this code:
//if memory serves, just like this
SafariOptions options = new SafariOptions();
SafariDriver driver = new SafariDriver(options);
But, unfortunately, this didn't help. Driver navigated me to the page, clicked the link and opened a new tab, but without any switch. When I checked for driver.WindowHandles I've only got one, although there was two visible tabs. Neither driver.SwitchTo().ActiveElement nor driver.SwitchTo().Frame(hardcoded_frame_name) doesn't seem to work. Pretty long waits (for 60 seconds after opening the link and another one after that) aren't working too. Now I think that this is really a bug and I will try to report this to Apple as soon as I can.
But for now, maybe someone has a fancy workaround for this?
As we discussed in the comments, it seems to be a timing issue. So we will induce
WebDriverWait to sync up with the trailing Browser instance. I am providing a code block as a solution through Selenium-Java, consider implementing it in C# and update me if it works for you.
driver.get("http://www.google.com");
System.out.println("Page Title is : "+driver.getTitle());
String parent_window = driver.getWindowHandle();
((JavascriptExecutor) driver).executeScript("window.open('http://facebook.com/');");
WebDriverWait wait = new WebDriverWait(driver,3);
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
Set<String> allWindows_1 = driver.getWindowHandles();
ArrayList<String> tabs = new ArrayList<>(allWindows_1);
driver.switchTo().window(tabs.get(1));
wait.until(ExpectedConditions.titleContains("Facebook"));
System.out.println("First Child Handle : "+driver.getTitle());
I could help you with the Java version:
After the actions done, do this below.
//Store the parent window
String parentWindow = driver.getWindowHandle();
//Open a new Windows(Mailtrap)
String a = "window.open('https://mailtrap.io/signin','_blank');";
((JavascriptExecutor)driver).executeScript(a);
//This Thread.sleep is useful with Safari. Do not remove.
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//Take control over new browser
for(String handle: driver.getWindowHandles()){
driver.switchTo().window(handle);
}
I have a repetitive task at the end of the month to give commands to multiple Remote Desktop Connections (Win7, Win Server 2008, Win server 2012, Win 8 ...) and i need to open all of them one by one to do this task. I want somekind of tool that would log on each and every one of them and give commands.
Here is what i tried :
public Form1()
{
InitializeComponent();
rdp.Server = "1.2.3.4";
rdp.UserName = "Rmlabuser2";
IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
secured.ClearTextPassword = "Rmlabuser2";
rdp.Connect();
// open cmd.exe and give commands like VER and return output into a message text box
// rdp.SecuredSettings.StartProgram = #"c:\windows\System32\cmd.exe";
}
Full code :
http://www.codeproject.com/Articles/43705/Remote-Desktop-using-C-NET
Any ideeas?
Thanks.
You can use psexec to run commands on remote computer.
If you need to run commands within active session, you can create a scheduled task on that computer that will do the needed stuff. Scheduled tasks can be configured to run under currently logged-in session or from system/predefined account.
There are a number of C# libraries that can work with windows scheduled tasks. For example http://taskscheduler.codeplex.com/