Browser is not opening when running Jenkins as a service - jenkins

I am running my selenium tests in IE in a Windows VM with the help of Jenkins. When running java -jar jenkins.war, my suite is working fine..
But when Jenkins is running as a service, browser is not opening and always it is failing.
I have opened the service properties and given Allow service to interact with desktop.
The alternate way I am running java -jar jenkins.war as a start up.. But this is starting jenkins when I login VM but if some circumstances due to windows patch update if machine gets restarted this is not working until I login the VM which is not i want.
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73), userDataDir=C:\Windows\TEMP\scoped_dir6052_18573}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=70.0.3538.102, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=false, acceptInsecureCerts=false, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]
Session ID: e6ef32b1e294ce9644a5078d9b8bf8c4
Failed ***********
Started InternetExplorerDriver server (32-bit)
2.51.0.0
Listening on port 45007
Only local connections are allowed
org.openqa.selenium.UnhandledAlertException: Modal dialog present:
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'xx-xx-xx', ip: 'xx.xx.xxx.xxx', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, enablePersistentHover=true, ie.forceCreateProcessApi=false, pageLoadStrategy=normal, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:45007/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]
Session ID: dbbe2316-a3b3-4e39-82e3-04dae698ec73
Nov 16, 2018 6:17:43 PM org.openqa.selenium.support.ui.ExpectedConditions findElement
WARNING: WebDriverException thrown by findElement(By.id: txtUserName)
org.openqa.selenium.UnhandledAlertException: Modal dialog present:
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'xxx-xx-xx', ip: 'xx.xx.xxx.xxx', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver

Error log states that your test failed because of:
org.openqa.selenium.UnhandledAlertException: Modal dialog present
It happens when some alert appeared and was not properly handled by your test. To fix it you need to add a logic to handle alert before you call a method to look for an element findElement(By.id("txtUserName")). The code might look like this:
try {
Alert alert = driver.switchTo().alert();
System.out.println("Alert appeared. Text= " + alert.getText());
alert.accept();
} catch (NoAlertPresentException ignored) {
//if alert is not present for some reason we don't want to fail and can continue a test
}
or you can wrap to a findElement call with a try catch, then close the alert, and try your logic again:
WebElement el;
try {
el = findElement(By.id("txtUserName"));
} catch (UnhandledAlertException f) {
try {
Alert alert = driver.switchTo().alert();
System.out.println("Alert appeared. Text= " + alert.getText());
alert.accept();
el = findElement(By.id("txtUserName"));
} catch (NoAlertPresentException ignored) {
//if alert is not present for some reason we don't want to fail and can continue a test
}
}

Related

chrome failed to start: exited abnormally in docker container on macos

On my Mac, I built image with FROM selenium/standalone-chrome-debug:3.4.0-chromium in Dockerfile.
When I run my app in the container, I got:
org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 4.19.76-linuxkit x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.13 seconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'a45e0250acbf', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.19.76-linuxkit', java.version: '1.8.0_121'
Driver info: driver.version: ChromeDriver
Image built in Jenkins with same Dockerfile run same application, it has no issue. Both chromedriver=2.29.461571.
I have setup remote debug and want to debug on my macos before I push to Jenkins/linux, but blocked by this chrome failed to start: exited abnormally in container on macos.
Why this happens on my macos but not in Jenkins/Linux and how to fix it?
This error message...
org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 4.19.76-linuxkit x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.13 seconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'a45e0250acbf', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.19.76-linuxkit', java.version: '1.8.0_121'
Driver info: driver.version: ChromeDriver
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.29
Release Notes of chromedriver=2.29 clearly mentions the following :
Supports Chrome v56-58
Presumably you are using the latest chrome=85.0
Release Notes of ChromeDriver v85.0 clearly mentions the following :
Supports Chrome version 85
So there is a clear mismatch between ChromeDriver v2.40 and the Chrome Browser v85.0
Solution
Ensure that:
JDK is upgraded to current levels JDK 8u252.
Selenium is upgraded to current released Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v85.0 level.
Chrome is updated to current Chrome Version 85.0 level. (as per ChromeDriver v85.0 release notes)
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
Take a System Reboot.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

When I run the Appium test for the below code

AndroidDriver driver;
#Test
public void setUp() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
/*capabilities.setCapability("BROWSER_NAME", "Android");*/
capabilities.setCapability("platformVersion", "5.1");
capabilities.setCapability("deviceName","G4");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("appPackage", "StatusBar"); // This is package name of your app (you can get it from apk info app
capabilities.setCapability("appActivity", "com.android.calculator2/.Calculator t126"); // This is Launcher activity of your app (you can get it from apk info app)
//Create AndroidDriver instance and connect to the Appium server.
//It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities
driver = new AndroidDriver(new URL("http://10.97.52.83:4723/wd/hub"), capabilities);
}
Getting below error
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: 'java -version' failed. Error: Command failed: 'java' is not recognized as an internal or external command,
operable program or batch file.
) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 242 milliseconds
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35'
System info: host: 'ingglw016025a', ip: '10.97.52.83', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51'
This error means your appium server is not running. Just try to kill the server and start it again. This should fixed this issue.

Grails Geb: Chrome failed to start

I'm trying to set up geb functional testing in Grails, then I get "chrome failed to start". Could anyone help me out?
Exception Details:
Starting ChromeDriver 2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf) on port 9374
Only local connections are allowed.
Failure: |
unauthorized login to the home page(com.myapp.HomeFunctionalSpec)
|
geb.driver.DriverCreationException: failed to create driver from callback 'script1426780645607568441896$_run_closure1#b0894c'
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.clearCookies(Browser.groovy:483)
at geb.Browser.clearCookiesQuietly(Browser.groovy:491)
at geb.spock.GebSpec.resetBrowser(GebSpec.groovy:45)
at geb.spock.GebSpec.cleanup(GebSpec.groovy:67)
Caused by: org.openqa.selenium.WebDriverException: unknown error: chrome failed to start
(Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 586 milliseconds
Build info: version: '2.41.0', revision: '3192d8a6c4449dc285928ba024779344f5423c58', time: '2014-03-27 11:29:39'
System info: host: 'ILWS011', ip: '192.168.0.107', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51'
Driver info: org.openqa.selenium.chrome.ChromeDriver
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.chrome.ChromeDriver.startSession(ChromeDriver.java:181)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:139)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:160)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:149)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:106)
at script1426780645607568441896.run_closure1(script1426780645607568441896.groovy:5)
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
... 10 more
Below is the BuildConfig.groovy
def gebVersion = "0.9.2"
def seleniumVersion = "2.41.0"
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
....
test "org.apache.httpcomponents:httpcore:4.2.3"
test "org.gebish:geb-spock:$gebVersion"
test "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
test "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
}
plugins {
// plugins needed at test environment
test ":geb:$gebVersion"
}
test/functional/GebGonfig.groovy
import org.openqa.selenium.chrome.ChromeDriver
driver = {
System.setProperty("webdriver.chrome.driver", "C://chromedriver//chromedriver.exe")
new ChromeDriver()
}
I'm using the Chromedriver2.14, and putting it in C:/chromedriver/
Did I set everything right? Are the versions matching with each other?
It's maybe because of old selenium Version. Use 2.45 and the newest webdriver.

Error with iOS driver set up

As per the instruction with http://ios-driver.github.io/ios-driver/?page=setup , i am trying to set up ios driver my application first testing using this automation.
I have installed java 7 and downloaded the app in given link. Installed OSX 10.9. While executing the command $ java -jar ios-server-0.6.6-SNAPSHOT-standalone.jar -aut path/to/aut.app -port 4444 i am getting below error
45:08:315 INFO ApplicationStore.<init> App archive folder:/Users/labuser/Downloads/applications
false
45:08:838 SEVERE IOSServer.main cannot start ios-driver server: org.openqa.selenium.WebDriverException: path/to/aut.app isn't an IOS app.
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9', java.version: '1.7.0_55'
Driver info: driver.version: unknown
Any one suggest me to resolve this error and am new to use commands in terminal
It looks like path/to/aut.app is a placeholder and you need to replace it with the path to your application.

Selecting by a numeric id in grails geb

Using the chrome driver for selenium, I'm trying to select an element from my page by its id, which is numerical (ie 1000).
This fails, giving:
org.openqa.selenium.InvalidElementStateException: findElements execution failed;
SYNTAX_ERR: DOM Exception 12 (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 13 milliseconds
Build info: version: '2.2.1', revision: '16551', time: '2012-04-11 21:42:35'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-33-generic', java.version: '1.7.0_09'
Driver info: driver.version: RemoteWebDriver
However, if I change the id to be some string that is composed not exclusively by numbers (ie m1000), the selection works.
Any idea why this is happening?
Seems that it's because ID tokens must begin with a letter ([A-Za-z]), see http://w3.org/TR/html401/types.html#type-name

Resources