Skip to content

Instantly share code, notes, and snippets.

@vivrichards600
vivrichards600 / simple-heardle-solution.cs
Last active June 19, 2022 10:16
A quick and dirty test to guess the Headle.App of the day
// A simple test to automate guessing the Heardle of the day
// Note: using Thread.Sleep is only used to keep things simple as part of a PoC
// A wait strategy should really be used but I was being lazy ;-)
//go to heardle of the day
ChromeDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://www.heardle.app/");
//find hidden field with url for the days song
var url = driver.FindElement(By.TagName("iframe")).GetAttribute("src");
@vivrichards600
vivrichards600 / gist:ae658e9f4c5b3d9787a68879d0be3b25
Created November 26, 2020 17:31
Scala/Cucumber - take a screenshot after each step
class Hooks extends ScalaDsl with EN with BrowserDriver {
AfterStep { scenario: Scenario =>
if (scenario.isFailed) {
val screenshotName = scenario.getName.replaceAll(" ", "_")
val screenshot = driver.asInstanceOf[TakesScreenshot].getScreenshotAs(OutputType.BYTES)
scenario.attach(screenshot, "image/png", screenshotName)
}
}
}
@vivrichards600
vivrichards600 / Color Sense Test 2
Created April 12, 2020 12:55
Automating color sense 2 test on http://zzzscore.com/color2/en/ using webdriver and c#
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://zzzscore.com/color2/en/");
var sixtySecondsFromNow = DateTime.Now.AddSeconds(60);
while (DateTime.Now <= sixtySecondsFromNow)
{
driver.FindElement(By.CssSelector(".main")).Click();
}
Console.WriteLine($"Score: {driver.FindElement(By.Id("score"))}");
driver.Quit();
@vivrichards600
vivrichards600 / Color Sense Test
Last active November 30, 2021 04:10
Automating color sense test on http://zzzscore.com/color/en using webdriver and c#
// Automating color sense test http://zzzscore.com/color/en using webdriver and c#
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://zzzscore.com/color/en/");
var sixtySecondsFromNow = DateTime.Now.AddSeconds(60);
while (DateTime.Now <= sixtySecondsFromNow)
{
driver.FindElement(By.CssSelector(".main")).Click();
}
@vivrichards600
vivrichards600 / 1to50
Last active April 11, 2020 17:10
Automating 1 to 50 on http://zzzscore.com/1to50/en/ using webdriver and c#
// Automating 1 to 50 on http://zzzscore.com/1to50/en/ using webdriver and c#
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://zzzscore.com/1to50/en/?ts=1586616870389");
for (var number = 1; number <= 50; number+=1) {
driver.FindElement(By.XPath($"//div[. = '{number}']")).Click();
}
driver.Quit();
@vivrichards600
vivrichards600 / visual-checking-a11y
Last active February 23, 2020 18:19
A gist to demonstrate how to visual check a page has images which have alt tags, inputs have associated labels and that there are no broken links on the page
// This Gist uses the following project to provide basic visual checking functionality
// https://github.com/vivrichards600/AutomatedVisualTesting
// This Gist is quick and dirty to show how to check a web page for:
// Images with no alt tags, Inputs with no associated labels, Broken links and Elements with duplicate ids
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.Extensions;
using static AutomatedVisualTesting.Utilities.Compare;
var inputs = document.querySelectorAll('input');
var labels = document.querySelectorAll('label');
for (var currentInput = 0; currentInput < inputs.length; currentInput++) {
var inputHasLabel = false;
for (var currentLabel = 0; currentLabel < labels.length; currentLabel++) {
if (labels[currentLabel].htmlFor == inputs[currentInput].id) {
inputHasLabel = true;
}
}