assertTextPresent equivalent in phpunit - phpunit

I'm trying to test for the presence of a string somewhere in a long webpage. Using PHPUnit's assertRegExp if the string is not found it prints out the entire page and then finishes with matches PCRE pattern "/xxxxxx/". According to the documentation I should be able to specify a message a third that will be printed out if the test fails. That message is printed, followed by the full page source. What I'd like to do is just print the message. Using Selenium in my previous apps I used assertTextPresent and it would just print out confirmation that the text was/was not found, without filling my screen.
I have tried wrapping the assertRegExp in a try-catch but it didn't change anything.

You could try assertContains() instead of assertRegexp().
PHPUnit is responsible for printing out the failed text, and this differs from one assert method to another. It just might work.
If it does not, open an issue at PHPUnit's issue tracker about PHPUnit printing too much out.

I am using the getBodyText() method to get all page content and than I use assertTextPresent() to check the presence of pattern.
$this->assertTextPresent($this->getBodyText(), 'text to find');
The solution has been positivly tested with latest phpunit 4.7.

I use assertTrue(stripos($haystack, $needle) !== false, 'Failed assertion message');

Related

How to locate the method using an error message string?

I would like to know where is this error code located in the AOT. Would like to know the path to understand the structure and develop custom code.
Transaction has been selected, for settlement, although settlement type: none was selected
I generally use one of two methods to locate message strings.
Provided the cross reference is updated (it should be in dev) use the "Label editor" to to search for then string, see this answer.
Put a breakpoint in top of info.add method, disable CIL if needed, then rerun to get the error message invoking the debugger, see this answer.

Programmatically add key mappings in Atom

I'm creating several commands programmatically and want to avoid having to add key mappings for them explicitly in keymap.cson.
The Flight Manual page for Keymap Manager shows an add method. It doesn't give an example of how to actually use this method, so my guess is that this should work:
atom.keymaps.add('atom-text-editor',{'alt-1':'custom:my-command'});
However, this does not appear to work. When I run this in the developer console, I get this message:
Encountered an invalid key binding when adding key bindings from 'atom-text-editor' 'custom:my-command'.
I got this message even if I changed alt to ctrl.
What does the correct method call on atom.keymaps look like.
I agree, the docs are not detailed enough. However, through trial and error, I managed to figure it out:
atom.keymaps.add('foo', {
'atom-text-editor' : {
'alt-1': 'custom:my-command',
'#': 'application:about'
// etc
}
});
Explanation:
atom.keymaps.add(source, bindings, priority);
The source argument is not the same as what is referred to as the selector in Atom speak. Instead, it's an identifier that can be used to remove the keybindings, should you wish to (except it seems they haven't actually implemented a remove method!).
Instead, the selector should go inside the bindings argument, as shown above.

Ruby/Selenium/Watir-Webdriver: "path is not absolute" error for absolute path

document_name ='TestDoc'
document_path = ("/Users/Me/QA/Project/Documents/#{document_name}")
File.new ("/Users/Me/QA/Project/Documents/#{document_name}") # => File is created
filename_field.send_keys("#{document_path}")
filename_field.send_keys :tab # => To Trigger event but where error occurs
filename_field = browser.file_field(:name, 'file') declared in a module elsewhere.
As far as I can tell, I have provided an absolute path for the filename to upload the file but when the tab key is sent, an error occurs of:
Selenium::WebDriver::Error::UnknownError: unknown error: path is not absolute:
With an odd squiggly symbol in RubyMine that I've never seen before. Any ideas?
Update:
I added
puts filename_field.value
# => C:\fakepath\TestDoc
Spoke to one of the developers and she said "Browser does it to fake things out, so the filesystem isn't exposed". Not sure if that helps solve my issue or I'm SOL?
That error comes from Chromedriver, and comes from sending an incorrect path string to a file element. Since :tab is not a path, it is correctly raising an error.
You shouldn't need to send a tab; just sending the path of the file should accomplish what you need.
I see many small strange things in your code.
Why
document_path = ("/Users/Me/QA/Project/Documents/#{document_name}")
Not
document_path = "/Users/Me/QA/Project/Documents/#{document_name}"
Why
filename_field.send_keys("#{document_path}")
Not
filename_field.send_keys(document_path)
But the main question is why you are using send_keys instead of set?
I failed to reproduce your problem. Maybe it will be possible if you will provide your html. But i suggest you to try:
filename_field.set(document_path)
Because you can easily check it even with irb send_keys is acting differently in firefox and in chrome for example. So maybe problem with it.
Another suggestion
That is a much more weak idea. But...
Try to clear value before changing it. You can do it with javascript:
b.execute_script("arguments[0].value=''", field)
I had the same issue with Chromedriver 2.26.436421 and it was solved when I removed the code which was sending the tab key.
With previous Chromedriver sending tab key was required to trigger the change event on the file input but with latest one it seems like it is only causing issues and the change event gets triggered without it.

Error messages: result.rejectvalue 3rd argument

in the following code what is the point of the third argument to rejectValue ?
errors.rejectValue("descriptions", "second_lang_desc_required", new String[] { secondLang.getCode() }, null );
I have this in the message value : Description in second language of application required {0} but this is exactly waht I see in the JSP, no replacement
According to Spring doc the purpose of the third argument is to provide a string array of arguments for replacing vars in messages.
In other words and telling from your code example its exactly what you expected it to be.
I guess you already checked if secondLang.getCode() is different from null. If so please have a look at whether or not you are using the latest release of org.springframework.
It is working in 4.2.4 but I remember having had to use a workaround before switching to 4.2.4 (Yes, of course - a clever guy would check change history and would 'know' instead of assuming, but I never claimed to be one, did I?)

How to verify text in a css class with Selenium?

I am using Selenium to automate app creation test. The test includes filling out fields on a web page and clicking a submit button. Once that is done, a new page loads with an alert stating success or failure. The problem for me is, the alert is coded in a css class as follows:
<div class="alert-box notice">
Successfully created application
×
</div>
All I need to do is verify the text "Successfully created application" exists. I do not need to manipulate anything.
I'm not sure what language you are doing, but basically, you need to get the text in the containing div.
So, for example,
driver.findElement(By.cssSelector(".alert-box.notice")).getText()
After some discussion with my peers and much online research, here is the solution I found.
At first I tried capturing the text based on Nathan's suggestion, but decided to store the results as a string.
String happy = driver.findElement(By.className("alert-box notice")).getText();
assertEquals(true, happy.contains("Successfully"));
The problem with this is that I kept getting errors such as, "org.openqa.selenium.InvalidSelectorException: The given selector alert-box notice is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: Compound class names not permitted"
Since I have no control over the class name, I went the xpath route as follows:
String happy = driver.findElement(By.xpath("html/body/div/div[2]/div/div/div/div[3]/div")).getText();
assertEquals(true, happy.contains("Successfully"));
This version runs correctly and I am able to verify the alert message.

Resources