Last active
March 29, 2025 13:33
-
-
Save diegomarino/8f887028ac35fafc1d10b253bbc246b1 to your computer and use it in GitHub Desktop.
bugbug.io check element values
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
| async function(element, selector, variables) { | |
| /** | |
| * π USAGE EXAMPLES (can be commented out): | |
| * | |
| * await checkColor(element, "rgb(0, 128, 128)"); | |
| * await checkFontWeight(element, "600"); | |
| * await checkVisibility(element); | |
| * await checkFontSize(element, "16px"); | |
| * await checkTextContent(element, "Trello Clone"); | |
| */ | |
| console.log("π Selector received:", selector); | |
| console.log("π¦ Variables received:", variables); | |
| console.log("π Element received:", element); | |
| const computedStyle = window.getComputedStyle(element); | |
| console.log("π§ͺ Full computed style:", computedStyle); | |
| // Example: check color using a variable or fallback | |
| const expectedColor = variables.expectedColor || "rgb(0, 128, 128)"; | |
| await checkColor(element, expectedColor); | |
| // Add more checks as needed | |
| // await checkFontWeight(element, "600"); | |
| // await checkVisibility(element); | |
| return true; // If all checks pass | |
| /** | |
| * π£ checkColor: Checks if the computed text color matches the expected one. | |
| */ | |
| async function checkColor(el, expectedColor) { | |
| console.log("π£ [checkColor] Running color check..."); | |
| const color = getComputedStyle(el).color; | |
| console.log("π¨ [checkColor] Computed color:", color); | |
| console.log("β [checkColor] Expected color:", expectedColor); | |
| if (color === expectedColor) { | |
| console.log("π’ [checkColor] Color matches."); | |
| } else { | |
| throw new Error(`π΄ [checkColor] Color mismatch. Expected: ${expectedColor}, got: ${color}`); | |
| } | |
| } | |
| /** | |
| * π£ checkFontWeight: Checks if the font weight matches the expected value. | |
| */ | |
| async function checkFontWeight(el, expectedWeight) { | |
| console.log("π£ [checkFontWeight] Running font-weight check..."); | |
| const weight = getComputedStyle(el).fontWeight; | |
| console.log("π€ [checkFontWeight] Computed font-weight:", weight); | |
| console.log("β [checkFontWeight] Expected font-weight:", expectedWeight); | |
| if (weight === expectedWeight) { | |
| console.log("π’ [checkFontWeight] Font-weight matches."); | |
| } else { | |
| throw new Error(`π΄ [checkFontWeight] Font-weight mismatch. Expected: ${expectedWeight}, got: ${weight}`); | |
| } | |
| } | |
| /** | |
| * π£ checkVisibility: Checks if the element is visible (not hidden or display:none). | |
| */ | |
| async function checkVisibility(el) { | |
| console.log("π£ [checkVisibility] Running visibility check..."); | |
| const style = getComputedStyle(el); | |
| const visible = style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0"; | |
| console.log("ποΈ [checkVisibility] Display:", style.display, "| Visibility:", style.visibility, "| Opacity:", style.opacity); | |
| if (visible) { | |
| console.log("π’ [checkVisibility] Element is visible."); | |
| } else { | |
| throw new Error(`π΄ [checkVisibility] Element is not visible.`); | |
| } | |
| } | |
| /** | |
| * π£ checkFontSize: Checks the font size. | |
| */ | |
| async function checkFontSize(el, expectedSize) { | |
| console.log("π£ [checkFontSize] Running font-size check..."); | |
| const size = getComputedStyle(el).fontSize; | |
| console.log("π [checkFontSize] Computed font-size:", size); | |
| console.log("β [checkFontSize] Expected font-size:", expectedSize); | |
| if (size === expectedSize) { | |
| console.log("π’ [checkFontSize] Font-size matches."); | |
| } else { | |
| throw new Error(`π΄ [checkFontSize] Font-size mismatch. Expected: ${expectedSize}, got: ${size}`); | |
| } | |
| } | |
| /** | |
| * π£ checkTextContent: Checks the inner text content of the element. | |
| */ | |
| async function checkTextContent(el, expectedText) { | |
| console.log("π£ [checkTextContent] Running text content check..."); | |
| const actualText = el.textContent.trim(); | |
| console.log("π [checkTextContent] Actual text content:", actualText); | |
| console.log("β [checkTextContent] Expected text content:", expectedText); | |
| if (actualText === expectedText) { | |
| console.log("π’ [checkTextContent] Text content matches."); | |
| } else { | |
| throw new Error(`π΄ [checkTextContent] Text content mismatch. Expected: "${expectedText}", got: "${actualText}"`); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment