Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to write test cases for hidden and read only elements in selenium 2 module #504

Closed
aditya- opened this issue Aug 24, 2013 · 18 comments

Comments

Projects
None yet
5 participants
@aditya-
Copy link
Contributor

commented Aug 24, 2013

Dear sir ,

I am writing acceptance tests using codeception with selenium 2 . I am almost able to write test cases all the types ... except readonly , and hiddent elements .. actually its very important from .. here i am facing mainly two issue .. please help ...

1.Unable to write test cases for elements declared as read only

see the following code .. actually i need to fill that field .. due to read only its not filled .. i need to alter this in code ..

2.Some elemnts by default hiddent ... on place of mouse (hover) those are visible like delete buttons .. etc .. after placing mouse only they are visible ..

.hidden {
display: none;
visibility: hidden;
}

.onhover > ul {
display: none;
}

Please suggest me how to write test cases for this read only and hidden elements .. Actually its very important for me

@DavertMik and @tiger-seo @Ragazzo please help

@DavertMik

This comment has been minimized.

Copy link
Member

commented Aug 24, 2013

Yes, Selenium2 works only with visible elements.
Probably you should use moveMouseOver method to reveal that elements: http://codeception.com/docs/modules/Selenium2#moveMouseOver

@aditya-

This comment has been minimized.

Copy link
Contributor Author

commented Aug 24, 2013

is there anyway to access readonly elements ... because we are using datepicker many times .. by default many are in readonly to avoid invalid format .. i need to fill that filed by making writeable .. how to do that ... and how to use execute in selenium scenario ... give me an live example @DavertMik .. plz

@aditya-

This comment has been minimized.

Copy link
Contributor Author

commented Aug 25, 2013

@DavertMik @Ragazzo .. any please answer

@wyhmichael

This comment has been minimized.

Copy link
Contributor

commented Aug 25, 2013

I think you can simulate click of a real user to set a date, or run
JavaScript to choose a date, instead of trying to fill the read-only field,
in my opinion, in this case, the datepicker field is readonly and not
fillable is also a valid test case that you might not want to break.

On Sat, Aug 24, 2013 at 11:16 PM, AARYAN ADITYA notifications@github.comwrote:

@DavertMik https://github.com/DavertMik @Ragazzohttps://github.com/Ragazzo.. any please answer


Reply to this email directly or view it on GitHubhttps://github.com//issues/504#issuecomment-23222637
.

Best Regards,

Yinghui (Michael) Wang

@DavertMik

This comment has been minimized.

Copy link
Member

commented Aug 25, 2013

Yes, you can use Javascript to make this field not readonly.
With executeScript action and proper jQuery code that changes attribute it should not be that hard.

@aditya-

This comment has been minimized.

Copy link
Contributor Author

commented Aug 28, 2013

moveMouseOver not working .. its dargging the page ..

and

mainly i have one main issue ..

i have some search fields in my application .. where i can type some data in that filed and press enter ..
is there any way to press enter button after filling a field ..

@aditya-

This comment has been minimized.

Copy link
Contributor Author

commented Aug 28, 2013

@DavertMik @wyhmichael please answer

@wyhmichael

This comment has been minimized.

Copy link
Contributor

commented Aug 28, 2013

@aditya-

  • moveMouseOver

I did a quick test on moveMouseOver, and didn't get the issue you mentioned, can you share how you used the function?

the following is the code I used for test, codeception version is v1.6.5

acceptance.suite.yml

class_name: WebGuy
modules:
    enabled:
        - Selenium2
        - WebHelper
    config:
        Selenium2:
            url: 'http://www.google.ca/'
            browser: firefox
            delay: 500
<?php
use \WebGuy;

class Mouse_And_Enter_Cest
{

  /**
   * Test Case: test move mouse over
   *
   * @param WebGuy   $I        WebGuy object
   * @param Scenario $scenario Scenario object
   *
   * @group moveMouseOver
   *
   * @return null
   */
  public function testMoveMouseOver(WebGuy $I, $scenario) 
  {
    $I->amOnPage("/");
    $I->moveMouseOver('//input[@id="gbqfq"]');
    $I->moveMouseOver('//input[@id="gbqfq"]');
    $I->moveMouseOver('//input[@id="gbqfq"]');
    $I->moveMouseOver('//input[@id="gbqfq"]');
    $I->moveMouseOver('//input[@id="gbqfq"]');
    $I->moveMouseOver('//input[@id="gbqfq"]');
    $I->moveMouseOver('//input[@id="gbqfq"]');
  }

