Coypu - beginner questions

4,714 views
Skip to first unread message

skip...@gmail.com

unread,
Feb 24, 2013, 2:49:04 AM2/24/13
to co...@googlegroups.com
Hi,
I've just started using Coypu and seems to have very useful features. There are a few things (beginner type questions) if you could help me with?
1. In most of  my testing, I have to check for some text and click a button. But the ID and button text is different/unknown.
    But the button will be in the same <tr> or <div>. How do I find this button? 
    Logically it would seem like, find the first sibling of the text element node that is a button.

2. How can I find links that contains a sub string in its text?
For instance, find the link if the text contains "encyclopedia".
<a href="http://en.wikipedia.org/wiki/Compress"><em>compress</em> - Wikipedia, the free encyclopedia</a>

3. Does Coypu have a wiki?

-Skip

Adrian Longley

unread,
Feb 24, 2013, 3:46:25 AM2/24/13
to co...@googlegroups.com




On 24 Feb 2013, at 07:49, skip...@gmail.com wrote:

Hi,
I've just started using Coypu and seems to have very useful features. There are a few things (beginner type questions) if you could help me with?
1. In most of  my testing, I have to check for some text and click a button. But the ID and button text is different/unknown.

How come? You are heading for a world of pain if you can't determine repeatably what the state of the app you are testing will be. 

    But the button will be in the same <tr> or <div>. How do I find this button? 
    Logically it would seem like, find the first sibling of the text element node that is a button

If you can find the container reliably, e.g. browserSession.FindId("myContainer") then you could just call .FindCss("button").Click() on this.

Or do it all in one FindCss(...).Click()

2. How can I find links that contains a sub string in its text?
For instance, find the link if the text contains "encyclopedia".
<a href="http://en.wikipedia.org/wiki/Compress"><em>compress</em> - Wikipedia, the free encyclopedia</a>

Coypu wont match partial links, I found this too ambiguous personally.

One way to achieve this would be to do a FindAllCss/XPath for links and then filter them yourself. But if you do, coypu won't wait for Ajax so you might need to wrap that call in an assert & retry

browserSession.RetryUntilTimeout(() => { find all, filter and assert here})

I am planning to let all the find methods take a predicate for this reason ... web I get around to it.

3. Does Coypu have a wiki?

Check the readme here:

https://github.com/featurist/coypu
(pull requests welcomed)

And there are quite extensive inline docs you should see in VS intellisense.

-Skip

--
You received this message because you are subscribed to the Google Groups "Coypu" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coypu+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

skip...@gmail.com

unread,
Feb 24, 2013, 12:39:35 PM2/24/13
to co...@googlegroups.com
Re: 1: Its partially because of multiple teams using slightly different words to mean the same thing: "Go", "Continue" .... I just didn't want to come up with an full list because that list is bound to break.  I guess I could fail the test - but resolving it now is more time consuming than its worth.

The FindCss suggestion looks like  it might work for my situation. Will give it try.Thanks. 

Re: 2: Is there a way I can ignore the case of string compare  in FindLink()?

Coypu definitely deserves more web exposure where people can post their methods/examples etc.... That's why the Wiki request. If you decide to go for a website/wiki, let me know if I can help with some time/web space and such.

-S

Denys Stoianov

unread,
May 21, 2013, 5:22:19 AM5/21/13
to co...@googlegroups.com
Hi, how to create pull request?
I tried but not figured out how to do that!


воскресенье, 24 февраля 2013 г., 10:46:25 UTC+2 пользователь Adiel написал:

Adrian Longley

unread,
May 21, 2013, 5:26:36 AM5/21/13
to co...@googlegroups.com
On 21 May 2013, at 10:22, Denys Stoianov wrote:

Hi, how to create pull request?
I tried but not figured out how to do that!

Denys Stoianov

unread,
May 21, 2013, 6:24:28 AM5/21/13
to co...@googlegroups.com

hi, how to select first autosuggest in coypu?
can coypu send keys as it can webdriver?
thanks

Adrian Longley

unread,
May 21, 2013, 7:01:31 AM5/21/13
to co...@googlegroups.com
Yes, you can send keys to an element with the SendKeys() method, for example:

browser.FindCss(".some-element").SendKeys(OpenQA.Selenium.Keys.ArrowDown);

Denys Stoianov

unread,
May 21, 2013, 8:54:54 AM5/21/13
to co...@googlegroups.com
Thanks for answer but my code below does not works,
please give me advice where can be my mistake


driver.FillIn("Selector").With("Ca");

            if (driver.HasContent("Car", new Options { Timeout = TimeSpan.FromSeconds(10) }))
            {
                var e = driver.FindId("Selector");
                e.SendKeys(Keys.ArrowDown);
                e.SendKeys(Keys.Enter);
            }

thanks




вторник, 21 мая 2013 г., 14:01:31 UTC+3 пользователь Adiel написал:

Denys Stoianov

unread,
May 24, 2013, 5:41:55 AM5/24/13
to co...@googlegroups.com

Hi, how to come back to Browser session after this hook?

var selenium= ((OpenQA.Selenium.Remote.RemoteWebDriver) browserSession.Native);
selenium.Manage().Window.Maximize();

and how come back to browserSession?
Or I can use as usual?

browser = browserSession();
browser.Visit("https://gmail.com")

is it correct?

Adrian Longley

unread,
May 24, 2013, 7:47:03 AM5/24/13
to co...@googlegroups.com
Yes, you can just carry on using browserSession.Visit() etc.

Denys Stoianov

unread,
May 31, 2013, 3:31:11 AM5/31/13
to co...@googlegroups.com

Hi,
how to wrap webdriver to coypu  if I start webdriver as usual using API?
here is my example one:
var profile = new FirefoxProfile();
profile.SetPreference("webdriver_assume_untrusted_issuer", false);
driver = new FirefoxDriver(profile);
b = new BrowserSession(driver);

This code is incorrect!

Adrian Longley

unread,
May 31, 2013, 5:34:48 AM5/31/13
to co...@googlegroups.com
Sorry for being unresponsive, have been away on holiday and no one else seems to be wanting to chime in right now.

This is what you need to do.  I will add this to the readme at some point.



[Test]
        public void CustomProfile()
        {
            var configuration = new SessionConfiguration {Driver = typeof (CustomFirefoxProfileSeleniumWebDriver)};

            using (var custom = new BrowserSession(configuration))
            {
                custom.Visit("https://www.relishapp.com/");
                Assert.That(custom.ExecuteScript("return 0;"), Is.EqualTo("0"));
            }
        }

        public class CustomFirefoxProfileSeleniumWebDriver : SeleniumWebDriver
        {
            public CustomFirefoxProfileSeleniumWebDriver(Drivers.Browser browser)
                : base(CustomProfile(), browser)
            {
            }

            private static RemoteWebDriver CustomProfile()
            {
                var yourCustomProfile = new FirefoxProfile();
                return new FirefoxDriver(yourCustomProfile);
            }
        }



Hope you can follow this. I think I will allow a function that returns a Driver instance too as that would be friendlier (like capybara does) when I get round to it.

Cheers
Adrian

This code is incorrect!

Adrian Longley

unread,
May 31, 2013, 5:35:34 AM5/31/13
to co...@googlegroups.com
Please post the HTML too and I will try it out and debug for you next week some time when I'm back.

Cheers


Denys Stoianov

unread,
Jun 18, 2013, 7:08:05 AM6/18/13
to co...@googlegroups.com
Hi, How to use Coypu with Drop Down?

how can I use xpath or css in from field?

browser.Select("part 1").From("//*[@id='ctl00_Form_deptDropDown']");

or can just use ID and NAME?




пятница, 31 мая 2013 г., 12:35:34 UTC+3 пользователь Adiel написал:

Adrian Longley

unread,
Jun 18, 2013, 7:16:15 AM6/18/13
to co...@googlegroups.com
On 18 Jun 2013, at 12:08, Denys Stoianov wrote:

Hi, How to use Coypu with Drop Down?

how can I use xpath or css in from field?

browser.Select("part 1").From("//*[@id='ctl00_Form_deptDropDown']");
You just need:
browser.FindXPath("//*[@id='ctl00_Form_deptDropDown']").Select("part 1");
in that particular case you should just use ID anyway of course, but yes, you can use any Find method and call .Select(...) on the element returned.

Denys Stoianov

unread,
Jun 19, 2013, 12:26:49 PM6/19/13
to co...@googlegroups.com
could you please give some advice or best practices work with table/grid with coypu?
thanks

вторник, 18 июня 2013 г., 14:16:15 UTC+3 пользователь Adiel написал:

Denys Stoianov

unread,
Jun 25, 2013, 12:11:42 PM6/25/13
to co...@googlegroups.com
Hi, I tried to use XPath for DropDown but it does not work, It looks like Coypu skipped row
see my code below:
skipped, does not work at all       

browser.FindXPath("//*[@id='ctl00_PageContent_contactForm_deptDropDown']").Select(department);
 
Work as expected:

browser.Select(department).From("ctl00_PageContent_contactForm_deptDropDown");

How can I use XPath or CSS for select value in DropDown lists?
Thanks

вторник, 18 июня 2013 г., 14:16:15 UTC+3 пользователь Adiel написал:

Adrian Longley

unread,
Jun 25, 2013, 5:57:20 PM6/25/13
to co...@googlegroups.com
Please post the exact HTML you are testing or I cannot try to reproduce this.

Thanks

Denys Stoianov

unread,
Jun 26, 2013, 4:34:56 AM6/26/13
to co...@googlegroups.com
here is mine html code

<select id="ctl00_PageContent_contactForm_deptDropDown" class="body" name="ctl00$PageContent$contactForm$deptDropDown">
<option value="" selected="selected"/>
<option value="value1">value1</option>
<option value="value2">value2</option>
</select>

среда, 26 июня 2013 г., 0:57:20 UTC+3 пользователь Adiel написал:
google-groupe.jpg

Denys Stoianov

unread,
Jul 1, 2013, 6:29:24 AM7/1/13
to co...@googlegroups.com
How to call method FindAllXPath with timeout?
Something like this one.
The code is incorrect.

var pool = browser.FindAllXPath("//*[@id='ui-id-2']//a"new Options { Timeout = TimeSpan.FromSeconds(10) }).ToList();
pool[0].Click();

Thanks


среда, 26 июня 2013 г., 11:34:56 UTC+3 пользователь Denys Stoianov написал:

Adrian Longley

unread,
Jul 1, 2013, 6:45:35 AM7/1/13
to co...@googlegroups.com
On Mon, Jul 1, 2013 at 11:29 AM, Denys Stoianov <denys.s...@gmail.com> wrote:
How to call method FindAllXPath with timeout?
Something like this one.
The code is incorrect.

var pool = browser.FindAllXPath("//*[@id='ui-id-2']//a"new Options { Timeout = TimeSpan.FromSeconds(10) }).ToList();
pool[0].Click();

In this particular case you do not need FindAllXPath, you could just use:

browser.FindXPath("//*[@id='ui-id-2']//a").Click();

which will click the first matching element anyway. And you can always use //*[n] in xpath to choose the element at position n.

If you do need to use an expression you cannot form in xpath then you can pass a predicate as the second argument to FindAllXPath which is a function that takes a list of elements and returns true if it matches your condition. This way Coypu can retry until the list of elements found matches your predicate. e.g:

browser.FindAllXPath("//*[@id='ui-id-2']//a", (elements) => elements.Count() >= 3)[0].Click();

That would retry until at least three links are present before clicking the first one, for example. 

Also if you do need to find things by id Coypu does have a FindId() method, and when you have a more complicated selector these queries are easier to write and understand as CSS than XPath in my opinion, e.g.:

browser.FindCss("#ui-id-2 a").Click();

Denys Stoianov

unread,
Jul 1, 2013, 5:29:01 PM7/1/13
to co...@googlegroups.com
thank you very much
but your implementation does not work at all, did you test it on any HTML?

approach 1

You just need:
browser.FindXPath("//*[@id='ctl00_Form_deptDropDown']").Select("part 1");
in that particular case you should just use ID anyway of course, but yes, you can use any Find method and call .Select(...) on the element returned.
 

approach 2


browser.FindAllXPath("//*[@id='ui-id-2']//a", (elements) => elements.Count() >= 3))[0].Click();

thanks
can you check your approaches?

понедельник, 1 июля 2013 г., 13:45:35 UTC+3 пользователь Adiel написал:

Adrian Longley

unread,
Jul 1, 2013, 6:01:45 PM7/1/13
to co...@googlegroups.com


On 1 Jul 2013, at 22:29, Denys Stoianov <denys.s...@gmail.com> wrote:

thank you very much
but your implementation does not work at all, did you test it on any HTML?

Yes, I have automated tests for all of Coypu against real HTML examples. Not to say there aren't any bugs lurking in cases I haven't thought of, but it does work as I described in general.

approach 1

You just need:
browser.FindXPath("//*[@id='ctl00_Form_deptDropDown']").Select("part 1");
in that particular case you should just use ID anyway of course, but yes, you can use any Find method and call .Select(...) on the element returned.
 
approach 2


browser.FindAllXPath("//*[@id='ui-id-2']//a", (elements) => elements.Count() >= 3))[0].Click();

thanks
can you check your approaches?

Your comments above are too vague, I understand that you haven't got it working but the API is fairly straight forward, it is the specifics of your HTML that will determine what approach will work. If you upload complete HTML + Coypu code somewhere I'll happily run it for you and try to help you debug when I have time, but can't promise a quick reply.

Meanwhile I suggest you try to look deeper into your test failures. Things don't simply "not work", something will happen. Is it failing to find any elements? Clicking the wrong thing? Throwing an unexpected exception? Investigating this more thoroughly might lead you to the solution yourself. Or if there's a Coypu/Selenium problem, lead you to exactly what it is.

Thanks
Adrian

Denys

unread,
Aug 6, 2013, 10:00:00 AM8/6/13
to co...@googlegroups.com
How to check check box using Coypu?

 <div id="My_TypeSelector_Selector" class="My_Selector">
 <input type="checkbox" /> Soccer <br />
 <input type="checkbox"/> Football - Russia<br />
 <input type="checkbox"/> Baseball<br />
<input type="checkbox"/> Football - Germany <br /> 
<input type="checkbox" /> Basketball <br/>
</div>

need to cheek all "Football" check-boxes


воскресенье, 24 февраля 2013 г., 9:49:04 UTC+2 пользователь skip...@gmail.com написал:

Adrian Longley

unread,
Aug 6, 2013, 10:11:52 AM8/6/13
to co...@googlegroups.com, co...@googlegroups.com
The text associated with each checkbox should be contained within a <label> element.

They are associated one of two ways:

1) An attribute on the label: for="idOfCheckbox" matching the id attribute of the checkbox

2) By virtue of the checkbox being contained within the label element. 

Using correct HTML like this also has the benefit that when your users click on "Football - Russia" the checkbox will be checked/unchecked. 

Coypu will understand this and let you do BrowserSession.Click("Football - Russia")

As for checking all checkboxes where the label contains "Football" it would be better for this to be predictable in your test and call the above as many times as you know there are "Football" checkboxes.

You could also use FindAllCss or FindAllXPath to match the text "Football" but I strongly encourage you to follow the above suggestion as your tests will be much more robust.

Adrian

Denys

unread,
Aug 13, 2013, 8:23:24 AM8/13/13
to co...@googlegroups.com
How to perform double-click using coypu?
Or I should dive into the native driver  and then use double click as usual?

вторник, 6 августа 2013 г., 17:11:52 UTC+3 пользователь Adiel написал:

Adrian Longley

unread,
Aug 13, 2013, 10:13:33 AM8/13/13
to co...@googlegroups.com, co...@googlegroups.com


On 13 Aug 2013, at 13:23, Denys <denys.s...@gmail.com> wrote:

How to perform double-click using coypu?
Or I should dive into the native driver  and then use double click as usual?

Yes. It's not in the Coypu API.

Denys

unread,
Aug 13, 2013, 12:06:34 PM8/13/13
to co...@googlegroups.com
How can I dive into the native element IWebElement  from SnapshotElementScope and use it with native driver?
I want to use it in code below:

         var driver = ((OpenQA.Selenium.Remote.RemoteWebDriver)browser.Native);
         Actions action = new Actions(driver);
         action.DoubleClick(IWebElement);
         action.Perform();
Thanks.

Adrian Longley

unread,
Aug 13, 2013, 12:42:21 PM8/13/13
to co...@googlegroups.com




On 13 Aug 2013, at 17:06, Denys <denys.s...@gmail.com> wrote:

How can I dive into the native element IWebElement  from SnapshotElementScope and use it with native driver?
I want to use it in code below:

         var driver = ((OpenQA.Selenium.Remote.RemoteWebDriver)browser.Native);
         Actions action = new Actions(driver);
         action.DoubleClick(IWebElement);
         action.Perform();

It should also have a Native property you can cast to IWebElement, no?
Thanks.

воскресенье, 24 февраля 2013 г., 9:49:04 UTC+2 пользователь skip...@gmail.com написал:
Hi,
I've just started using Coypu and seems to have very useful features. There are a few things (beginner type questions) if you could help me with?
1. In most of  my testing, I have to check for some text and click a button. But the ID and button text is different/unknown.
    But the button will be in the same <tr> or <div>. How do I find this button? 
    Logically it would seem like, find the first sibling of the text element node that is a button.

2. How can I find links that contains a sub string in its text?
For instance, find the link if the text contains "encyclopedia".
<a href="http://en.wikipedia.org/wiki/Compress"><em>compress</em> - Wikipedia, the free encyclopedia</a>

3. Does Coypu have a wiki?

-Skip

Denys

unread,
Aug 14, 2013, 5:04:50 AM8/14/13
to co...@googlegroups.com
I don't known how to cast to Native
I just have situation like this:

var lis = browser.FindAllXPath("//div[@class='select2-result-label']", elements => elements.Count() >= 1).ToList();
  lis[0].Click();lis[0].Click();// Double click does dot work

How to cast to Native from lis[0] and use it in code below
action.DoubleClick(IWebElement);

Thanks


вторник, 13 августа 2013 г., 19:42:21 UTC+3 пользователь Adiel написал:

Adrian Longley

unread,
Aug 14, 2013, 6:11:42 AM8/14/13
to co...@googlegroups.com




On 14 Aug 2013, at 10:04, Denys <denys.s...@gmail.com> wrote:

I don't known how to cast to Native
I just have situation like this:

var lis = browser.FindAllXPath("//div[@class='select2-result-label']", elements => elements.Count() >= 1).ToList();
  lis[0].Click();lis[0].Click();// Double click does dot work

How to cast to Native from lis[0] and use it in code below
action.DoubleClick(IWebElement);
action.DoubleClick((IWebElement) lis[0].Native);

should do it
Reply all
Reply to author
Forward
0 new messages