Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch phpunit-selenium2 tests in Chrome and IE

I am created test using this tutorial http://net.tutsplus.com/tutorials/php/how-to-use-selenium-2-with-phpunit/. And all work fine, but I can launch this test only on Firefox. I read a lot of articles about this in internet, but I don't find any solution. I have Windows XP, PHP 5.4.7, PHPUnit 3.7.13 by Sebastian Bergmann. Before running test I launched selenium-server-standalone-2.28.0.jar. There is my test

<?php
class Example extends PHPUnit_Extensions_Selenium2TestCase
{   protected function setUp()
    {   
    $this->setBrowser("firefox");
        $this->setBrowserUrl('http://test.com/');
    }

    public function testogin()
    {
        $this->url('http://test.com/');
        $this->timeouts()->implicitWait(10000);
        $username = $this->byId('user_login');
        $username->value('test.ru');
        $password = $this->byId('user_pass');
        $password->value('test');
        $this->byId('login_btn')->click();
    }
}
?>

Please, help me run this test on other browsers. If you need more information, ask me. Thanks

like image 817
oleg_star Avatar asked Feb 08 '13 08:02

oleg_star


People also ask

How can we run same test cases on multiple browser at same time?

Create an XML which will help us in parameterizing the browser name and don't forget to mention parallel="tests" in order to execute in all the browsers simultaneously. Execute the script by performing right-click on the XML file and select 'Run As' >> 'TestNG' Suite as shown below.

Can we do Cross browser Testing in Selenium WebDriver?

With the increasing demand for automation testing, Selenium is one such tool which perfectly fits for Cross Browser Testing of a website. It is very necessary to check the compatibility and performance of the websites on different browsers and operating systems.

How to select elements by class name in selenium with PHPUnit?

PHPunit’s Selenium extension provides a really nice API for that. You can select elements by class name, tag, name, ID, CSS selector, XPath, etc. The method will return a PHPUnit_Extensions_Selenium2TestCase_Element instance which you can use to select other child elements, attributes, etc.

How do I enable the Chrome browser in selenium?

To enable the Chrome browser, you need to download the chromeDriver and specify the path as an option when launching the Selenium server. Is the Document Ready? If your page content is loaded via AJAX, and you don’t want to trigger the tests directly on page load, you’ll want to wait until your page is loaded and your elements are present.

How to launch Facebook Home Page in Chrome browser using selenium?

Here is the code to launch the facebook home page in Chrome browser and print the page title in the output console. To launch the chrome browser you, you need to download the chromeDriver executable file which will link your tests in Selenium and the Chrome browser.

How many devices and browsers can Selenium tests run on?

Give your users a seamless experience by testing on 3000+ real devices and browsers. Don't compromise with emulators and simulators Home Guide How to run Selenium tests on IE using IE Driver?


2 Answers

For Chrome:

  • Glance through the docs
  • Download the ChromeDrive
  • Start Selenium with extra argument: java -jar selenium-server-standalone-<version>.jar -Dwebdriver.chrome.driver=/path/to/chromedriver.exe
  • Now do $this->setBrowser('chrome'); in your setUp()-method

I have not tried the IE Driver yet, so I cannot do more for you then point to the docs.

Lastly, try and run your tests on all these browsers, you can give an array with all browsers: https://phpunit.de/manual/4.8/en/selenium.html Again, I haven't tried this one myself yet, so I cannot be more specific then those docs.

Hopefully I have given you enough pointers now... :)

like image 75
qrazi Avatar answered Oct 11 '22 07:10

qrazi


For IE:

  • Download the InternetExplorerDriver
  • Start Selenium with extra argument:

    java -jar selenium-server-standalone-.jar -Dwebdriver.chrome.driver=/path/to/chromedriver.exe -Dwebdriver.ie.driver=/path/to/IEDriverServer.exe

  • Now do $this->setBrowser('iexplore'); in your setUp()-method

like image 28
TOS Avatar answered Oct 11 '22 09:10

TOS