behat mink equivalent of dropdown->selectOptionByText()? - behat

I'm working with Selenium and behat mink for the first time. I have the following code:
$category_dropdown = $this->find('xpath', "//select[#name=\"category\"]");
echo $category_dropdown->getHtml();
$category->selectOptionByText('Take Out);
and the output is:
<option value="183">Fast Food</option>
<option value="186">Take Out</option>
PHP Fatal error: Call to undefined method Behat\Mink\Element\NodeElement::selectOptionByText()
The line $category->selectOptionByText('Take Out'); causes errors because the function selectOptionByText doesn't actually exist. Is there another way to achieve the intended behaviour?
I'm so new to all this that I'm still trying to figure out the online documentation for this framework.

You were close...
Try to use
$category->selectOption('Take Out');
Here is the LINK to all the methods from NodeElement class
And by the way there is already Gherkin method which can help you
I select "([^"]|\"*)" from "([^"]|\"*)"
which in your case is
I select "Take Out" from "category"
Here is the LIST of already available Gherkin methods

Related

Using Robot Framework Ldap Library

How far has the Robot framework Ldap library implementation gone ?
Can the keywords be used for execution with pybot ?
Updating the question now.
I came across python-ldap and using that for performing an ldapsearch
def my_search(l, baseDN, searchScope, searchFilter, retrieveAttributes):
logger.console("Reachedhere")
try:
logger.console("Reachedhereinsidetry\n")
ldap_result_id = l.search(baseDN,searchScope,searchFilter,retrieveAttributes)
logger.console("Gotresult\n")
Now I invoked my_search in my Robot testcase. It throws this error
TypeError: an integer is required
Robot Testcase excerpt. :
${SearchReturn} my_search ${ldapObj} "uid=2343,ds=SU,o=DEFAULT,dc=C-N" ldap.SCOPE_ONELEVEL "objectClass=*" None
There is nothing in integer format here. What could be the issue ?
Any leads on this ?
The error you're getting seems to me to be a casting error. I.e. something is fed a string, where an integer is expected. This is an easy situation to come in with the Robot Framework script.
In the Robot Framework general documentation the section about Number Variables shows that you can set a variable to an integer via the ${76}notation. This should happen in the calling keyword or test case.
In case you're unable to do that in the calling keyword, the BuiltIn library has a Convert To Integer keyword which would then do the conversion for you.

How to write a custom Failure message for the Failed Step in Cucumber-java in extentReports

I want to write custom failure message in my Cucumber ExtentReports.
Tool using :
Cucumber
Java
Selenium
JUnit
ExtentReports
What's happening now:
I have a cucumber scenario.
Given something
When I do something
Then this step fails
The failed step Fails with:
Assert.assertTrue("CUSTOM_FAIL_MSG", some_condition);
In the ExtentReport, I see the
What I want to achieve:
What I have researched so far:
There is a scenario.write("") function but this creates a new info log into the report(But I am looking for CustomFailure message rather than a new log entry)
scenario.stepResults has the String which is displayed in the report. However, I could not find a way to set some value in the same.
Any ideas on this?
Have you tried using the create label markup?
Here is how to do it for the FAILED test:
test.log(Status.FAIL, MarkupHelper.createLabel(result.getName()+" Your MSG here!", ExtentColor.RED));
and the PASSED test:
test.log(Status.PASS, MarkupHelper.createLabel(result.getName()+" Test Case PASSED", ExtentColor.GREEN));
You can easily manipulate the string part (var interpolation?) according to your need.
Does this help?
try to replace the JUnit assertion library with the testNG library...also using cucumber you can see the failed step...why do you want to change this "narrative" log?...or if you want a better report try to use a 3rd party library

Running a GEB test using Intellij

Being a beginner in GEB testing, I am trying to run a simple login program in Intellij. Could you please help me run this test in Intellij? My question is what selections should I make in the edit configurations page? Please help. This example is from the book of geb.
import geb.Browser
Browser.drive {
go "http://google.com/ncr"
// make sure we actually got to the page
assert title == "Google"
// enter wikipedia into the search field
$("input", name: "q").value("wikipedia")
// wait for the change to results page to happen
// (google updates the page dynamically without a new request)
waitFor { title.endsWith("Google Search") }
// is the first link to wikipedia?
def firstLink = $("li.g", 0).find("a.l")
assert firstLink.text() == "Wikipedia"
// click the link
firstLink.click()
// wait for Google's javascript to redirect to Wikipedia
waitFor { title == "Wikipedia" }
}
If you are running this in IntelliJ you should be able to run this as a JUnit test (ctrl+F10). Make sure that this is inside of a Class and in a method.
For ease of syntax, it would be good to use Spock as your BDD framework (include the library in your project; if using Maven, follow the guide on the site but update to Spock 0.7-groovy-2.0 and Geb 0.9.0-RC-1 for the latest libraries
If you want to switch from straight JUnit to Spock (keep in mind you should use JUnit as a silent library) then your test case looks like this:
def "show off the awesomeness of google"() {
given:
go "http://google.com/ncr"
expect: "make sure we actually got to the page"
title == "Google"
when: "enter wikipedia into the search field"
$("input", name: "q").value("wikipedia")
then: "wait for the change to results page to happen and (google updates the page dynamically without a new request)"
waitFor { title.endsWith("Google Search") }
// is the first link to wikipedia?
def firstLink = $("li.g", 0).find("a.l")
and:
firstLink.text() == "Wikipedia"
when: "click the link"
firstLink.click()
then: "wait for Google's javascript to redirect to Wikipedia"
waitFor { title == "Wikipedia" }
}
Just remember: Ctrl + F10 (best key shorcut for a test in IntelliJ!)
The above is close but no cigar, so to speak.
If you want to run bulk standard Gebish test from WITHIN Intellij,
I tried 2 things.
I added my geckodriver.exe to the test/resources under my Spock/Geb tests
I literally in the given: part of my Spok/Geb test did the following:
given:
System.setProperty("webdriver.gecko.driver", "C:\\repo\\geb-example-gradle\\src\\test\\resources" + "\\geckodriver.exe");
Failed
Succeeded
Now the usual deal with answers is, that someone writes something, you try it and then it fails.
So, if it did not work for you, use the reference Geb/Spock project on Github as follows and import it into intellij (remember, New Project, then find the gradle.build script and then intellij will import it nicely)...it also kicks off a build so dont freak out:
https://github.com/geb/geb-example-gradle
Download the driver:
https://github.com/mozilla/geckodriver/releases
and move it to the test/resource folder of the reference project you just imported under test/groovy...(see image)
Now add the above given: clause to the GebishOrgSpec Sock/Geb test:
The test runs nicely from WITHIN Intellij. Evidence the browser open and the test running:
LOVELY JOBBLY :=)

Selenium IDE: this.browserbot.getUserWindow().typeList.filter returns error on IE8

I have faced with following trouble during working with Selenium.
I need to verify that some value exists in list and I use the following code:
assertEval
this.browserbot.getUserWindow().typeList.filter(function(v) { return v[0] === 'Type_${r_suffix}'; })[0][0];
Type_${r_suffix}
This works file on Firefox, but on IE 8 returns error: Object doesn't support this property or method.
Could someone have an idea where is a problem?
As the MDN docs say, the filter() method is available only for IE9 and above.
Your're just using a too new technology. Filter it manually using a for loop or insert the code for Array.prototype.filter (from the MDN) to have access to it.

Selenium webdriver: What is the substitute for browserbot?

I'm trying to convert some Selenium HTML tests to use the WebDriver 2.0 framework. According to the web site (http://seleniumhq.org/docs/03_webdriver.html), the WebDriver framework no longer supports the "browserbot" Javascript variable. So my question is, how do I convert a command like
<tr>
<td>verifyEval</td>
<td>this.browserbot.getUserWindow().s.pageName</td>
<td>Config_6_Summary_Confirm_EX</td>
</tr>
using WebDriver? When I run the command
String target = selenium.getEval("this.browserbot.getUserWindow().s.pageName")
commnand, I get an exception stating, "this.browserbot is undefined". Thanks, - Dave
I make a suggestion to following.
String target = selenium.getEval("window.s.pageName")
You can access to 'browserbot' from WebDriver's getEval by "selenium.browserbot".(not "this")
selenium.getEval("typeof(this.browserbot)"); // undefined
selenium.getEval("typeof(selenium.browserbot)"); // object
but, can not use some browserbot function.
(I don't know the deference of 'enabled function' and 'disabled function'. sorry)
"getUserWindow()" is disabled.
You can use a "window" instead of it.