how to run codeception acceptance testing with selenium on remote server - java

I have a testing server for my phpunit, and now we want to add our codeception acceptance testing with selenium.
But as you the remote server has no "desktop" so it will not open a browser like in our developers computers.
I tried installing firefox on the machine but I still get this error:
Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: LINUX
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'testdev', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version:
'3.2.0-23-generic', java.version: '1.7.0_65'
Driver info: driver.version: FirefoxDriver
so now I did this
WebDriver:
url: 'http://example.com/'
browser: firefox
capabilities:
binary: "/usr/bin/firefox"
and I get this error:
Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: no display specified
Error: no display specified
is it possible what I'm doing?
or I must have a "screen"?

In order to use Selenium with Firefox, or Chrome, etc - you need a linux distro that has a User Interface.
If you are on a linux machine that doesn't have a display (aka, just a terminal), then you can research Selenium HTMLUnit (headless browsing).

You could do headless browsing via the PHPBrowser, or you could install a GUI like xfce4 vnc4server, which will give you a virtual desktop to run Firefox in. This has the added bonus that you can watch the test run graphically.

Related

selenium script is not running [duplicate]

This question already has answers here:
SessionNotCreatedException: Message: session not created from disconnected: unable to connect to renderer with ChromeDriver 2.45 Chrome v71
(6 answers)
Closed 3 years ago.
Starting ChromeDriver 77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865#{#442}) on port 14991
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1573970978.437][SEVERE]: Unable to receive message from renderer
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: session not created
from disconnected: Unable to receive message from renderer
(Session info: chrome=77.0.3865.120)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'DESKTOP-JCFLT7B', ip: '192.168.1.107', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '10.0.2'
Driver info: driver.version: ChromeDriver
This issue is occurs because your chrome browser version is not compatible with the chrome driver version. Check your chrome browser version and then install chrome driver from the below location based on your os.
https://chromedriver.chromium.org/downloads
for e.g:
I am using Version 78.0.3904.97 (Official Build) (64-bit) with windows and currently using chromedriver_win32.zip

Selenium unable to connect to ChromeDriver 75 on Mac

We are upgrading a previously-working Selenium/Java/Chrome test configuration, to newer versions:
ChromeDriver 2.35 -> 75.0.3770.90
Selenium Java 3.14 -> 3.141.59
macOS 10.14.5 (unchanged)
Java 11.0.3 (unchanged)
Chrome 75.0.3770.100 (unchanged)
However, when attempting to run a Selenium test, we see:
java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:28719
The full stack/log:
Starting ChromeDriver 75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770#{#1003}) on port 28719
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Jun 26, 2019 10:45:03 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
...
org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:28719
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'Craigs-iMac.local', ip: '192.168.1.131', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.5', java.version: '11.0.3'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByTagName(RemoteWebDriver.java:396)
at org.openqa.selenium.By$ByTagName.findElement(By.java:320)
All the resources I've found in this area suggest using --whitelisted-ips='', which did not have an effect, or were related to incompatible Selenium/Chrome/ChromeDriver versions, which I don't think is the issue here.
Update: I can confirm that the driver starts, and is listening on port 28719, but then stops at some point between startup and execution of the actual test. I've found no errors/logging related to the shutdown.
Update 2: I've debugged, and the initial commands sent to the remote driver succeed (setWindowSize()), but this line causes the driver to die silently:
((WebStorage) driver).getLocalStorage().setItem("token", token);
It seems newer versions of the ChromeDriver (Or Selenium? I don't know.) launch Chrome with an initial page sitting at the URL data:.
By adding these system properties prior to instantiating the ChromeDriver:
System.setProperty("webdriver.chrome.logfile", "/Users/craig/chromedriver.log");
System.setProperty("webdriver.chrome.verboseLogging", "true");
I was able to glean the following right before the driver quits:
[1561563455.971][INFO]: [01517094c63c0dd609c06a5622afe6b1] RESPONSE ExecuteScript ERROR <unknown>: Failed to read the 'localStorage' property from 'Window': Storage is disabled inside 'data:' URLs.
(Session info: headless chrome=75.0.3770.100)
So by changing this call in my test utility code:
((WebStorage) driver).getLocalStorage().setItem("token", token);
To this:
if (driver.getCurrentUrl().startsWith("data:")) {
// Driver will quit if we try to access localStorage without a page load
driver.get("/");
}
((WebStorage) driver).getLocalStorage().setItem("token", token);
Everything is now fine. https://i.imgur.com/edBQBeJ.gif
Editing:
LocalStorage is available only after launching any website. ie after driver.get
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/html5/LocalStorage.html

How to run selenium tests on chrome if only binary file of chrome is placed in a server location in E drive

I have a situation in my project as below :
My code was executing as expected till the IT admin uninstalled chrome and FF from Jenkins server.
After raising a concern they placed a chrome binary in E drive .( E:\GC Local\GoogleChrome).But Chrome is not installed anywhere
I am facing issues to resolve this.
Do anyone guide here ?
Code I used :
if ("chrome".equals(browser))
{
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir")
+ "\\src\\test\\resources\\drivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
options.addArguments("--start-maximized");
driver = new ChromeDriver(options);
}
Will it work for you ?
ChromeOptions options = new ChromeOptions();
options.setBinary("E:\\GC Local\\GoogleChrome");
I understand that in homepath \app data chrome should be installed by default to run chrome tests. In my case , there is no chrome istalled in homepath-app but in E drive
When I used the below code :
ChromeOptions options = new ChromeOptions();
options.setBinary("E:\\GCLocal\\GoogleChrome\\GoogleChromePortable.exe");
// System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\Browsers\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir")
+ "\\src\\test\\resources\\drivers\\chromedriver.exe");
driver = new ChromeDriver(options);
I am getting getting the following :
T E S T S
Running TestSuite
Browser :chrome
Starting ChromeDriver 2.29.461591 (62ebf098771772160f391d75e589dc567915b233) on port 45594
Only local connections are allowed.
Error in initializing the Test .Details :-
org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited normally
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 62.74 seconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'WHIS2002', ip: '10.192.129.112', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_77'
Driver info: org.openqa.selenium.chrome.ChromeDriver
./TestReport.html
The above approach is correct. My issue was that portable-chrome binary refused to open due to some issues in server .code was fine.
This happened because of portable chrome binary performance issues which I solved like this :
Google Chrome Portable may run slowly from some flash drives. You can speed this up by copying GoogleChromePortable.ini from the GoogleChromePortable\Other\Source directory to the GoogleChromePortable directory and editing it to set RunLocally=true. If you do so, be sure to allow Google Chrome Portable time to copy your profile back after shutting it down. Of course, there are privacy implications to copying your personal data locally to a PC not under your control.
Thanks

