minkphp / minksahidriver Goto Github PK
View Code? Open in Web Editor NEW[DEPRECATED] Sahi.JS driver for Mink framework
License: MIT License
[DEPRECATED] Sahi.JS driver for Mink framework
License: MIT License
We're recently (see Behat/Mink#438) reformatted xpath expressions in NamedSelector
to make them more manageable.
Unfortunately this has broken tests completely, because MinkSahiDriver
is putting xpath expressions into JavaScript and this becomes multi-line string and causes JavaScript error.
This is example PHPUnit output:
21) Tests\Behat\Mink\Driver\SahiDriverTest::testAdvancedFormSecondSubmit
Behat\SahiClient\Exception\ConnectionException: error:_sahi.setServerVarPlain('___lastValue___52d82e38d82b9', (function(){
var count = 0;
while (_byXPath("(//html/.//input
[./@type = 'submit' or ./@type = 'image' or ./@type = 'button' or ./@type = 'reset'][((./@id = 'Login' or ./@name = 'Login') or contains(./@value, 'Login') or contains(./@title, 'Login'))]
|
.//input
[./@type = 'image'][contains(./@alt, 'Login')]
|
.//button
[((./@id = 'Login' or ./@name = 'Login') or contains(./@value, 'Login') or contains(./@title, 'Login') or contains(normalize-space(string(.)), 'Login'))]
|
.//*
[./@role = 'button'][((./@id = 'Login' or ./@name = 'Login') or contains(./@value, 'Login') or contains(./@title, 'Login') or contains(normalize-space(string(.)), 'Login'))])["+(count+1)+"]")) count++;
return count;
})())
SyntaxError: unterminated string literal
Sahi.prototype.ex@http://www.domain.tld/_s_/spr/concat.js:3480
@http://www.domain.tld/_s_/spr/concat.js:3267
<a href='/_s_/dyn/Log_getBrowserScript?href=null&n=3482'><b>Click for browser script</b></a>
.../vendor/behat/sahi-client/src/Behat/SahiClient/Connection.php:221
.../vendor/behat/sahi-client/src/Behat/SahiClient/Connection.php:240
.../src/Behat/Mink/Driver/SahiDriver.php:628
.../src/Behat/Mink/Driver/SahiDriver.php:260
.../vendor/behat/mink/src/Behat/Mink/Element/Element.php:91
.../vendor/behat/mink/src/Behat/Mink/Element/Element.php:67
.../vendor/behat/mink/src/Behat/Mink/Element/TraversableElement.php:119
.../vendor/behat/mink/tests/Behat/Mink/Driver/GeneralDriverTest.php:806
I get error when called:
$session->getStatusCode();
PHP Fatal error: Uncaught exception 'Behat\Mink\Exception\UnsupportedDriverActionException' with message 'Status code reading is not supported by Behat\Mink\Driver\SahiDriver' in /behat-mink/vendor/behat/mink-sahi-driver/src/Behat/Mink/Driver/SahiDriver.php:256
Stack trace:
#0 /behat-mink/vendor/behat/mink/src/Behat/Mink/Session.php(192): Behat\Mink\Driver\SahiDriver->getStatusCode()
#1 /behat-mink/mink-example.php(28): Behat\Mink\Session->getStatusCode()
This temporary restriction or a bug? Thanks.
Hello!
I'm trying to run test on Firefox, but somehow filed are not filled in:
Scenario:
Given I am a guest
And I go to "/app"
And I should see an "input[name=username]" element
And I should see an "input[name=password]" element
And I fill in "username" with "admin"
And I fill in "password" with "password"
And I press "Login"
...
I've tried different pages etc. - still the same result. On Chrome/Opera/Safari this tests goes well and fields go get filled.
A simple scenario that clicks on a link which opens a pdf and then goes to another page, makes behat waits until a time out exception is thrown when using Sahi.
Feature: download a file In order to resolve an issue downloading a file with behat As a developer I need to create a failing test Scenario: Try the download of a pdf with Sahi Given I am on "http://twig.sensiolabs.org/documentation" When I follow "PDF" Then I am on "http://www.wikipedia.org" Command execution time limit reached: `_sahi._navigateTo("http://www.wikipedia.org", true)` 1 scenario (1 failed) 3 steps (2 passed, 1 failed) 1m7.534s
That doesn't seems to be a problem when using Selenium2
Feature: download a file In order to resolve an issue downloading a file with behat As a developer I need to create a failing test Scenario: Try the download of a pdf with Selenium2 Given I am on "http://twig.sensiolabs.org/documentation" When I follow "PDF" Then I am on "http://www.wikipedia.org" 1 scenario (1 passed) 3 steps (3 passed) 0m9.935s
I've tried with Firefox and Chrome and the behavior is the same in both.
It's probably related to the type of file to download as the problem si also present here
Feature: download a file In order to resolve an issue downloading a file with behat As a developer I need to create a failing test Scenario: Try the download of a file Given I am on "http://pear.behat.org/" When I follow "2.3.5" Then I am on "http://www.wikipedia.org" Command execution time limit reached: `_sahi._navigateTo("http://www.wikipedia.org", true)` 1 scenario (1 failed) 3 steps (2 passed, 1 failed) 1m6.76s
but not here
Feature: download a file In order to resolve an issue downloading a file with behat As a developer I need to create a failing test Scenario: Try the download of a file Given I am on "http://symfony.com/download" When I follow "http://symfony.com/download?v=Symfony_Standard_Vendors_2.2.1.tgz" Then I am on "http://www.wikipedia.org" 1 scenario (1 passed) 3 steps (3 passed) 0m6.988s
Main issue: https://github.com/Behat/Mink/issues/406
I'm experiencing an issue using Mink to control Firefox through Sahi where when I try to interact with the session in any way (e.g. running getPage()->getContent()
or simply wait(2000)
) I don't get the expected response and Mink eventually times out.
I've used the exact same code for various other websites and it works perfectly. This one single website seems to be stopping either Mink or Sahi from providing a response. I can't seem to find any reliable way of debugging the issue, all I can do is wait for the timeout to occur.
The code I'm using to retrieve the markup from a page is as follows:
// Configure driver
$this->driver = new \Behat\Mink\Driver\SahiDriver('firefox',
new \Behat\SahiClient\Client(
new \Behat\SahiClient\Connection(null, CRAWL_SERVER, 9999)
)
);
// Init session:
$this->session = new \Behat\Mink\Session($this->driver);
// Start session:
$this->session->start();
// Open the url
$this->session->visit($config['url']);
// Get the markup from the page
$markup = $this->session->getPage()->getContent();
The page I'm trying to scrape is: https://www.o2.co.uk/shop/phones/
I also have a post up on on Stack Overflow here.
I'm using Mink 1.6 - installed using composer on 27/11/2014
tl;dr Why is Mink/Sahi timing out on this site?
The Sahi download is broken on Travis currently. If anyone has an idea to solve it, please provide a patch
Following tests are failing:
1) Tests\Behat\Mink\Driver\SahiDriverTest::testExecuteScript with data set #1 ('document.querySelector("h1").textContent = "Hello world";')
Behat\SahiClient\Exception\ConnectionException: error:_call(document.querySelector("h1").textContent = "Hello world";)
SyntaxError: missing ) after argument list
Sahi.prototype.ex@http://www.website.tld/_s_/spr/concat.js:3480
@http://www.website.tld/_s_/spr/concat.js:3267
<a href='/_s_/dyn/Log_getBrowserScript?href=null&n=3480'><b>Click for browser script</b></a>
.../vendor/behat/sahi-client/src/Behat/SahiClient/Connection.php:221
.../vendor/behat/sahi-client/src/Behat/SahiClient/Connection.php:255
.../src/Behat/Mink/Driver/SahiDriver.php:616
.../vendor/behat/mink/src/Behat/Mink/Session.php:300
.../vendor/behat/mink/tests/Behat/Mink/Driver/JavascriptDriverTest.php:324
2) Tests\Behat\Mink\Driver\SahiDriverTest::testExecuteScript with data set #3 ('function () {document.querySelector("h1").textContent = "Hello world";}();')
Behat\SahiClient\Exception\ConnectionException: error:_call(function () {document.querySelector("h1").textContent = "Hello world";}();)
SyntaxError: missing ) after argument list
Sahi.prototype.ex@http://www.website.tld/_s_/spr/concat.js:3480
@http://www.website.tld/_s_/spr/concat.js:3267
<a href='/_s_/dyn/Log_getBrowserScript?href=null&n=3480'><b>Click for browser script</b></a>
.../vendor/behat/sahi-client/src/Behat/SahiClient/Connection.php:221
.../vendor/behat/sahi-client/src/Behat/SahiClient/Connection.php:255
.../src/Behat/Mink/Driver/SahiDriver.php:616
.../vendor/behat/mink/src/Behat/Mink/Session.php:300
.../vendor/behat/mink/tests/Behat/Mink/Driver/JavascriptDriverTest.php:324
3) Tests\Behat\Mink\Driver\SahiDriverTest::testExecuteScript with data set #5 ('(function () {document.querySelector("h1").textContent = "Hello world";})();')
Behat\SahiClient\Exception\ConnectionException: error:_call((function () {document.querySelector("h1").textContent = "Hello world";})();)
SyntaxError: missing ) after argument list
Sahi.prototype.ex@http://www.website.tld/_s_/spr/concat.js:3480
@http://www.website.tld/_s_/spr/concat.js:3267
<a href='/_s_/dyn/Log_getBrowserScript?href=null&n=3480'><b>Click for browser script</b></a>
.../vendor/behat/sahi-client/src/Behat/SahiClient/Connection.php:221
.../vendor/behat/sahi-client/src/Behat/SahiClient/Connection.php:255
.../src/Behat/Mink/Driver/SahiDriver.php:616
.../vendor/behat/mink/src/Behat/Mink/Session.php:300
.../vendor/behat/mink/tests/Behat/Mink/Driver/JavascriptDriverTest.php:324
This driver suffers from many cases where it does not behave properly (see failures in the testsuite).
It is also much slower than Selenium2 (see the time spent to run the testsuite), has less features than Selenium2, and is a pain to maintain.
I suggest marking this driver as deprecated (and unmaintained), acknowledging the fact that we haven't managed to fix it since years (the testsuite has never been green since the introduction of the driver testsuite ensuring proper driver behavior). If anyone is using the driver and wants to bring it uptodate, we can still make them a driver maintainer and undeprecate the driver if its testsuite becomes green.
If we do this, we should do a final release of the driver (as we did for SeleniumDriver).
/cc @aik099
Please see https://github.com/Behat/Mink/pull/350 that adds this feature to behat.
If not possible to do with native client we can add it using JS code.
I'm having following test suite failures (some were posted in dedicated tasks):
1) Behat\Mink\Tests\Driver\Custom\ExtraTest::testIssue32
xpath with line ending works
Failed asserting that null is not null.
.../tests/Custom/ExtraTest.php:20
7) Behat\Mink\Tests\Driver\Form\Html5Test::testHtml5FormRadioAttribute
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'invalid'
+'f'
.../vendor/behat/mink/driver-testsuite/tests/Form/Html5Test.php:45
8) Behat\Mink\Tests\Driver\Form\RadioTest::testSameNameInMultipleForms
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'test3'
+'test2'
.../vendor/behat/mink/driver-testsuite/tests/Form/RadioTest.php:69
9 Behat\Mink\Tests\Driver\Form\SelectTest::testSetValueSingleSelect
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'10'
+'20'
.../vendor/behat/mink/driver-testsuite/tests/Form/SelectTest.php:92
10) Behat\Mink\Tests\Driver\Form\SelectTest::testSetValueMultiSelect
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
- 0 => '1'
- 1 => '2'
+ 0 => '2'
+ 1 => '3'
)
.../vendor/behat/mink/driver-testsuite/tests/Form/SelectTest.php:102
Hey I'm using Behat with Mink and Sahi. My Web-Application is running local with apache and XAMPP.
I just tryed to get the hole page with
$driver = new \Behat\Mink\Driver\SahiDriver('firefox',
new \Behat\SahiClient\Client(
new \Behat\SahiClient\Connection(null, 'localhost', 9999)
)
);
$session = new \Behat\Mink\Session($driver);
$session->start();
$session->visit('https://localhost/CMS/index.php/login/login');
echo $session->getPage()->getContent();
and get this error:
Command execution time limit reached: _sahi.setServerVarPlain('___lastValue___527a9575b8270', document.getElementsByTagName("html")[0].innerHTML)
After I deactivated my https connection on my Side i was able to get the page. I think Sahi don't like the Certificate or something like this.
Hope this will help someone and someone cane give me an advice how I'm able to handle a https connection.
What may I help on to get some kind of release out to unblock mink version conflicts? :)
Sahi supports header management through following functions (see http://sahipro.com/docs/sahi-apis/http-header-manipulation-apis.html):
We can use them to implement DriverInterface::setRequestHeader
method.
Hi,
I'm using Mink + Sahi + PhantomJS for scraping purposes.
I have a problem in which sahi takes huge amount of memory and cpu even after the scraping task has been completed. Also, phantomJS processes linger for many many minutes until they exit.
This takes lots of system resources and is not really usable for us as a result.
In our application design many CLI php processes start, each is given a URL to surf to, it surfs to that page, process the page html and extract some information, report it, then finish and the PHP process exits.
I hope this is a good place to check this. Any help will be appreciated!
Current results:
setValue
for input/file: change
fires 0 timessetValue
for textarea: change
fires 0 timesSince selectOption
, check
and uncheck
for Sahi does fire change
event without us doing manual firing, then I guess it's some bug in SahiClient side.
Tests added in Behat/Mink#495
It would be very handy to be able to switch windows like the Selenium 2 driver can. If I get a chance I will work on this, but if someone else can do it that would rock.
Method selectRadioOption
of the driver is escaping given xpath and then giving it to getAttribute
method which does the same.
This bug unnoticed for a long time since it can't be seen when xpath doesn't contain any escapable symbols.
In Behat/Mink#434 we've added extra line endings to make xpaths more readable, which allowed to catch wrong xpath escaping code in this and other drivers.
Recently in Mink a tests, that validate that exception is thrown during attempt to act (e.g. click) on an element, that isn't present on a page throw an exception.
It appears though, that some of them aren't passing currently:
2) Behat\Mink\Tests\Driver\Basic\ErrorHandlingTest::testCheckInvalidElement
Failed asserting that exception of type "Behat\Mink\Exception\DriverException" is thrown.
3) Behat\Mink\Tests\Driver\Basic\ErrorHandlingTest::testUncheckInvalidElement
Failed asserting that exception of type "Behat\Mink\Exception\DriverException" is thrown.
4) Behat\Mink\Tests\Driver\Basic\ErrorHandlingTest::testIsVisibleNotFoundElement
Failed asserting that exception of type "Behat\Mink\Exception\DriverException" is thrown.
5) Behat\Mink\Tests\Driver\Basic\ErrorHandlingTest::testFocusFoundElement
Failed asserting that exception of type "Behat\Mink\Exception\DriverException" is thrown.
6) Behat\Mink\Tests\Driver\Basic\ErrorHandlingTest::testBlurFoundElement
Failed asserting that exception of type "Behat\Mink\Exception\DriverException" is thrown.
Drivers have very basic instructions on how to get use them, but no instructions how to contribute into them. Need to add section on CONTRIBUTING.md with details about:
The test suite is running terribly slow (compared to Selenium2). Maybe we're setting some kind of script running speed and it's stuck in Sahi settings until all tests are done?
While debugging test suite I've noticed that sending 1 command to Sahi (going to /_syn/... url) tooks more then 1 second. It's even worse on Travis. Maybe the problem is really in HTTP connection handling in SahiClient.
Originally created at Behat/Behat#142
Given my behat.yml
:
default:
extensions:
Behat\MinkExtension\Extension:
base_url: 'http://www.google.com'
goutte: ~
selenium2: ~
sahi: ~
javascript_session: sahi
And some lines in my feature context:
<?php
/**
* @Given /^I fill in "([^"]*)" with:$/
*/
public function iFillInWith($field, PyStringNode $value)
{
$field = $this->fixStepArgument($field);
$value = $this->fixStepArgument($value->getRaw());
$this->getSession()->getPage()->fillField($field, $value);
}
/**
* Returns fixed step argument (with \\" replaced back to ").
*
* @param string $argument
*
* @return string
*/
protected function fixStepArgument($argument)
{
return str_replace('\\"', '"', $argument);
}
And my test.feature
:
Feature: Test
Do do do
Do do do
Do do do
@javascript
Scenario: Test with PyString
Given I am on "/"
When I fill in "q" with:
"""
FOOBAR
Bill
"""
I run this and get this error in the output:
php ./bin/behat features/test.feature
Feature: Test
Do do do
Do do do
Do do do
@javascript
Scenario: Test with PyString # features/test.feature:7
Given I am on "/" # FeatureContext::visit()
When I fill in "q" with: # FeatureContext::iFillInWith()
"""
FOOBAR
Bill
"""
error:_setValue(_byXPath("(//html/.//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')][(((./@id = 'q' or ./@name = 'q') or ./@id = //label[contains(normalize-space(string(.)), 'q')]/@for) or ./@placeholder = 'q')] | .//label[contains(normalize-space(string(.)), 'q')]//.//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')])[1]"), "FOOBAR
Bill")
SyntaxError: unterminated string literal
()@http://www.google.com/_s_/spr/concat.js:3016
@http://www.google.com/_s_/spr/concat.js:2822
<a href='/_s_/dyn/Log_getBrowserScript?href=null&n=3016'><b>Click for browser script</b></a>
1 scenario (1 failed)
2 steps (1 passed, 1 failed)
0m14.31s
If I change the PyString input into this:
Feature: Test
Do do do
Do do do
Do do do
@javascript
Scenario: Test with PyString
Given I am on "/"
When I fill in "q" with:
"""
FOOBAR
"""
I get this output:
php ./bin/behat features/test.feature
Feature: Test
Do do do
Do do do
Do do do
@javascript
Scenario: Test with PyString # features/test.feature:7
Given I am on "/" # FeatureContext::visit()
When I fill in "q" with: # FeatureContext::iFillInWith()
"""
FOOBAR
"""
1 scenario (1 passed)
2 steps (2 passed)
0m4.049s
So success. Do you know why?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.