How do I get chrome working with selenium, using php webdriver? - php

Everything works fine with Firefox, but I can't start chrome. I'm on linux, using php webdriver bindings.
require_once "/usr/local/src/selenium/php-webdriver-bindings-0.9.0/phpwebdriver/WebDriver.php";
putenv("PATH=".getenv("PATH").':'.'/usr/local/src/selenium/chrome_webdriver/'); //Prepare for chrome
$webdriver = new WebDriver("localhost", "4444");
//$webdriver->connect("chrome");
$webdriver->connect("chrome","",array(
'webdriver.chrome.driver'=>'/usr/local/src/selenium/chrome_webdriver/chromedriver',
));
The error message I get is "The path to the chromedriver executable must be set by the webdriver.chrome.driver system property". As you can see, I've tried setting that in the desiredCapabilities array, but that must be the wrong place. I can see in the selenium logs that my setting is getting through as this log line shows:
INFO - Executing: [new session: {javascriptEnabled=true, webdriver.chrome.driver=/usr/local/src/selenium/chrom..., browserName=chrome, nativeEvents=false, version=}] at URL: /session)
I start selenium with java -jar selenium-server-standalone-2.21.0.jar
I'm using Chromium v.18.
I created a shortcut /usr/bin/google-chrome that points to /usr/bin/chromium-browser
I can start chromedriver manually with no problems. It says:
port=9515
version=20.0.1133.0
Having that running, or not, does not make any difference to the error message selenium gives me.
UPDATE: Related question: selenium 2 chrome driver (answer there is for java, not php)

You can try passing the webdriver.chrome.driver property from commandline while starting the selenium server. Like this:
java -Dwebdriver.chrome.driver = pathtochromedriver -jar selenium-server.jar
I am not sure about the reason why the other one is not working. You need to check whether its really setting the system property from code..

Without any blanks it worked for me on WinXP32:
java -Dwebdriver.chrome.driver=C:\chromedriver.exe -jar selenium-server.jar

Related

Symfony(4.4) Panther Test case doesn't work on GitlabCI

I use Panther Tests Case and PHPUnit on my symfony project for functional testing.
When I run my tests on my computer (php bin/phpunit), everything works fine. When i'm connected on my server and I run my tests, everything works fine.Chrome-driver is correctly installed on th server and i can run it with command lines.
BUT, when i push on gitlab and my CI starts, i always have the same error :
That is a screenshot from gitlab interface
My script begins with a connection to my server using SSH.So the beahviour should be the same as when i connect to my server using Putty and SSH...
The command i use on my .gitlab.ci script is 'php bin/phpunit'. The same that i use locally.
I've found some posts speaking about this problem but all on Selenium and nothing for panther... Please help ! :)
don't know if the problem is still existing, but I've been struggling with the same issue since yesterday and I fixed it by evenutally reading the doc ;-) : https://github.com/symfony/panther#chrome-specific-environment-variables
Due the Chrome's sandboxing, there is the need to specify a specific ENV variable to ensure the correct running in a container.
I update my .gitlacb-ci.yml with this on my test step:
before_script:
- ... {HERE : ensure your chromedriver is existing in the container}
- export PANTHER_NO_SANDBOX=1
So... lesson learned/remembered : 5 min of doc reading is worth 2 days of google searching... ;-)

php DOTNET class - works on command line NOT on web browser

The below code works from command line .
$full_assembly_string = 'dllname';
$classname= "classname";
$cObj = new DOTNET($full_assembly_string,$classname);
echo($cObj ->SayHello());
But when i try to execute from browser it show the message window - apache has stopped working.
Is there anyone was able to run .net custom dll from php ??
This example works on browser and cmd .
http://php.net/manual/en/class.dotnet.php
Depending on what kind of implementation you're using there can be 2 php.ini files:
1 for command line
1 for server env
i suggest locating and searching for discrepancies between the 2.