Unable to start Phantomjs driver from java .app on OSX

I have created an application on Java that starts a phantomjs driver.
My program successfully creates the phantomjs driver when launched from eclipse with the following lines:
DesiredCapabilities desireCaps = new DesiredCapabilities();
desireCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, directory + "/phantomjs");
desireCaps.setCapability("phantomjs.cli.args", Collections.singletonList("--ignore-ssl-errors=true"));
desireCaps.setCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0");
driver = new PhantomJSDriver(desireCaps);
I created an .app as such:
where "MainJar.jar" is the jar generated by eclipse,
"launcher" is the batch that basically does java -jar MainJar.app, and "phantomjs" is the selenium phantomjs official executable.
When I launch the application from the ".app", I get the following error on driver = new PhantomJSDriver(desireCaps);:
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'Air-de-Me', ip: 'XXX.XXX.X.XX', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_73'
Driver info: driver.version: PhantomJSDriver
However, when I run the application by launching the "launcher" script, the application successfully creates the driver. My first though was that the "app" could not find the phantomjs driver because the path was set incorrectly, but I printed (phantomjs_file).exists(); in my log and it finds it correctly.
I have set rights on every single file inside my app and the app itself with chmod 777, just to exclude permission errors.
Is there a reason why the browser could not init?
Any help would be greatly welcome.
I have found the answer to my problem. The problem was that phantomjs could not get the permissions to write its own log file when run from the ".app".
I have found a way (the only way that worked for me), to disable phantomjs log-writting:
driver = new PhantomJSDriver(new PhantomJSDriverService.Builder()
.usingPhantomJSExecutable(new File("PATH_TO_EXECUTABLE"))
.withLogFile(null).build(),
desireCaps);

Chromedriver failing on Jenkins (Linux)

I am trying to run UI tests on Chrome on Jenkins, and from the error it appears that it is failing to start.
org.openqa.selenium.WebDriverException: chrome not reachable
(Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Linux 2.6.32-358.el6.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.54 seconds (user: 'UnknownUser-0', output: '1440016601647')
Build info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-27 09:10:26'
System info: host: 'abc.xyz.com', ip: '111.222.333.444', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-358.el6.x86_64', java.version: '1.8.0_05'
Driver info: org.openqa.selenium.chrome.ChromeDriver
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
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:171)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:139)...
The code (in Java) simply tries to instantiate a default instance of Chromedriver, and fails. The following message also shows in the log, which confuses me. It appears that the driver is opening, but stopping immediately?
Starting ChromeDriver 2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf) on port 4601
Only local connections are allowed.
[0.422][WARNING]: PAC support disabled because there is no system implementation
Starting ChromeDriver 2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf) on port 9515
Only local connections are allowed.
The instantiation is done as:
WebDriver webDriver = null;
String chromeDriverLocation = MyCustomPropertyReader.getProperty("webdriver.chrome.binary.location");
System.setProperty("webdriver.chrome.driver", chromeDriverLocation);
final DesiredCapabilities capabilities = DesiredCapabilities.chrome();
webDriver = new ChromeDriver(capabilities);
I am able to run the Chromedriver from the command prompt, and I have also checked that all the environment variables that are needed to load it up and indeed available during the instantiation.
Could someone tell me what I might be missing, or if there is a way to obtain more information about the cause of this failure?
The issue was resolved by updating the browser installation, and making sure that both Chromedriver and the Chrome browser can be run from the command prompt.

Categories

Resources