How can i apply or use selenium testing to php sites - php

I mostly buil sites in php/joomla/jquery. Someone told me to learn some unit testing system like selenium.
I want to know that , can i use that for php sites or only java based sites.
When i was learning j2ee then i find many testing systems but i don't know those work with php and joomla

Selenium can be used for PHP sites. Easiest path to getting started is (or was at one time, at least) to download the Seleneium IDE plugin for Firefox and use it to build tests. It can then export your tests as code into a number of different languages.
By the way, I don't consider Selenium a unit test tool. For unit testing in PHP, check out something like PHPunit.

Related

Codeception vs peridot + php-webdriver?

I would like to implement some basic acceptance tests for my company's legacy PHP app. Selenium WebDriver looks like the best fit, but I need advice on what testing framework to use.
Option 1
Our unit tests are written in Peridot PHP, and I know WebDriver can be run from PHP via php-webdriver. So, it looks like I should be able to write a suite of Peridot tests that use the php-webdriver API to interact with the site. It's been done for PHPUnit, and at a glance I don't see why Peridot can't do the same (gulp).
Option 2
Alternatively, I also know the Codeception framework integrates well with WebDriver. The nice thing about this is that Codeception takes care of setting up the WebDriver server and loading a test database. It also allows for a very nice, readable set of English-language tests, although it would mean maintaining two separate testing frameworks.
Considerations
How completely does Codeception cover the WebDriver set of commands? (i.e. can I do anything I might try in the Selenium IDE through Codeception?)
Does Codeception allow me to use the PageObject design pattern?
What kind of learning curve would I be facing without Codeception in terms of setting up my WebDriver server and test database? Does Codeception even make it that much easier?
There are Firefox plugins to convert 'Selenese' (html) test cases into PHPUnit or Codeception format. The PHPUnit test cases would need to be adapted to Peridot, but the Codeception converter is still in alpha and doesn't convert everything. I would rather not use these a great deal, but they would definitely help with the learning curve. How reliable are either one of these?
An official WebDriver plugin is definitely on the way for Peridot, but in the meantime, it's pretty easy to mix in WebDriver support using scopes.
We actually use WebDriver to demonstrate scopes here:
https://github.com/peridot-php/peridot-scope-example

What is the difference between behat, mink and selenium in php

I am new to testing. All i knew was we PHPunit for testing various functions within class and then i know selenium for browser testing.
I know we can write php to link with selenium web driver to do headless testing of browser.
I am not able to get how does behat and mink come in there. Are these seperate from selenium and they are the alternatives of selenium.
Can i do aweb application tetsing without beaht, mink and only with selenium and php
PHPUnit and Behat are similar, both being testing frameworks. They allow you to test your code, by using different approaches:
PHPUnit tests are based on code you write to check how your classes behave under the required circunstances. A lot of people use this type of framework to practice TDD, but you can of course write tests after the code, or for code written a long time ago.
Behat tests are written in a human readable way, and they are supposed to allow everyone involved in the project to read them. This type of testing is called BDD. You can write tests that explain in (nearly) plain english how your system is supposed to behave.
IMO PHPUnit is more general and is the preferred way of writing most tests. I use Behat for testing my systems general behavior, and PHPUnit for unit testing every class and method independently of others.
On the other side, Mink is a library that allows you to browse programatically, using PHP, and access the contents. It can be used to control in a unified way a lot of browsing systems like Selenium, Zombie, etc. each of them based on different technologies.
You can use Mink outside Behat, but they are usually used together because this way you can write tests that show how a website behaves: Given I enter my credentials in the login form, And press the submit button, I should see my profile page...
And yes, you can use PHPUnit and Selenium together as explained in the docs...

Testing PHP project after coding is finished