Selenium WebDriver Firefox

I'm running a LAMP configuration on Ubuntu Server 13.04. I setup XVFB and Selenium to load on startup as services (/etc/init.d). Firefox is working if I export DISPLAY before opening it in a terminal session, however I'm not attempting to test in a terminal session; I'm using PHPWebDriver to call an instance of WebDriver.
When attempting to open a session as so:
$driver_include = "/includes/user/webdriver/__init__.php";
require $driver_include;
$wd_host = 'http://localhost:4444/wd/hub';
$web_driver = new PHPWebDriver_WebDriver($wd_host);
$session = $web_driver->session('firefox');
I get the following error:
Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.
I also have Xvfb set to DISPLAY :10. By exporting to this display I can open Firefox in a terminal.
My question is:
How do I tell WebDriver to use a certain DISPLAY by default without starting it manually from a terminal session?
I think you will be fine as long as you make sure that the Grid server is running in a shell WITHIN a windowed environment. It won't work if you start the grid outside of a windowed environment that is needed to start the Firefox profile. If you are trying to run headless, without a DISPLAY, then you should use GhostDriver/PhantomJS instead, or something similar.

Google App Engine PHP Helloworld Example Does Nothing

I assume I'm making some simple mistake, but I just can't get the Google App Engine PHP SDK (GAE) "helloworld" example to work.
When I attempt to run the example on a Windows XP command line, I get no errors. The dev appserver is ever started on port 8080. I followed the GAE PHP SDK "Getting Started" page to the letter. If I mistype the path name, I get an error on that, but that’s it.
I have installed Python 2.7, PHP 5.4 and the GAE PHP SDK 1.8.3. All seem to work independently without error. Testing such…phpinfo() works, the Python interpreter works as well.
I’ve read all of the other questions/answers on this subject on the Stack(here) but nothing has helped. Here's some details:
My "helloworld" dir (the app.yawl file is there too):
C:\helloworld\helloworld.php
My Google GAE dir:
C:\google_appengine
My PHP dir:
C:\PHP
My Python dir:
C:\Python27
Here's the dev appserver startup command line I'm using in a Windows XP CMD window:
python C:\google_appengine\dev_appserver.py --php_executable_path=C:\PHP\php-cgi.exe C:\helloworld\helloworld
The dev web server does not start, can't see the listener on default port 8080 in netstat.
You said that the app.yawl file is present in the helloworld directory.
Its actually app.yaml . You may have saved that with incorrect extension. Check it.
The other thing I noticed is in the last command you are pointing to the .php file as C:\helloworld\helloworld.
You should actually point to the APPLICATION_DIRECTORY, which in your case is just C:/helloworld/

Python: Can't start Selenium Webdriver (Firefox) via a script, but it works via command line

Title says it all. I'm using webdriver on a remote webserver without a GUI. From the command line, I can do this and everything works fine:
from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800,600))
display.start()
browser = webdriver.Firefox()
I.e., I can navigate the web, get urls, get source code, and everything else with the browser instance. But trying to execute a script on the server containing the same lines doesn't work. It might be relevant that the script is executed via PHP. Everything in the script works up until browser = webdriver.Firefox() - that is, the imports and display stuff all work fine. It's just that last line; for some reason, the browser doesn't want to open when a script tries to do it. This makes no sense and I'm really stumped. Possible reasons/fixes? Maybe something to do with permissions?
EDIT
Just to clarify, I'm doing this all on the remote server. By command line I'm using SSH with PUTTY, and when I try testing the script, I simply do it on the website.
Solved it by changing the permissions of the folder containing the Python script that called the webdriver from 755 to 757 (i.e., I gave write permissions to all users). I'm not sure whether this was a quirk of my situation because of something else I overlooked or whether there's actual insight to be gained here, but I'd say the take home lesson is if weird stuff is happening when working on an unfamiliar server, check the permissions.

Categories