📜 ⬆️ ⬇️

Find.By - finding & verifying locators

I’ll start this article by working with QA Automationg and the fact that I like to automate all routine actions. So recently, for me, writing, editing and checking locators for elements on the page has become such.

Usually this process looks like this: I write an xpath expression in chrome or firepath, then I copy it and add an attribute to an element in C # code. But locators often need to be fixed or just to check which element it points to. And even this simple change of the predicate as [@ id = 'myId'] to [contains (@id = 'Id')] ends with the test crashing at runtime because I wrote '=' instead of ',' and was too lazy to check the changes. In general, too many actions with copying, pasting, switching between windows and the like for such a simple task. I decided to write a plugin for ReSharper, which by Alt + Enter would highlight my element in the browser.

Formulation of the problem


Write plug-ins for ReSharper and Chrome, which together would solve two simple tasks:

Decision


With the first task, everything turned out to be quite simple. I decided not to write my parser and validator for xpath, but just used the XmlDocument class from the .NET library:

XmlDocument document = new XmlDocument(); var navigator = document.CreateNavigator(); try { navigator.Compile("xpath expression"); //   ,    } catch (XPathException exception) { //   } 

The second part of the question was implemented as follows:

To search for items in dom using XPath, I use the jquery.xpath.js library.
')
Since I have never written plugins for chrome before, sending requests from the https site to http localhost turned out to be the most difficult for me. Google Chrome blocks all such requests from the web page. It took me no time to search for a solution, but it turned out to be very simple and, probably, even logical: http requests can be made from background.js, and then transferred to the page, which I did.

Work plug in action




Links


We write the simplest plugin for ReSharper - an article that helped start writing for ReSharper
Find.By chrome - plugin for Google Chrome
Find.By resharper - plugin for ReSharper
Find.By - github project repository

Source: https://habr.com/ru/post/306930/


All Articles