Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a Magento-based application and I'm trying to use PHPUnit with Selenium to test clicking on the links, but I keeps getting an error. I am also using the BrowserStack, which could be causing the issue. Also, if anyone knows how to print out all the html in the terminal that would be great too.

//Use composer to insall phpunit-selenium

require '/home/mark/PhpstormProjects/Project/vendor/autoload.php';
define('BROWSERSTACK_USER', 'USERNAME');
define('BROWSERSTACK_KEY', 'TOKEN');

class WebTest extends PHPUnit_Extensions_Selenium2TestCase
{

    public static $browsers = [
        /* array(
             'browserName' => 'Safari',
             'host' => 'hub.browserstack.com',
             'port' => 80,
             'desiredCapabilities' => array(
                 'version' => '6.1',
                 'browserstack.user' => BROWSERSTACK_USER,
                 'browserstack.key' => BROWSERSTACK_KEY,
                 'os' => 'OS X',
                 'os_version' => 'Mountain Lion'
             )
         ),*/
        [
            'browserName'         => 'chrome',
            'host'                => 'hub.browserstack.com',
            'port'                => 80,
            'desiredCapabilities' => [
                'version'           => '30',
                'browserstack.user' => BROWSERSTACK_USER,
                'browserstack.key'  => BROWSERSTACK_KEY,
                'os'                => 'Windows',
                'os_version'        => '8.1'
            ]
        ]
        /* array(
             'browserName' => 'IE',
             'host' => 'hub.browserstack.com',
             'port' => 80,
             'desiredCapabilities' => array(
                 'version' => '11.0',
                 'browserstack.user' => BROWSERSTACK_USER,
                 'browserstack.key' => BROWSERSTACK_KEY,
                 'os' => 'Windows',
                 'os_version' => '7'
             )
         )*/
    ];

    protected function setUp()
    {
        parent::setUp();
        $this->setBrowserUrl('http://www.example.com/');
    }

    public function testTitle()
    {
        $this->url('http://www.example.com/');
        $this->assertEquals('Example Domain', $this->title());
    }

    public function testGoogle()
    {
        echo $this->getBrowser();

        $this->url('http://www.google.com/');
        $element = $this->byName('q');
        $element->click();
        $this->keys('Browserstack');
        $button = $this->byName('btnG');
        $button->click();
        $this->assertEquals('Browserstack - Google Search', $this->title());
    }

    public function testCheckout()
    {
        echo $this->getBrowser();

        $this->url('http://sitename/checkout/cart/add/uenc/aHR0cDovL3Rlc3QuamV3ZWxzdHJlZXQuY29tL2VhcnJpbmdz/product/1308/');

        $this->url('http://test.sitename.com/checkout/cart/');

        $this->assertEquals('Shopping Cart | sitename.com', $this->title());
        $element = $this->byXPath('/html/body/div[3]/section/div/div/div[1]/div[2]/div[5]/div[2]/button[2]');

        //ive also tried 
        $element = $this->byId('mfi5');
        //this id is generated by the version of magento we are using
        $this->click($element);

        $this->assertEquals('Checkout | sitename.com', $this->title());
    }
}

I get the following error:

WebTest::testCheckout
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: no such element
  (Session info: chrome=30.0.1599.101)
  (Driver info: chromedriver=2.6.232923,platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 29 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
System info: host: '5-255-93-8', ip: '5.255.93.8', os.name: 'windows', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_05'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome={userDataDir=C:\Windows\proxy\scoped_dir3904_2113}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=30.0.1599.101, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: db0a84a0384ebea5dc167bde8cba098f
org.openqa.selenium.NoSuchElementException

after much testing and going through things I have this: this is Not using browser stack,, how easy would it be to use with browser stack also how would i remove the annoying sleep(); lines to something more cleaner

 public function testAddProductToBag()
{

    $this->url('http://test.project.dev/item3');
    //Selects medium from the drop down list
    $ringSizeOption = $this->byCssSelector('#select_4267 > option:nth-child(3)');
    $ringSizeOption->click();

    $addtoBag = $this->byXPath("//*[@title='Add to bag >>']");
    $addtoBag->click();


    sleep(7);

    //$this->timeouts()->implicitWait(7000);
    //Selects the total amount from the div in the top left corner
    $amountDiv = $this->byCssSelector('a.blog:nth-child(2) > label:nth-child(1)');
    $this->assertEquals("£48.60 (1)", $amountDiv->text(), "Error: Nothing in cart");
}
share|improve this question
    
Have you tried doing that locally, not via BrowserStack? –  Ian Bytchek Oct 9 '14 at 18:57
    
I've not done that yet but the reason I'm using it is for the cross browser compatibility. However I will try to just using normal selenium and report back on Monday –  Mark Oct 10 '14 at 21:51

1 Answer 1

Running safari with the $this->keys('random text') doesn't work and this was my issue.

The ability to input a string into an input after selecting the input field seems to cause safari to crash.

So removing the Safari browser and an update to some code solved the issue..

I will now need to look into how to get the $this->keys() working correctly in Safari but reading through several articles I can't imagine I'm going to have much luck.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.