1

I was going through a tutorial, on PHPUNIT i got the tutorial quit well...and do some logins on my own..

But i went into the web to load a page and submit a value on a real-time page

it works fine... but the issue i have is that after entering the user key ..it submit but it wont wait for the next page

I see similar questions here but none is working-out for me

Pls Can anyone help me.

This is my code

<?php
class TestLogin extends PHPUnit_Extensions_Selenium2TestCase {
public function setUp()
{
    $this->setHost('localhost');
    $this->setPort(4444);
    $this->setBrowser('firefox');
    $this->setBrowserUrl('http://localhost/tutor');
}

public function setSpeed($timeInMilliSec)
{
    $this->setSpeed('120');
}
 /*Function to locate website*/
public function testHasLoginForm()
{
    $this->url('http://www.jamb.org.ng/DirectEntry/');/*This is the site*/
    $username = $this->byId('ctl00_ContentPlaceHolder1_RegNumber');/*Search for a name*/
            ##ctl00_ContentPlaceHolder1_txtRegNumber
    $action = $this->byId('ctl00_ContentPlaceHolder1_Reprint')->attribute('action');
    $this->byId('ctl00_ContentPlaceHolder1_RegNumber')->value('49130518ED');/*value of the textbox*/
    $jump = $this->byId('ctl00_ContentPlaceHolder1_Reprint');
    $jump->submit();
}

}
?>
sectus
  • 15,605
  • 5
  • 55
  • 97
pumamammal
  • 61
  • 1
  • 9

3 Answers3

1

You could use

 $this->timeouts()->implicitWait(10000);//10 seconds

to set timeout of searching elements on page.

https://github.com/sebastianbergmann/phpunit-selenium/blob/master/PHPUnit/Extensions/Selenium2TestCase/Session/Timeouts.php

sectus
  • 15,605
  • 5
  • 55
  • 97
  • @user3803698 , yes, i did. – sectus Jul 28 '14 at 03:19
  • @user3803698 , `OK (1 test, 0 assertions)` without modifications – sectus Jul 28 '14 at 07:27
  • pls am quit knw to selenium, phpunit, pear n d rest but hv been working hard on the tutorials....if i build up a page....i login in that page quit alright from my local host....but this time u wanna automate a website... i've been trying hard to get someone to ask questions. dont knw if we could hookup... this is my skype pumamammal – pumamammal Jul 28 '14 at 07:41
  • @user3803698 , what are you trying to achieve? – sectus Jul 28 '14 at 08:09
  • I want to login into http://www.jamb.org.ng/DirectEntry/ with the value 49130518ED and get to this link http://www.jamb.org.ng/DirectEntry/PrintSlip.aspx and download the picture which is in http://www.jamb.org.ng/DirectEntry/ImagePage.aspx thats all – pumamammal Jul 28 '14 at 08:18
  • @user3803698 , is it an test case, or you just want to download file? – sectus Jul 28 '14 at 08:19
  • yeah....but it has to setup cookies, so that /imagePage.aspx can see the image. i have couple of values which it will take me much super more time to finish manually. THIS IS another value 49003257DE – pumamammal Jul 28 '14 at 08:29
  • @user3803698 , use curl to download file. It could use cookies. – sectus Jul 28 '14 at 08:39
  • i wouldn't have use selenium if cookies were easy to create. the cookies value were encrypted. making it hard to create...on just have to automate something through front-end. thats why i need to login d value in the Re-Print Slip Column and use image_save_from_url function to get image....thats what i tot either...do u have any better way of doing this...pls advice me. This is the Process. The Reg. No are to be entered in the Re-Print Slip Space to login then the download – pumamammal Jul 28 '14 at 08:41
  • @user3803698 , with curl you do not need to encrypt or create cookie. Just find tutorial about "login with curl". – sectus Jul 28 '14 at 08:58
  • Ask questions, use chat. – sectus Jul 28 '14 at 09:35
  • I tried implicitWait method but it seams that it don't work. Any suggestions? I've added my anser with try catch block in a loop which is perfect for many tasks. – Arek Kostrzeba Jan 04 '18 at 14:09
0

Resolved.i just changed

 $jump->submit();

to

$this->byName('ctl00$ContentPlaceHolder1$Reprint')->click();
Quamber Ali
  • 2,170
  • 25
  • 46
pumamammal
  • 61
  • 1
  • 9
  • am just stocked by this... i want to download this whole of this page after the login. i get this Print Popout thing. i just want to save the jamb.org.ng/DirectEntry/ImagePage.aspx into my computer after the login and teardown() do u have any way i could do that?? – pumamammal Jul 29 '14 at 21:42
0

If you want to wait for diffrent elements or even capabilities i suggest use this pattern This is example wait for element. I recommend using byCssSelector here to get more flexibility.

You can easily use this pattern for example to wait for element to be clickable:

protected function waitForClickable($element, $wait=30) {
    for ($i=0; $i <= $wait; $i++) {
        try{
            $element->click();
            return true;
        }
        catch (Exception $e) {
            sleep(1);
        }
    }
    return false;
}

You can even use it in any context passing anonymous function as parameter:

protected function waitForAny($function, $args, $wait=30) {
    for ($i=0; $i <= $wait; $i++) {
        try{
            call_user_func_array($function, $args);
            return true;
        }
        catch (Exception $e) {
            sleep(1);
        }
    }
    return false;
}

Usage:

$f = function($e){
    $e->click();
};
$this->waitForAny($f, array($element));
Shihas
  • 814
  • 15
  • 44
Arek Kostrzeba
  • 551
  • 1
  • 7
  • 21