  /**
   * Test Case: press button
   *
   * @param WebGuy   $I        WebGuy object
   * @param Scenario $scenario Scenario object
   *
   * @group pressButton
   *
   * @return null
   */
  public function testPressButton(WebGuy $I, $scenario) 
  {
    $I->amOnPage("/");
    $I->fillField("//input[@id='gbqfq']", "codeception");
    $I->pressKey("//input[@id='gbqfq']", "enter");
    $I->see("codeception");
  }
}
@aditya-

This comment has been minimized.

Copy link
Contributor Author

commented Aug 28, 2013

@wyhmichael .. Really thanks for helping .. Thanks for your contribution .. i will try once again ..

but another main issue i am facing every where .. like

i have some search fields in my application .. where i can type some data in that filed if press enter .... requested data will be shown

i have many fields like this is there any way to press enter button after filling a field ..

@wyhmichael .. Please suggest

thanq

@wyhmichael

This comment has been minimized.

Copy link
Contributor

commented Aug 28, 2013

@aditya-

my code above has an example (testPressButton) showing how to press enter button for an element, does that work for you?

@aditya-

This comment has been minimized.

Copy link
Contributor Author

commented Aug 29, 2013

@wyhmichael that code was given by @wyhmichael .. no need to check back ... its working great .. Thank you .. thanks for example .. but still searching to make elemnt visble in selenium .. becuase i have lot features that are viable after placing mouse on it .. like delete button ..etc .. i am trying .. even moveMouseOver not working for this type of features .. instead of mouse over its scrolling the page for my web app .. any other suggestions to fix ..

@wyhmichael

This comment has been minimized.

Copy link
Contributor

commented Aug 29, 2013

@aditya- not sure how your html page works, it would be better if you can provide an example page, which may help us go deeper on your case.

@aditya-

This comment has been minimized.

Copy link
Contributor Author

commented Aug 30, 2013

@wyhmichael .. Its soemthing like .. this : http://usman.it/themes/charisma/gallery.html

after placing mouse on image .. edit + cross button will come like this .. please suggest .. how to fix

@wyhmichael

This comment has been minimized.

Copy link
Contributor

commented Aug 30, 2013

@aditya-

right, your app is using a lot of JQuery, which could be tricky testing with selenium

in this case, moveMouseOver works to enable control div, but it's not allowed to use 'click' from selenium2 module directly here

like @DavertMik said, we can adopt some js code as a workaround, here's my test using FF23.01 with selenium2 module on MacOSX, it works for me, you can give it a try.

<?php

use \WebGuy;


class JQuery_Hover_Cest extends SNS_Base_Cest
{

  /**
   * Test Case: test hover performed by jquery using selenium
   *
   * @param WebGuy   $I        WebGuy object
   * @param Scenario $scenario Scenario object
   *
   * @group jquery-hover
   *
   * @return null
   */
  public function testHover(WebGuy $I, $scenario) 
  {
    $I->amOnPage("themes/charisma/gallery.html");

    // hover the first colorbox on the page, trigger edit/delete div
    $I->moveMouseOver('//a[@class="cboxElement"][@title="Sample Image 1"]');

    // run script after div shows

    // edit
    $script = 'return document.getElementsByClassName("gallery-delete btn")[0].click()';
    $I->executeJs($script);

    // delete
    $script = 'return document.getElementsByClassName("gallery-delete btn")[0].click()';
    $I->executeJs($script);
  }
}
@aditya-

This comment has been minimized.

Copy link
Contributor Author

commented Sep 2, 2013

Thanks allot @wyhmichael .. i will try this today on my application .. Really thanks for your contribution ...

@aditya-

This comment has been minimized.

Copy link
Contributor Author

commented Sep 6, 2013

@wyhmichael ..
I tried your method in many ways .. Thanks for your quick response and work .. but it was failing ...
Please check the issue #537 i have mentioned the exact issue very clearly .. Please suggest your opinion

@kjnanda

This comment has been minimized.

Copy link

commented Apr 27, 2017

codeception moveMouseOver function is not working in firefox but the same works fine in chrome browser. Do anyone have any idea? Or is there any workaround possible?

Firefox version - 52
Selenium version - 3+

The same thing will work fine if I degrade the selenium version.
Firefox version - 47
Selenium - 2.53.1

@Naktibalda

This comment has been minimized.

Copy link
Member

commented Apr 27, 2017

@kjnanda Please upgrade to the latest versions of Firefox, Selenium and Geckodriver.
Marionette implemented action commands just a month or so ago. (I still don't get a relationship between Marionette and Geckodriver).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.