After lots of discussion on Javascript and functional-page testing, it seems like Selenium would be a possible route, and it would fit right into the PIFR framework.

First, a little background on how Selenium works in the PHP world.

  • Selenium is a Java-based full-functional-browser testing framework.
  • Its tests can be written in a number of languages, one of which is PHP.
  • PHP-implemented Selenium tests are executed by the phpunittest-runner framework. If running on the command-line, you'd do something like "phpunit MyTest" to run the tests in the MyTest class, or "phpunit /tests" to run all the tests in the "tests" directory. It's very similar to our own, familiar run-tests.sh. (details on phpunit and selenium).
  • When a Selenium test is run in phpunit, it tells how things are done in the setUp(). $this->selenium = new Testing_Selenium("*iexplore", "http://www.google.com", '192.168.5.109'); would inform the Selenium library to use IE, go to Google.com, and use the Selenium RC server on 192.168.5.109. (which could be a Windows machine).
  • PHPUnit returns success and failure details, as other test-runners, including our own, do.
  • The Selenium project also provides Selenium IDE, a slick little Firefox Add-on that helps automate the generation of (very simple) tests. It's good for the basis of tests, and makes creating tests a bit more accessible to people who wouldn't use it otherwise. But it's really just a starting point.

A new "Selenium" plugin type (or perhaps it should be a phpunit plugin type) could basically imitate what we're doing with Simpletest or Selenium.

  1. It would have its own test type (.phpunit-test?)
  2. When patches are submitted, they get run against the tests that are available for this type, just as we currently run .test files against the simpletest plugin.
  3. An initial implementation would just be a headless Linux box running X that could launch firefox and run it through the tests.
  4. It can return details with a pass/fail just as we currently do.
  5. A Drupal install could be created for each test using the existing code for it to run against.
CommentFileSizeAuthor
#11 selenium.patch7.95 KBAnonymous (not verified)

Comments

damien tournoud’s picture

Subscribe. Setting up a Selenium instance with a headless Firefox (or Chromium, isn't webkit generally more picky about HTML and Javascript correctness?) is not that much a hassle.

The trickiest part, I believe would be to test that PIFR 2.x actually support multiple testing environments. We never actually made that work until now.

marvil07’s picture

subscribing

boombatower’s picture

I see the use of running javascript testing inside headless firefox such as crowbar and/or webkit, but I still don't see the use in the extra complication of selenium.

rfay’s picture

Selenium is a robust way of testing browser/server interaction (like AJAX forms). I've done some work with trying to make jQuery run AJAX forms in a test environment (like the two qunit-like scenarios we started with) and it's pretty questionable. Selenium, on the other hand, is designed for this kind of interaction. It would also make Selenium-IDE (which you've worked with) accessible for use with our test workflow.

I'm not sure what you mean about complexity. It seems to me like setting up a few tests and running phpunit and having it do firefox exercises in a headless linux machine is pretty easy.

boombatower’s picture

Setting up the actual selenium RC plugins and/or grid is no simple matter. I'm sure someone with more experience might be able to do it easier, but I had minimal success after half day of messing with it. I could get the RC setup, but it never worked as it was described...it left all kinds of browser instances open and didn't like the actually be triggered remotely, only worked if I ran command on that machine manually.

rfay’s picture

I spend a bit of time on it and got it going, and I was able to launch remotely as well. I have to admit it took me a fair bit of time to grok it.

And I also have to admit that I don't have any concept of whether it would be reliable, because I don't have enough experience. However, it's basically the leader in the field. And I *think* it would fit right into our model.

Anonymous’s picture

subscribe. very cool. we just had a commit that broke head that we can't test without some js testing.

Anonymous’s picture

ok, got hacky integration working, will post code shortly.

i asked webchick about using code licensed "Apache License, Version 2.0", seems that's a no go, so we'd need to ask for dual-licensing from upstream.

anyone know about the Archive_Tar code in modules/system/system.tar.inc ? its BSD, but we're distributing it...

seutje’s picture

sub

Anonymous’s picture

Project: Project Issue File Review » Drupal core
Version: 6.x-2.x-dev » 7.x-dev
Component: Code » simpletest.module
Assigned: Unassigned »
Status: Active » Needs review

ok, hacky hacky patch attached.

to play along at home, you'll need:

a) the selenium php client driver's 'Testing' folder in your path
b) set the variables in FieldUiJavascriptTest to point at your server and child drupal
c) a working selenium RC install

the HMAC cookie stuff could do with some polish, but i think the idea is sound, once we actually invalidate the HMAC based on a timestamp range...

apart from code, we need to see if we can get the driver licensed as GPL or BSD.

Anonymous’s picture

StatusFileSize
new7.95 KB

with patch this time.

Status: Needs review » Needs work

The last submitted patch, selenium.patch, failed testing.

Anonymous’s picture

talked to rfay in #drupal about this, he asked for a summary of what i was thinking, so here goes:

1. get support for running tests against selenium in D7 core, even if don't have the selenium tests in core. right now that mostly means allowing the db prefix and etc to be changed based on a cookie as well as (or instead of) a UA header. this is a small change, so i'm hopeful i can get that in.

