Skip to content

Instantly share code, notes, and snippets.

@chrisparnin
Created September 28, 2016 15:46
Show Gist options
  • Save chrisparnin/e3ee1a96c681f12ae11246cfe3225182 to your computer and use it in GitHub Desktop.
Save chrisparnin/e3ee1a96c681f12ae11246cfe3225182 to your computer and use it in GitHub Desktop.
@Test
public void postMessage()
{
driver.get("https://csc510-fall16.slack.com/");
// Wait until page loads and we can see a sign in button.
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("signin_btn")));
// Find email and password fields.
WebElement email = driver.findElement(By.id("email"));
WebElement pw = driver.findElement(By.id("password"));
// Type in our test user login info.
email.sendKeys("[email protected]");
pw.sendKeys("****");
// Click
WebElement signin = driver.findElement(By.id("signin_btn"));
signin.click();
// Wait until we go to general channel.
wait.until(ExpectedConditions.titleContains("general"));
// Switch to #bots channel and wait for it to load.
driver.get("https://csc510-fall16.slack.com/messages/bots");
wait.until(ExpectedConditions.titleContains("bots"));
// Type something
WebElement messageBot = driver.findElement(By.id("message-input"));
messageBot.sendKeys("hello world, from Selenium");
messageBot.sendKeys(Keys.RETURN);
wait.withTimeout(3, TimeUnit.SECONDS).ignoring(StaleElementReferenceException.class);
WebElement msg = driver.findElement(
By.xpath("//span[@class='message_body' and text() = 'hello world, from Selenium']"));
assertNotNull(msg);
}
@arewm
Copy link

arewm commented Oct 9, 2017

Slack has changed a little bit in a year. I had to make a couple of changes to get this code to pass:

@Test
public void postMessage()
{
	driver.get("https://" + System.getenv("SLACK_WEB_ADDRESS") + "/");

	// Wait until page loads and we can see a sign in button.
	WebDriverWait wait = new WebDriverWait(driver, 30);
	wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("signin_btn")));

	// Find email and password fields.
	WebElement email = driver.findElement(By.id("email"));
	WebElement pw = driver.findElement(By.id("password"));

	// Enter our email and password
	// If running this from Eclipse, you should specify these variables in the run configurations.
	email.sendKeys(System.getenv("SLACK_EMAIL"));
	pw.sendKeys(System.getenv("SLACK_PASSWORD"));

	// Click
	WebElement signin = driver.findElement(By.id("signin_btn"));
	signin.click();

	// Wait until we go to general channel.
	wait.until(ExpectedConditions.titleContains("general"));

	// Switch to #selenium-bot channel and wait for it to load.
	driver.get("https://" + System.getenv("SLACK_WEB_ADDRESS") + "/messages/selenium-bot");
	wait.until(ExpectedConditions.titleContains("selenium-bot"));

	// Type something
	WebElement messageBot = driver.findElement(By.id("msg_input"));
	assertNotNull(messageBot);
		
	Actions actions = new Actions(driver);
	actions.moveToElement(messageBot);
	actions.click();
	actions.sendKeys("hello world, from Selenium");
	actions.sendKeys(Keys.RETURN);
	actions.build().perform();

	wait.withTimeout(3, TimeUnit.SECONDS).ignoring(StaleElementReferenceException.class);

	WebElement msg = driver.findElement(
			By.xpath("//span[@class='message_body' and text() = 'hello world, from Selenium']"));
	assertNotNull(msg);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment