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:
Static analyzer XPath expressions;
Highlight any selenium locator in the browser by Alt + Enter.
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:
The second part of the question was implemented as follows:
ReSharper plugin raises TcpServer for localhost
Chrome plugin constantly asks him "Is there anything to highlight?"
A list of things to highlight empty until the user presses Alt + Enter and selects the Highlight element.
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.