Last active
January 19, 2024 21:58
-
-
Save aevans-mms/d8fae7c35089038040e838dc38aea370 to your computer and use it in GitHub Desktop.
Hello Selenium
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
package org.example; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
public class Main { | |
public static void main(String[] args) { | |
WebDriver driver = new ChromeDriver(); | |
driver.get("https://www.nejm.org/"); | |
String title = driver.getTitle(); | |
System.out.println("title: " + title); | |
driver.quit(); | |
} | |
} |
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
package org.example; | |
import org.junit.jupiter.api.AfterEach; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import static org.assertj.core.api.Assertions.assertThat; | |
import static org.junit.jupiter.api.Assertions.assertEquals; | |
public class NejmTest { | |
WebDriver driver; | |
@BeforeEach | |
public void startWebDriver() { | |
driver = new ChromeDriver(); | |
driver.get("https://stag.nejm.org/"); | |
} | |
@AfterEach | |
public void closeWebDriver() { | |
driver.quit(); | |
} | |
@Test | |
public void openHomePage() { | |
driver.get("https://www.nejm.org/"); | |
String title = driver.getTitle(); | |
System.out.println("title: " + title); | |
assertEquals("The New England Journal of Medicine: Research & Review Articles on Disease & Clinical Practice", title); | |
} | |
@Test | |
public void checkPartialTitle() { | |
driver.get("https://www.nejm.org/"); | |
String title = driver.getTitle(); | |
System.out.println("title: " + title); | |
assertThat(title).contains("The New England Journal of Medicine"); | |
} | |
@Test | |
public void createAccount() { | |
WebElement create_account_link = driver.findElement(By.partialLinkText("Create Account")); | |
create_account_link.click(); | |
String title = driver.getTitle(); | |
assertThat(title).contains("Create an Account"); | |
// Note: this assertion will fail when not on VPN -- blocked by Cloudflare | |
} | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>org.example</groupId> | |
<artifactId>nejm-test</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<properties> | |
<maven.compiler.source>17</maven.compiler.source> | |
<maven.compiler.target>17</maven.compiler.target> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>org.seleniumhq.selenium</groupId> | |
<artifactId>selenium-java</artifactId> | |
<version>4.14.1</version> | |
</dependency> | |
<dependency> | |
<groupId>org.junit.jupiter</groupId> | |
<artifactId>junit-jupiter</artifactId> | |
<version>5.9.3</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.assertj</groupId> | |
<artifactId>assertj-core</artifactId> | |
<version>3.24.2</version> | |
</dependency> | |
</dependencies> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can check out this project together from https://github.com/aevans-mms/nejm-test