Does XPATH in python Twisted support this syntax: "/message/body[.='test']"? - twisted

I'm working on a XMPP testing tool, use Twisted xpath to match XMPP message.
Suppose I have a message stanza like:
<message to='xxx' type='chat'><body>test</body></message>
If I want to match that the message's body text value is "test", then for standard xpath syntax, it will be:
"/message/body[.='test']"
But this syntax is not supported in twisted.
My question is: Is there anyway to resolve this issue? Or it is just impossible?
Thanks in advance.

The xpath support provided by Twisted Words for XMPP interactions is very limited. It is far from a full xpath implementation. So, for any particular questions about whether some xpath feature is supported by it or not, the answer is quite possibly that it is not supported.
Ideally, Twisted Words wouldn't need an xpath implementation at all. It could be built on top of one of the other xpath implementations available to Python (eg, the one exposed by lxml). However, no one has yet done the work to determine how to actually achieve this (considering Twisted Words also uses a custom DOM implementation for XMPP as well).
Until that task is undertaken, you can get some idea of what parts of xpath are supported by looking at the grammar at the end of twisted/words/xish/xpathparser.g.
As far as I know, no one has invented a way to combine the Twisted Words DOM with another xpath library, so you're just stuck with the missing features (if you know of such an invention, or invent such a thing yourself, let us know! It might make the above mentioned task easier :).

Related

What is the equivalent of karate.get() in Java?

I have created a Java object in karate scripts using Java interop and have used it as required.
Now, I want to retrieve that same instance in another Java class. Is there a way to do that?
In karate, we have an equivalent method like karate.get('objectName'). Is there any equivalent API available in Karate lib?
Please assume that the answer is no. I'd like to mention that the whole point of creating Karate was to avoid using Java for API test automation. I say this because I suspect based on your questions that you have made the same mistake I've seen a few other teams make - which is attempting to make Karate work like the Seleniums and Rest Assureds of the world. That always ends badly. And what's worse is that these teams blame Karate for that and go around telling everyone. I'd rather have that not happen - so if this is a "blocker" please consider using some other tool.
If you are already calling Java, you have plenty of ways to pass objects around right? Just use that and don't over-complicate your tests. Or you can use the "singleton" pattern, nothing to do with Karate, you can look it up.

Focus language grammar

I need to extract some info from a list of mainframe scripts written in focus language.
I'm trying to write a java program for parsing source code. Due to the name of the language it is difficult to find any useful information on the internet. Maybe someone know if exist a grammar for this language on internet(for example for antlr4) or maybe an implemented lexer.
Thanks in advance for any response!
Follow this link to the Focus Developer Manuals, then click on the left side to open the list of manuals available.
Note: The link to "FOCUS Developer Manuals" at the bottom of the the WikiPedia page was http://... instead of https://..., and resulted in a connection refused error. I have corrected the Wiki page.
There is a curated list of ANTLR grammars here. Unfortunately, there is no grammar for the focus product.
Not all authors make their grammars available at the above link, you might try searching github and other code repositories.

Karate Java API for Match methods

Background:
I noticed this interesting post on Twitter about a Java API for Karate: https://twitter.com/ptrthomas/status/1344290316212342784
I don't have a twitter account so unable to reply - hope you don't mind me asking here instead.
I have used Karate (with the parallel runner, feature files and all) in one work project and it is a joy to use - and a few folks in the workplace are very impressed with the complex JSON assertion. We are achieving a level of JSON response field coverage for that project that is not possible with other frameworks (IMO).
I've now been tasked with improving an older test project which uses JUnit + RESTAssured, but has quite limited field assertions. I am unable to fully convert it to raw Karate (too many tests, not enough time), but I'm keen to explore the possibility of supplementing what is there already with the Karate Java API mentioned in above twitter post.
For example - for an existing test which gets a Response using RESTAssured, it would be nice for me to somehow use the 'contains' method (or any of the methods in Match class) in Karate to assert that response, as it is the best JSON assertion tool I have come across.
Questions:
Off the bat - is this a practice you would recommend for my use case? Let me know if you think this is an anti-pattern. I ask this because the example here (https://github.com/ptrthomas/karate-showcase) is not using RESTAssured to get the response and my use case is a bit different.
If its worth exploring - I assume this stuff will be available in v1.0.0? (I see public methods such as that are on the develop branch, but couldn't see it on the v1.0.0 github thread).
but I'm keen to explore the possibility of supplementing what is there already with the Karate Java API mentioned in above twitter post.
That's very interesting and you have got me also thinking about this potentially interesting way to introduce Karate to legacy projects. I do get this question on how to magically migrate existing RA tests a lot.
I would recommend it. You can expect a 0.9.9.RC3 next week that should have all the assertions you want. And the API has been simplified so you don't need to call isTrue() etc.
We plan to have better examples (maybe you can help) but for now, use this as a starting point (look at the last test / very end of the file): MatchTest.java
If you want to get started now (which I recommend and you can provide more feedback) do take a look at the developer guide: https://github.com/intuit/karate/wiki/Developer-Guide

Do Karate UI support Angular UI based application testing

If karate supports Angular testing, can i have some example so that i can look into it.
Have been going through locators given at https://intuit.github.io/karate/karate-core/#locators but unable to get exact information on how to proceed.
There is no need, Karate works with plain HTML.
And if you need to do some specifc JS helpers (which is all that frameworks that claim to support Angular do), just use the tips here and make re-usable functions: https://stackoverflow.com/a/60800181/143475
If you still have a question, ask a new question and provide a sample (can be online, see examples in link above) for us to understand and discuss.

Easy selenium selecting?

Does anyone have any resources on usage of selenium selectors (specifically javascript)
Ideally there'd be a chrome plugin that allows you to inspect an element and gives you the (all) method(s) of selecting it.
The IDE for firefox looks nice: http://docs.seleniumhq.org/projects/ide/
Just wondering if there are's anyway to simplify this annoying task.
You can (but highly discouraged) use Firebug + Firepath to generate CSS selectors/XPaths.
For complex web applications, there is no way you can get maintainable locators from those generators.
Auto-generated selectors are purely rubbish in terms of maintenance. Machines can't determine what is the most efficient way to locate, unless developers construct some certain algorithms depending on the structure of DOM. But I believe that is much hard than learning XPath or CSS selector.
My suggestion would be every Selenium developers should learn XPath and CSS selectors properly. Firebug + Firepath would be a good tool to evaluate and validate the locators, but please compose them from scratch.
For example, this is what a basic XPath generator would give you:
.//*[#id='page']/div/div/div/div/div/div/div/div/ul[1]/li[1]/a
This is what a "smart" generator might do (which simplifies XPath by certain pre-defined rules, but may still cause trouble):
.//*[#id='page']//a
But this what a experienced human developer would do:
.//*[#id='page']//div[starts-with(#class, 'header-')]//a[contains(#class, '/blog')]