2. integrate selenium tests with simpletest as much as possible. the crappy proof-of-concept code at #11 shows that this is pretty easy. i could be wrong, but this seems like the way to a) allow for minimal changes to the testbot and b) allow for maximum simpletest skill transfer

3. make it easy for devs with a selenium RC install to write tests. i'm thinking it should be as easy as installing a module and setting some config for the selenium host and the dev site host and that's it. this will require packaging some code that can talk to the selenium RC server, either by reusing existing code or implementing it from scratch.

4. see if we can get some best practice going during the D8 cycle, hopefully leading to shipping D8 with js testing in core

kwinters’s picture

I have some concerns regarding the ease of use for test developers, which may just be from my lack of exposure to Selenium.

Basically, no matter how great the testing framework is, if it's hard to run the tests in your development environment then it will have poor adoption. That would be very bad for javascript unit testing, and at that point it might only make sense to use Selenium for what other frameworks can't do and we'd still need #237566: Automated JavaScript unit testing framework, too.

I write code on a Mac, and test it locally using MAMP (fairly common practice). What steps are going to be needed to run Selenium tests in this environment? WAMP may be a bigger issue.

What about people who test their code on a dedicated development server? Or a cheap shared server that doesn't let you install things?

"Use the test bot" isn't a full solution. Uploading to the test bot without being fairly confident it will work is a painful process.

rfay’s picture

@kwinters, I think all of your concerns are valid. The additional one: Selenium-php (or Selenese PHP) is different from Simpletest even though it looks the same, so there's a whole additional knowledgeset. @JustinRandell hopes to overcome this by wrapping up many similar functions, but that doesn't completely make the problem go away.

We've looked at a number of different approaches to this problem, though, and in my mind this is the best of the crowd. We need in-browser testing. I don't think we're going to get it without some configuration and added complexity.

I should mention that many, many developers now do just use the test bot instead of testing locally, because the bot is so much faster. But I, like you, am uncomfortable with that workflow, and it's ugly in the issue queue.

-Randy

kwinters’s picture

I'm not as concerned about coding differences, since that can be mitigated and the people writing tests have control over it. Also, the people affected are mostly just test writers, not as much patch contributors who are getting tested. Getting additional software installed can easily be a pain or effectively impossible.

What are your thoughts re: using Selenium for things that only it can do, and the approach in the other issue for more basic JS unit testing? It could lessen the impact of install issues at the cost of potentially more test system code.

Anonymous’s picture

@kwinters - needing a selenium RC setup is a big barrier, but this is additional to the tests that use DrupalWebTestCase (at least for now). devs that don't want to set this up and write these tests don't have to change a thing. if even 5% of devs write tests that cover in-browser failures via selenium, we've made progress. we've had a few commits recently that just broke HEAD, and we were none the wiser because only a real browser based test would find it.

at least as i see it, for D7 this will be contrib only. hopefully we can get enough experience and success with selenium to push for the tests to live in core for D8, if not, we'll have learned through experience a lot about what a real solution will look like.

rfay’s picture

@kwinters, I am expecting that initially the Selenium approach would be used only where needed, although because of its increased capability it's possible that it could gain favor. As far as the other approaches to JS testing (mostly involving running JS-only tasks in an iframe in the tester's browser), I think they have near-fatal flaws. I spent a lot of time exploring them, and the running-in-an-iframe technique is ugly and fragile. Running in the tester's browser means that we have no way to automate testing, and no control of the browser that's doing it. (Not to say that it wouldn't be an incremental step forward, it's just that a Selenium approach gives us real, automatable functional tests.)

kwinters’s picture

I'm all for an experimental "let's see how far we can reasonably take it" approach. If it works then great, I mostly just wanted to make sure someone was thinking about the barrier to entry.

boombatower’s picture

As I discussed in my blog post I don't think we need a javascript testing framework anywhere near as complex as selenium and I have found the way in which it runs tests to be overly complex. If we go with the other approach using something like qunit it becomes no harder then running current simpletests for developers and pifr simply needs a webkit or crowbar (geiko engine) to run the javascript.

Anonymous’s picture

i'm looking into qunit now. i'm starting from the point of view "can it catch bugs like those introduced by recent commits which broke HEAD". it doesn't matter how simple it is if it can't do that.

for example:

whatever we use has to catch this sort of thing. these bugs are what got me looking into this.

rfay’s picture

qunit is a just a test runner, and it works pretty well. The real issue is whether we can make a test. If we can, we can do lots of things. I'm all in favor of progress on all of this any way we can get it. However, the approach in #775050: JavaScript testing framework #10-15 was possible. It seemed fragile, but I did testing in an iframe to work. Wrapping the test runner around that is, I think, a solvable problem. Doing it in an automated testing environment seems like something else entirely.

tayzlor’s picture

sub

micklweiss’s picture

subscribing

rfay’s picture

Version: 7.x-dev » 8.x-dev
Anonymous’s picture

Assigned: » Unassigned
lomo’s picture

Issue summary: View changes

Just updated the link to the PHPUnit documentation dealing with Selenium/Wedriver technologies.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Status: Needs work » Fixed

With WebDriverTestBase we do have support for this now.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.