Last active
June 19, 2022 10:16
-
-
Save vivrichards600/8a42aed3ca7ab7c4f2219952de067f3e to your computer and use it in GitHub Desktop.
A quick and dirty test to guess the Headle.App of the day
This file contains 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
// 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"); | |
//get song title out of the soundcloud url | |
url = url.Replace("https://w.soundcloud.com/player/?url=https://soundcloud.com/", ""); | |
var title = url.Substring(0, url.IndexOf("&")).Split("/")[1].Replace("-"," "); | |
//only take first 10 characters (some titles are weird) e.g. some titles have a -1 in them | |
// also check if the title is actually longer than 10 characters. If it is, shorten the title | |
var shortenedTitle = title.Replace(" 1",""); | |
if (shortenedTitle.Length > 10) shortenedTitle = title.Substring(0, 10); | |
//click to start the game | |
driver.FindElement(By.XPath("//button[text()='Play']")).Click(); | |
Thread.Sleep(2000); | |
//play todays headle - this let you submit an answer | |
driver.FindElement(By.XPath("/html/body/main/div[4]/div/div/div/div[2]/button")).Click(); | |
Thread.Sleep(1000); | |
//provide song title for autocomplete | |
driver.FindElement(By.Id("autoComplete")).SendKeys(shortenedTitle); | |
Thread.Sleep(1000); | |
//select song from list | |
driver.FindElement(By.Id("autoComplete_result_0")).Click(); | |
//submit answer | |
driver.FindElement(By.XPath("//button[text()='Submit']")).Click(); | |
//check we see the text which says we got the days heardle! | |
var winner = driver.FindElement(By.XPath("/html/body/main/div[2]/div/div[2]/p[2]")).Text; | |
Assert.IsTrue(winner.Equals("You got today's Heardle within 1 second.")); | |
//play a bit of the headle before we do a little victory dance and quit :) | |
Thread.Sleep(5000); | |
driver.Quit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment