I am creating a Python script with Selenium. I want to run a specific test that checks the default text of a textbox when the page loads up. Below is my code.......
try:
self.assertEqual("Search by template name or category..", sel.get_text("//table[#id='pluginToolbarButton_forms']/tbody/tr[2]/td[2]/em"))
logging.info(' PASS: text box text is correct')
except Exception:
logging.exception(' FAIL: text box text is incorrect')
Here is my error......
self.assertEqual("Search by template name or category..", sel.get_text("//table[#id='pluginToolbarButton_forms']/tbody/tr[2]/td[2]/em"))
File "C:\Python27\lib\unittest\case.py", line 509, in assertEqual
assertion_func(first, second, msg=msg)
File "C:\Python27\lib\unittest\case.py", line 502, in _baseAssertEqual
raise self.failureException(msg)
AssertionError: 'Search by template name or category..' != u'Submitter Requests'
Am I using the wrong function?
Your AssertionError states that the assertion you tried (that's the self.assertEqual(...) in your first code example) failed:
AssertionError: 'Search by template name or category..' != u'Submitter Requests'
This assertion explains that the string 'Search by template name or category' is different from 'Submitter Requests', which is correct ... the strings are, in fact, different.
I would check your second parameter to self.assertEqual and make sure that you're selecting the right feature.
This looks like you are using the right function, but perhaps you are not running your tests in the correct fashion.
The problem seems to be that you are not selecting the right element to compare with. You are basically telling the program to match that "Search by template name or category.." is equal to the contents of whatever is in:
//table[#id='pluginToolbarButton_forms']/tbody/tr[2]/td[2]/em
Apparently, the contents are "Submitter Requests", i.e not what you would expect, so the test fails (as it should). You might not be selecting the right element with that XPath query. Maybe a CSS query would be best. You can read about element selectors in the Selenium documentation.
Keep an eye open for a pitfall as well: the text returned by Selenium is a Unicode object, and you are comparing it against a string. This might not work as expected on special characters.
Related
I want to setup QMessageBox text format, but I can't find a valid method.
QtGui.QMessageBox.information(
self,
"Confirm delete!",
"Are you sure you want to delete file?\n %s" % filename,
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
QtGui.QMessageBox.No
)
I want to make bold,like:
"Are you sure you want to delete file?\n <b>%s</b>"
How can I do this?
According to PySide's documentation you can use the setTextFormat to specify the Qt.RichText format.
However this will only work when you create a custom QMessageBox instance and then set it up, it will not work when using the QMessageBox.information static-method.
By default QMessageBox uses the Qt.AutoText format which tries to detect whether the text is rich text by using the Qt.mightBeRichText function (I could only find Qt's documentation). The documentation of that function states:
Returns true if the string text is likely to be rich text; otherwise
returns false.
This function uses a fast and therefore simple heuristic. It mainly
checks whether there is something that looks like a tag before the
first line break. Although the result may be correct for common cases,
there is no guarantee.
Unfortunately in your message you have a line break \n before any tag, and hence the function fails to detect your message as rich text.
In any case once you interpret the text as rich text you have to use the HTML line break <br> so using the message:
"Are you sure you want to delete file?<br> <b>%s</b>"
will make the QMessageBox auto-detect the rich text and produce the result you want.
I have a list of first name and last that is supposed to be used to compose website links. But sometimes some users don't always follow the naming rule and finally, their website name doesn't match correctly with the expected one.
Here is an example: lest's say the name is John and last name is Paul. In this case, the website URL should be johnpaul.com. But sometimes, use put johnpaul.com or pauljohn.com, or john-paul.com.
I would like to automatize some processes on these websites. The vast majority of them are correct, but some not. When it is not correct, I just google the expected URL and it is generally the first or second result I get on google.
I was asking myself if it is possible to make a Google request and check the 2 or 3 first links with python to get the actual URL. Any idea on how to make something like this?
my code now looks like this:
for value in arr:
try:
print requests.get(url).status_code, url
except Exception as e:
print url, " is not available"
I'd go with endswith()
string = "bla.com"
strfilter = ('.com', '.de') # Tuple
if string.endswith(strfilter):
raise "400 Bad Request"
this way you filter out the .com .net etc errors.
I've noticed a weird parsing problem with ravendb's python client.
when i use this query
query_result = list(session.query().where_equals("url",url).select("Id","htmlCode","url"))
knowing that url = "http://www.mywebsite.net/"
The relevent part of the error stack is the following :
File "/usr/local/lib/python3.5/dist-packages/pyravendb/store/session_query.py", line 71, in __iter__
return self._execute_query().__iter__()
File "/usr/local/lib/python3.5/dist-packages/pyravendb/store/session_query.py", line 307, in _execute_query
includes=self.includes)
File "/usr/local/lib/python3.5/dist-packages/pyravendb/d_commands/database_commands.py", line 286, in query
raise exceptions.ErrorResponseException(response["Error"][:100])
pyravendb.custom_exceptions.exceptions.ErrorResponseException: Lucene.Net.QueryParsers.ParseException: Could not parse: 'url:http://www.mywebsite.net/' --->
BUT if I simply add a simple ' ' to the url parameter in the query, it works without any parsing error (but dosent returns a result though since syntax isnt the same).
I would like to contribute to the pyravendb on github but I'm not sure where it's parsing the parameters, it's probably calling lucene for that.
Any idea why a simple space can prevent proper parsing ?
The query you send to lucene is this url:http://www.mywebsite.net/
lucene key will be the url and the value suppose to be http://www.mywebsite.net/
because you have : in http://www.mywebsite.net/ the lucene parser get "confused" and raise a parsing error.(split key,value special character is :)
To fix your problem you need to escape the : in your url parameter and then give it to the query so your url parameter should look like this:
http\://www.mywebsite.net/
For your question why simple space can prevent proper parsing is because space in lucene indicates about another parameter to look for. (you can see what query we build when you using the where_in method)
This issue will be fixed in the next version of pyravendb (current version is 1.3.1.1)
I'm using web driver to automate a test case. I'm trying to verify the text present in the page or not. I'm doing the following, but I don't know how to verify the textPresent is what I'm actually looking for.
textPresent = driver.find_element_by_xpath ("//span/p")
then when I did textPresent.text it's giving the text "An error occured processing Order" where I'm actually looking for "Successfuly added to processing" in the same xpath location. So in this situation, I want to fail the test case. How do i do that?
We should include a check point to verify the equality of actual text with expected :
expectedText = "Successfuly added to processing";
textPresent = driver.find_element_by_xpath ("//span/p");
if textPresent != expectedText
<Write fail condition here e.g. return "Fail" or raise Exception("Fail")>
I'm using the Django template system in a standalone tool (not in a web app), like so:
from django import template
try:
tmpl = loader.get_template(my_template_path)
context = template.Context(my_template_context)
txt = tmpl.render(context)
except (template.TemplateSyntaxError, template.TemplateDoesNotExist), e:
# ...
When a template contains an error, an exception is thrown. How do I get the filename, line number, and line position of the error? Should I expect to get this information from the exception in this case (not rendering a response for a browser)?
I notice that TemplateSyntaxError has a source attribute whose value is a tuple containing a LoaderOrigin and a pair of numbers. The LoaderOrigin has a name equal to the filename. The numbers do not appear to resemble the character positions of the error, but maybe there's another way to interpret them?
TemplateDoesNotExist does not appear to have a source, only args and message, which provide the name of the template that could not be found. Is there a way to locate the template tag doing the loading, or does this error happen at a later phase when line numbers are no longer available?
I do have django.settings in effect, and TEMPLATE_DEBUG is set to True, if that matters. (I believe this is needed to get line numbers reported when rendering templates into webpages, with the fancy error display.) I am also using a trivial template loader, set via TEMPLATE_LOADERS, though I don't think that should matter. Also, I'm stuck with Django 1.3 at the moment, so a 1.3-compatible solution would be preferred.
Thanks!
I believe that source attribute of the TemplateSyntaxError is what you are looking for. Django code implies that the mentioned numbers are line numbers between which an error occured, see https://github.com/django/django/blob/1.3.7/django/views/debug.py#L153.
As for TemplateDoesNotExist, it seems to be ignored, when it occurs as a result of the template tag, see https://github.com/django/django/blob/1.3.7/django/template/loader.py#L50.