Firefox Driver hangs on creation when using Jenkins node - jenkins

I have just installed the Selenium Grid plugin for Jenkins and beginning to explore distributing tests with it. I have created a simple test that just opens a browser, gets a url, and then closes the browser. This seems to work for Chrome (on Mac) and IE (on Windows) but for some reason when using Firefox 18.0.2 on Mac, I see the browser window open but the url I'm supposed to load never shows up in the url bar and things hang and I get an error:
WebDriverException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
It is hanging somewhere in the constructor to create the RemoteDriver. I added a trace statement right after the constructor and the code never gets there.
The weird thing is the test executes just fine if I start up a local Selenium Grid node on the same machine that fails and direct my tests there instead of the Jenkins Selenium Grid hub. So it seems to potentially be an issue with how I set up the Jenkins node but I can't figure out how to troubleshoot this. Any help would be appreciated.
My code is something like this:
WebDriver driver = null;
public Browser(String gridUrl) {
driver = makeFirefox(gridUrl);
driver.get(url);
}
private WebDriver makeFirefox(String gridUrl) {
FirefoxProfile prof = new FirefoxProfile();
prof.setEnableNativeEvents(true);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, prof);
WebDriver driver = null;
try{
driver = new RemoteWebDriver(new URL(gridUrl), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return driver;
}

For anyone who runs into this, I was able to at least temporarily "solve" the problem by downgrading to Firefox 17. Things work fine there, just not Firefox 18.

Related

Is Appium supported with MS Server 2022

We are trying to get Appium to run in a MS Server 2022 environment using the published calculator program. When it is run on a win-10 PC the application runs fine - it spawns the application and the script can control the calculator's keys.
When it is run on the 2022 server, the calculator.exe spawns but there is no control of the application keys.
There are some differences in the application/environment. In the "published" calc environment the app is addressed like this:
capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
This was not recognized by the system so we went for the direct path:
capabilities.setCapability("app", "C:\Windows\System32\calc.exe");
Many of the other addressable features of the calculator program showed different values for their addressable IDs.
Bottom line is that there are lots of differences between the systems, has anyone gotten MSserver 2022 and Appium to work?
`public class CalculatorTest {
private static WindowsDriver<WebElement> CalculatorSession = null;
private static WebElement CalculatorResult = null;
#BeforeClass
public static void setup() {
try {
DesiredCapabilities capabilities = new DesiredCapabilities();
//capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
capabilities.setCapability("app", "C:/Windows/System32/calc.exe");
CalculatorSession = new WindowsDriver<WebElement>(new URL("http://127.0.0.1:4727/"), capabilities);
CalculatorSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
CalculatorResult = CalculatorSession.findElementByAccessibilityId("CalculatorResults");
Assert.assertNotNull(CalculatorResult);
}catch(Exception e){
e.printStackTrace();
} finally {
}
}
`
org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: Failed to locate opened application window with appId: C:/Windows/System32/calc.exe, and processId: 29876.
The output of the power shell:Get-StartApps command for calculator.
MSServer 2022:
Calculator         {1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\win32calc.exe
Windows 10:
Calculator Microsoft.WindowsCalculator_8wekyb3d8bbwe!App

Printing a PDF from a Windows Service using GhostScript - How to diagnose permission issue

I have a service written in C#. Running the following code:
public static bool PrintPDF(string ghostScriptPath, int numberOfCopies, string printerName, string pdfFileName)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.Arguments = $#"-dPrinted -dNoCancel=true -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies={numberOfCopies} -sDEVICE=mswinpr2 -sOutputFile=""\\spool\{printerName}"" ""{pdfFileName}""";
startInfo.FileName = Path.Combine(ghostScriptPath, "gswin64c.exe");
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
Process process = Process.Start(startInfo);
Console.WriteLine(process.StandardError.ReadToEnd() + process.StandardOutput.ReadToEnd());
process.WaitForExit(30000);
if (process.HasExited == false) process.Kill();
return process.ExitCode == 0;
}
Outside of Windows Service, it's working without any problem.
Inside the service, when running as Local System, GhostScript started running but timed out without any output.
After some fiddling around, I finally switched the service to run as Network Service and also set Network Service as owner of the folder from which the service exe and GhostScript exe where placed (Before I did that, I got Access Denied error) - And now the service is running fine.
My questions is - How come Network Service can work where Local System can't? I thought Local System has more privileges. And also, how can I get more info regarding the actual issue? I've found a workaround but it was simply a lucky shot in the dark. I have no idea what the real problem is.
Some more info:
Running Windows 10 64 bit, and using GhostScript v9.29
You need to run the service under a local user account that is dedicated to it.
You also need to login with that user at list one time in order the printer list to be populated!

how to do automated browser testing with Dart?

Is there any headless browser for dart? Or a wrapper for something like selenium? My goal is to use the browser for automated end-user testing for a website i wrote years ago. Now i need to make few changes on the site. Since it contains specific business logic, i would like to write some quick tests for the site without refactoring or modifying it for unit-tests, before i make those changes.
It seems like a fun introduction to get more familiar with dart ecosystem as well.
You can use Chrome or Dartium and drive it with ChromeDriver and the webdriver package
Here is a quick example:
import 'dart:convert';
import 'dart:io';
import 'package:webdriver/io.dart';
main() async {
// Start the ChromeDriver process
Process chromeDriverProcess = await Process
.start('chromedriver', ['--port=4444', '--url-base=wd/hub']);
await for (String browserOut in const LineSplitter()
.bind(UTF8.decoder.bind(chromeDriverProcess.stdout))) {
if (browserOut.contains('Starting ChromeDriver')) {
break;
}
}
// Connect to it with the webdriver package
WebDriver driver = await createDriver(
uri: Uri.parse('http://localhost:4444/wd/hub/'),
desired: Capabilities.chrome);
// Go to your page
await driver.get('http://stackoverflow.com');
//TODO: write your tests
print(await driver.execute('return navigator.userAgent', []));
// Take a simple screenshot
String screenshot = await driver.captureScreenshotAsBase64();
new File('stackoverflow.png').writeAsBytesSync(BASE64.decode(screenshot));
driver.quit();
chromeDriverProcess.kill();
}
It is not totally "headless" but it is easy to make it work on server like Travis-CI with this config:
before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
content-shell is a headless browser with Dart support like Dartium
(https://www.dartlang.org/install/mac)
and https://pub.dartlang.org/packages/webdriver can be used for Selenium test.
There is headless support for Chromium work-in-progress. When Dartium is upgraded to use this Chromium version, Dartium should be able to be run headless.
The Dart team is working on incremental JS compilation (DDC - Dart development compiler) which should allow to use Chrome as development browser. The headless mode (when available) can be used directly.
Depending on your use case and requirements, you might also be able to use puppeteer
For example (from the docs), you can take a screenshot of the page
void main() async {
// Start the browser and go to a web page
var browser = await puppeteer.launch();
var page = await browser.newPage();
// Setup the dimensions and user-agent of a particular phone
await page.emulate(puppeteer.devices.pixel2XL);
await page.goto('https://dart.dev', wait: Until.networkIdle);
// Take a screenshot of the page
var screenshot = await page.screenshot();
// Save it to a file
await File('example/_github.png').writeAsBytes(screenshot);
await browser.close();
}
You can also generate a PDF, take a screenshot of a node, interact with the page, evaluate JavaScript, and use the results from your Dart code, and more.

Firefox native messaging through webextension

Created a webextension for firefox (currently using Nightly 52), that uses native messaging to launch a java program on Linux (Ubuntu 14, 32x).
The webextension loads, reads the .json file and reads the path which points to a script that starts the java program. The JSON and the path are correct as when I use:
var native = browser.runtime.connectNative("passwordmanager");
console.log("native.name" + native.name); //outputs passwordmanager.
native.onDisconnect.addListener(function(m) { console.log("Disconnected"); });
The above code prints the name of the native port and also prints "Disconnected". So I m guessing the native app is terminating for some reason.
The application is only skeleton right now, that just does sysout and reads sysin and works correctly if Launch it directly through the shell script.
While debugging the webextension, I am not able to step into the call to connectNative, as it just steps-over that call instead of doing step-in. So kind of out of options whats' going wrong.
Please let me know if anyone is able to create a native messaging app based on FF webextension and any pointers on what I might be doing wrong.
Thanks
This solution here shows you how to detect onConnect and onFail. It should help you out to figure out your real problem.
So I don't think you can do proper error handling with connectNative from the JS side alone. You can do somewhat error handling if you get the exe side involved, but you can't get a string for "error reason" when an error occurs. The error is only logged to console.
First make sure to set your deeloper prefs, so messages show in your browser console. You can use this addon - https://addons.mozilla.org/en-US/firefox/addon/devprefs/ - or read that addon description it gives you the MDN page with the prefs to set.
Then this is how you can do some sort of error handling (without error reason) (pseudo-code - i might need a .bind in the callbcks):
function connectNative(aAppName, onConnect, onFail) {
var listener = function(payload) {
if (!connected) {
connected = true;
port.onDisconnect.removeListener(failedConnect);
onConnect();
} else {
// process messages
}
}
var failedConnect = function() {
onFail('failed for unattainable reason - however see browser console as it got logged there');
}
var connected = false;
var port = chrome.runtime.connectNative(aAppName);
port.onMessage.addListener(listener);
port.onDisconnect.addListener(failedConnect);
return port;
}
Now in your exe, as soon as it starts up, make it write to stdout something. That will trigger the onConnect.

sendkeys command causing exception in selenium webdriver on IOS safari

I have been trying to run some sample Remote WebDriver tests on the Safari browser on the IOS Simulator 7.0 (IPhone) but my tests give an exception every time I try to type in values on a text box. Just trying to use the example from iosdriver
DesiredCapabilities safari = IOSCapabilities.iphone("Safari");
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://<someip>:4444/wd/hub"), safari);
driver.get("http://hp.mobileweb.ebay.co.uk/home");
WebElement search = driver.findElement(By.id("srchDv"));
search.sendKeys("ipod");
search.submit();
gives me the exception
a "org.openqa.selenium.NoSuchElementException: cannot find element for criteria :{"AND":[{"l10n":"none","expected":"UIAElement","matching":"exact","method":"type"},{"l10n":"none","expected":"Address","matching":"exact","method":"name"}" .
Anyone else run into this? It is identifying the element but typing in values fail..It works fine when I try it on firefox on my desktop.
I am no expert, but am familiar with selenium webdriver..
Are you sure that the id for "search " --- ('srchDv') actually exists on the page you are trying to automate?
if so
i would then look into the UIA -Element Hierarchy / Accessibility link to UIA Element Class reference
Hope this is helpful
You have an incorrect selector. The page you are automating does not have an id srchDv. If you are getting the search box, then you need to use:
driver.findElement(By.id("gh-ac")).clear();
driver.findElement(By.id("gh-ac")).sendKeys("ipod");
Also, instead of using submit, personally i would follow the way that your user would commit the action, and that's by clicking the search button.
driver.findElement(By.id("gh-btn")).click();

Resources