I've got a PHP project to test. I've already (almost) finished coding the project and I didn't have any testing plan at the start. Being new to PHP, I thought I'd finish the coding and start testing afterwards. As unit testing needs to be done as you go along, what is my other alternative for a test? I want something like a complete system test rather than unit by unit.
I've got around 30 PHP script files, 5 of which are class scripts.
NB It needs to be a formal way of testing, rather than trying to hack it.
I believe your aim behind the test is more "academic" than practical. So testing by friends doesn't really help much. Having said that you have already completed coding the project so if you wanted to unit test using PHPUnit or SimpleTest you will have to go back and start coding the unit test cases.
I think the best option here would be to create a "formal" test document. There are tons of resources out there for how to do this. Basically it will have:
Url
Action
Expected Result
Observed Result
If your expected and observed results match, then that test case is passed.
You can create as many test cases as you want for your project based on these basic guidelines.
Testing has it's different role in SDLC. There are various aspect on which testing could be done. Like:
Smoke Testing
Functionality Testing
System Testing
Retesting
Regration Testing
Preformance Testing
and many more testing technique are there for testing a web application.
Just upload the project and ask someone to test it.You have to test it or get it tested.There is no other way
You can also run a simple scanner(like burp or acunetix) to test whether website can be hacked or not.
You can use a web app scanner,
There are some F/OSS out there such as;
Skipfish - CLI Windows/Linux
Netsparker Community Edition - Windows - Light version of a commercial scanner
List of web app security scanners - commercial and free

PHP Automated Deployment and Testing

I asked a question here on automated deployment of automatically deploying java code.
Our back-end Java API is accessed by a PHP web app. It would be nice to be able to automatically deploy this web app (along with static files like CSS, JS and images) to our web server while performing automatic testing on PHP code. Is there something similar to this for PHP?
I also wonder if as part of this automated testing you can check that each actual page loads without a fatal error. I am sure I read about a google project which allows you to write page tests e.g. click on link a, go to page b etc etc.
Thanks
You may want to look into using Phing for deployment which has features that allow testing with PHPUnit and/or SimpleTest
Maybe this question handling deployment strategies can help you.
Additionally, but maybe gone too far, tools like cruise control may help you to apply continuous integration, too.
PHPUnit with ant was my way to go for automated testing, which could be a vaild option for you, too since you're obviously using some java already :)
Since you're working with Java, you might consider using Hudson (also mentioned in your other question), which has the ability to execute build tasks consisting of several 'steps' One step step could be unit testing your Java App, another unit testing a PHP app, yet another deployinhg Java app, and another deploying a PHP app (and you could add some more ;P )
It has a Maven plugin, so you could actually use your existing Maven scripts.

Cucumber for PHP application

Is it possible to use Cucumber outside Rails? I'd like to start using it for testing some of my PHP applications, but I really don't know how to start.
Probably the easiest way would be creating a Rails project only to run Cucumber features, but that seems like to me as overkill.
What is the simplest way to set up Cucumber for testing a non-Rails application?
Check out:
https://github.com/cucumber/cucumber/wiki/php
It is easy to use cucumber with PHP, even managing the database.
Checkout http://everzet.com/Behat/
(the URL appears to have changed to http://behat.org/)
Cited from the cucumber website:
Cucumber works with Ruby, Java, .NET, Flex or web applications written in any language. It has been translated to over 30 spoken languages.
Here's a great example of how to functionally test a PHP Webapp using Cucumber ... it will show you how to set up your test folder and where to put steps
http://jystewart.net/2008/11/10/testing-php-apps-with-ruby-tools/
Check out what this guy has done with Capybara.
Capbyara is a package that lets you choose your CLI browser driver - basically you can preface tests with #javascript and the Scenario will be played out using Selenium's very powerful chrome ... this allows you to smoothly test javascript where required!!!
http://otaqui.com/blog/1072/testing-remote-php-websites-with-capybara-cucumber-mechanize-selenium-2-webdriver-and-saucelabs/
Further, I've been checking out this link, where the author uses Cuke4PHP to integrate PHPUnit with Cucumber ... this would then let you wrap PHPUnit tests in CucumberSteps ... allowing you to behaviorally test your application and DB using your existing PHP code
http://lucato.it/php-bdd-cucumber-cuke4php
I myself am trying to meld all these pieces together into first a working and then robust test platform for a heavy-duty existing PHP webapp ... but I just began. Will update you if I make a good progress.
You could definitely look at Behat and Mink. Behat is a runner for cucumber's Gherkin syntax (Given, When, Thens) and Mink lets Behat run real browsers. It provides you with a single API across several browser drivers, quite similar to Ruby's Capybara.
While using Cucumber and something like Webrat or Selenium to test a non Ruby application is ok, sticking with PHP if that's what your app is written has manifold benefits - developer skillset and ease of app setup (the kind of stuff you do in Given steps) being the most obvious.
Behat, with Mink, PhantomJS and Sahi extensions, is a great BDD combo for php. If you are coming at it from a QA perspective, anyway.

Categories