How to verify text in a css class with Selenium? - css

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.

Related

How to update mark a form dirty after a server side modification

I don't understand how to make the Client ui aware of a server side change in a document.
My use case is the following : I'm adding a button to my form, that calls a custom document method :
In MyDocType.py, I have :
class MyDocType(Document):
#frappe.whitelist()
def change_some_value_in_doc(self):
self.the_field_i_want_to_change = 50
It work in the sense that the_field_i_want_to_change is immediately updated to the new value.
However, If I hit Save, I get the message "No changes in document". I managed to determine that this is because on the JS side, the form is not marked as "dirty", but despite reading the documentation over and over, I cannot find the right way.
I tried with self.notify_update() which seems to have no effect.
Is it a bug ? Or am I misunderstanding how this is supposed to work ?
I'm using frappe v 14.0.0-beta.3
[EDIT]
Actually, I realized that doing
class MyDocType(Document):
#frappe.whitelist()
def change_some_value_in_doc(self):
self.the_field_i_want_to_change = 50
self.save()
Does work in the sense that it save the new value, but it's not exactly what I'm looking for, because my purpose is actually to pre-fill some data with the custom method and leave to the user to complete before saving...
Any help to get me in the right direction would be very appreciated.
To pre-fill data in your form - that you want the user to confirm before saving to the database, you should use client-side scripting (in JS). Changing the value on the server is not going to help you since you want the user to get pre-filled values before inserting a record in the database.

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.

Error while pressing the button " type object "my model" has no attribute "my action" - Odoo 10

I'm working on Odoo 10. When I click on the button, get mentioned error.
I want to convert a contact in partner so I need create a new line in another table with the values I put in the .create(vals).
The following links are some extracts of my code , hope you can help me.
my class : model.py
my view : model_view.xml
my error : server trace back
I don't understand your code at all. You inherit a model called test.res.partner and I don't know if you already created it. That may be the issue.
It could be also the fact that you may no be importing your model.py file if this module inherits another one that you have already created.
In general this message indicates that the method convert_prospect does not exist in the model test.res.partner.
But seeing how you write your view (like using xpath in a view that does not inherit from another one) you should rework your fundamentals.
Ah and don't call that prospect() at the end.

Basic Alexa Skills

I have downloaded the Alexa Skills online tutorial found at:
https://github.com/amzn/alexa-skills-kit-js/blob/master/samples/reindeerGames/src/index.js
and followed (I think) all of the instructions in the tutorial found at:
https://developer.amazon.com/public/community/post/TxDJWS16KUPVKO/New-Alexa-Skills-Kit-Template-Build-a-Trivia-Skill-in-under-an-Hour
This is meant to be a tutorial for first time Alexa Skills developers. My question is, I get this error message once I hit the "Save and Test" button:
errorMessage": "Exception: TypeError: Cannot read property 'application' of undefined"
Does anyone know what the above error means or how to get rid of it?
Thanks v much.
This looks like a javascript error telling you that you are trying to use a property named application on an undefined variable.
JavaScript assigns the value "undefined" to any variable that you use but haven't set yet.
There are a several ways that you can debug problems in your Lambdas. Perhaps the easiest is to review the Logs. To do this:
Go to the Lambda console (where you upload your code to Lambda)
Select the Monitoring tab
Select "View logs in CloudWatch" (in the upper right)
Review the latest log, looking for a reported error in one of your files (typically index.js) and specifically the line number. That should help you find the error.
Note that the time stamps will be GMT, so probably won't match your actual time. This can be confusing if you have multiple entries. But the minutes should match, helping you verify that you're looking at the correct log entry.
A more advanced, and quicker way to debug Lambda problems, is the include a "test" request, and run this each time you upload code to Lambda.
To set this up:
Run one of your defined utterances in the ASK test page under the "Service Simulator" section.
Copy the code displayed below that in the "Lambda Request" section.
Now switch to the Lambda console for your Lambda function
Click the down arrow in the Actions button and select "Configure test event"
Paste the request you copied above into the text field
Click Save and Test.
Now each time you upload new code to Lambda, you can select "Test" and the request that you just saved will be run.
And best of all, the console log will be displayed in the lower right corner, saving you from having to switch to the logs and refresh to view them.

assertTextPresent equivalent in 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');

Resources