Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Added a catching of the SahiClient exception to wrap it in DriverException #42

Merged
merged 2 commits into from
May 3, 2014

Conversation

stof
Copy link
Member

@stof stof commented May 3, 2014

Refs https://github.com/Behat/Mink/issues/473

The error message are not detailed because Sahi does not let SahiClient handle element not founds in a nice way (findByXPath only gives you an accessor for the element, it does not perform any JS action to check whether this XPath matches)

@@ -268,7 +277,11 @@ public function getText($xpath)
*/
public function getHtml($xpath)
{
return $this->client->findByXPath($xpath)->getHTML();
try {
return $this->client->findByXPath($xpath)->getHTML();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just wrap $this->client->findByXPath($xpath) call into helper method that will to try/catch as with other drivers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->client->findByXPath($xpath) does not call Sahi yet. It gives you an accessor object, which will be represented as _sahi._byXPath($xpath) when performing operations on it. This is precisely why building a good error handling is a pain (we would have to build more complex JS code in SahiClient by embedding error handling in the JS we send)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But SahiClient is already giving an exception back. And it's not SahiClient business to return DriverException instead. Let's keep the proposed (in this PR) code then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. SahiClient gives you an exception back in getHTML because of the JS exception when accessing .innerHTML on undefined when running _sahi._byXPath($xpath).innerHTML. There is no exception in $this->client->findByXPath($xpath), which just instantiate a ByXPathAccessor object and returns it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we somehow invert the process to make error handling easier without a full SahiClient API rewrite?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So by placing try/catch around $this->client->findByXPath($xpath)->getHTML(); we ensure that we catch exception for 2 cases:

  1. the element can't be found
  2. unable to get HTML of element

I wonder if handle both cases also in Selenium2Driver, where we only try-catch around the filterByXpath.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, being unable to get the html of an existing element would mean that something is broken in you Selenium stack IMO. Catching such case is not really necessary.

I would prefer giving a finer error handling for Sahi, but this is not possible unfortunately (this try/catch currently even catches cases where Sahi is down for instance, because there is no finer checks)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, being unable to get the html of an existing element would mean that something is broken in you Selenium stack IMO. Catching such case is not really necessary.

That maybe was a bad example. But if you attempt to check the DIV element, then the DriverException should be raised in every driver.

I would prefer giving a finer error handling for Sahi, but this is not possible unfortunately (this try/catch currently even catches cases where Sahi is down for instance, because there is no finer checks)

Then let's keep current checks and then (in other PR) introduce more fine grained exception in SahiClient.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if you attempt to check the DIV element, then the DriverException should be raised in every driver.

Indeed. And it is one of the remaining test failures. But the fix is different so I will do it in a separate PR for readability (this PR is changing most methods to catch the exception, so changing some logic in them would be hard to review)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@stof
Copy link
Member Author

stof commented May 3, 2014

@aik099 Are you OK for merging this as it fixes lots of tests for the driver ? I'm afraid we won't be able to provide nicer error messages here.

Once done, I will try to look at the remaining testsuite failures

@aik099
Copy link
Member

aik099 commented May 3, 2014

Sure. Go ahead and merge.

stof added a commit that referenced this pull request May 3, 2014
Added a catching of the SahiClient exception to wrap it in DriverException
@stof stof merged commit 8bb291b into minkphp:master May 3, 2014
@stof stof deleted the error_handling branch May 3, 2014 09:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants