Last active
April 18, 2019 16:58
-
-
Save teksrc/5265bfc923f5cfe504d39555950a9023 to your computer and use it in GitHub Desktop.
TamperMonkey Dom Highlighter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name ShowDS Component | |
| // @match https://qa.dialsource.com/* | |
| // @match http://localhost:3000/* | |
| // ==/UserScript== | |
| // Using TamperMonkey, this custom DOM Highlighter script inserts CSS into whatever page is loaded. | |
| // Then all attributes with an sqa-ID are rendered with an outline style. | |
| // It shows what elements have the ID and what ones still need it. | |
| // And on mouse over I can just read the ID. I don't have to search for it on Dev tools | |
| // By writing Selenium using sqa-ID instead of XPath, the DOM elements can get moved around and the test will still work. | |
| (function() { | |
| 'use strict'; | |
| function addGlobalStyle(css) { | |
| var head, style; | |
| head = document.getElementsByTagName('head')[0]; | |
| if (!head) { return; } | |
| style = document.createElement('style'); | |
| style.type = 'text/css'; | |
| style.innerHTML = css; | |
| head.appendChild(style); | |
| } | |
| console.log('dstm Start'); | |
| addGlobalStyle('*[data-sqa-component-name] { outline:1px dashed orange !important;border:1px dashed orange !important; } '+ | |
| '*[data-sqa-component-name]:hover::after {all:initial;position:fixed; right:0px; clear:both; display:block;background-color:black; z-index:1000; -webkit-user-select: all; content:attr(data-sqa-component-name); color:orange; '+ | |
| ' font-family: monospace; transition: all .05s ease-in-out; }'); | |
| // I have to scale these to defeat the 'minimum text font' bugs that chrome currently has. | |
| addGlobalStyle('*[data-sqa-id] { outline:1px dashed green !important; } '+ | |
| '*[data-sqa-id]:hover::after {all:initial;position:relative; right:0px; clear:both; '+ | |
| 'display:block;background-color:black; z-index:1000; -webkit-user-select: all; content:attr(data-sqa-id); color:green; '+ | |
| 'font-family: monospace; transition: all .05s ease-in-out; }'); | |
| addGlobalStyle('*[dataSqaId] { outline:1px dashed green !important; } '+ | |
| '*[dataSqaId]:hover::after {all:initial;position:relative; right:0px; clear:both; '+ | |
| 'display:block;background-color:black; z-index:1000; -webkit-user-select: all; content:attr(data-sqa-id); color:green; '+ | |
| 'font-family: monospace; transition: all .05s ease-in-out; }'); | |
| // I have to scale these to defeat the 'minimum text font' bugs that chrome currently has. | |
| addGlobalStyle('[class*="SQA"] { outline:1px dashed green !important; } '+ | |
| '[class*="SQA"]:hover::after {all:initial;position:relative; right:0px; clear:both; '+ | |
| 'display:block;background-color:black; z-index:1000; -webkit-user-select: all; content:attr("search class attribute"); color:green; '+ | |
| 'font-family: monospace; transition: all .05s ease-in-out; }'); | |
| console.log('dstm End'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment