Modelizer / Laravel-Selenium

Selenium Testing for Laravel 5
MIT License
108 stars 33 forks source link

Speed up timeout process if no element found. #26

Closed splatEric closed 7 years ago

splatEric commented 7 years ago

Hi,

Loving the idea behind this, and have been using the package extensively on my current project. However, I have a problem with the findElement method. When I provide a field identifier as a name, it first goes through finding by id, xpath etc. Selenium seems to take about 10 seconds to timeout on failing to find with these criteria, which makes the tests very slow.

So, is there some configuration I am missing that can force selenium to fail faster, or should I create new methods by which I can specify that label I am providing is the name attribute, and so that will be the first approach taken to retrieve the element.

I am sure there's something obvious I am missing, but I have trawled the internet and selenium forums, and just don't seem to have any luck getting consistent behaviour on this front.

Modelizer commented 7 years ago

Thanks! I think you should give it a try

should I create new methods by which I can specify that label I am providing is the name attribute, and so that will be the first approach taken to retrieve the element.

Ideally, It should not take so much time.

splatEric commented 7 years ago

Okay, are there any conventions I should adhere to for the interface? We could either do:

typeByName($text, $name) typeById($text, $id) typeByCss($text, $css)

Etc

Or

type($text, $value, $selector_type)

And if $selector_type is null it could behave as normal and simply use findElement

If we do this approach, it would follow that other methods for setting values should support a similar convention ...

On 9 Dec 2016, at 20:43, Shaikh Mohammed Mudasir notifications@github.com wrote:

Thanks! I think you should give it a try

should I create new methods by which I can specify that label I am providing is the name attribute, and so that will be the first approach taken to retrieve the element.

Ideally, It should not take so much time.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Modelizer/Selenium/issues/26#issuecomment-266118091, or mute the thread https://github.com/notifications/unsubscribe-auth/ACVP6CuNQ3VC6WEeMpeUHAQHVKb3YmAlks5rGb1TgaJpZM4LIwvI .

Modelizer commented 7 years ago

I guess it's been already done. Please check https://github.com/Modelizer/Selenium/blob/master/src/Services/InteractWithPage.php#L212-L222

My point it how can we speed up the timeout process?

splatEric commented 7 years ago

Yeah trouble with that is there's no way of controlling the order in which those are called.

I did play with the wait for stuff on Friday, but didn't have a huge amount of luck before I ran out of time to carry on with it.

My proposal is more about direct control of the test route, whereas addressing the underlying issue around timeout for the selenium request seems trickier ...

On 10 Dec 2016, at 21:43, Shaikh Mohammed Mudasir notifications@github.com wrote:

I guess it's been already done. Please check https://github.com/Modelizer/Selenium/blob/master/src/Services/InteractWithPage.php#L212-L222

My point it how can we speed up the timeout process?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Modelizer/Selenium/issues/26#issuecomment-266242129, or mute the thread https://github.com/notifications/unsubscribe-auth/ACVP6HH89t0jwZFCTL0ui0FceLLjb4zhks5rGx0UgaJpZM4LIwvI .

Modelizer commented 7 years ago

Can you give me a sample of this?

My proposal is more about direct control of the test route

splatEric commented 7 years ago

If I have an html form element such as:

<input type="text" name="foo" />

In my test I have the following:

$this->type('bar', 'foo');

Under the hood, the type method will call findElement. As you pointed out, this will then go through the various by[kind] methods to find the element to add 'bar' to. But the problem I am having is that each call to selenium byId is taking 10 seconds to timeout, slowing the tests considerably:

15:29:05.833 INFO - Executing: [find element: By.id: left_dist_axis])
15:29:16.203 WARN - Exception thrown
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"left_dist_axis"}
  (Session info: chrome=54.0.2840.98)
  (Driver info: chromedriver=2.24.417412 (ac882d3ce7c0d99292439bf3405780058fcca0a6),platform=Mac OS X 10.12.1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 14 milliseconds

(this is from the selenium logs of an actual test I'm running)

Possibly I am just missing some configuration so that the ById method can timeout in more timely manner, but in the meantime I was thinking that given I know that I am providing a name attribute to dig out the input field, it would be useful if I could specify that either in the call to the type method, or by having specific type[kind] methods to handle this:

In my test: $this->typeByName('bar', 'foo')

In InteractWithPage:


function typeByName($value, $name, $clear = false) 
{
        $element = $this->findElementByName($name);

        if ($clear) {
            $element->clear();
        }

        $element->value($value);

        return $this;
}

function findElementByName($name)
{
    try {
        return $this->byName($value);
    } catch (\Exception $e) {
        throw new CannotFindElement('Cannot find element by name: '.$name.' isn\'t visible on the page');
    }
}
Modelizer commented 7 years ago

Yeah! that would be great. Please send a PR with a test case. Thanks :+1:

splatEric commented 7 years ago

okay, it might not happen for a little while, I've just looked at my schedule for the next week or so and it's looking a bit on the busy side, but this is now on the todo list ;-)

marktopper commented 7 years ago

Any updates on this?

splatEric commented 7 years ago

Apologies, got sidetracked by Christmas and other bits of work. And then of course they announced Laravel Dusk, which might make some of this rather redundant.

But I will hopefully have some time over the next few days to come back to this.

Modelizer commented 7 years ago

Laravel Dusk will have a new sets of API and Taylor has extract older one to browser kit I will decide road map for this package once Laravel Dusk is release.

Reason to keep maintaining this package is there will be small amount of people who want to use Selenium due to some scenario.

marktopper commented 7 years ago

I get it 👍