Skip to content

Commit

Permalink
still tryna add signup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Umi007 committed Jun 13, 2024
1 parent 09527ff commit 89cddb4
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 89 deletions.
15 changes: 1 addition & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,6 @@ jobs:
restore-keys: |
${{ runner.os }}-maven-
- name: Install Chrome and Chromedriver
run: |
sudo apt-get update
sudo apt-get -f install -y
wget -q -O /tmp/google-chrome-stable_current_amd64.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i /tmp/google-chrome-stable_current_amd64.deb || sudo apt-get -f install -y
CHROME_VERSION=$(google-chrome --version | grep -oE '[0-9.]+' | head -1)
CHROMEDRIVER_VERSION=$(curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION")
wget -q -O /tmp/chromedriver_linux64.zip https://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip
unzip /tmp/chromedriver_linux64.zip -d /tmp/
sudo mv /tmp/chromedriver /usr/local/bin/chromedriver
sudo chmod +x /usr/local/bin/chromedriver
- name: Build with Maven
env:
Expand All @@ -65,5 +53,4 @@ jobs:
DB_PASSWORD: test_password
SPRING_PROFILES_ACTIVE: test
run: |
# Run tests with Selenium and Chrome in headless mode
mvn test -X --debug -DargLine="-Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -Dwebdriver.chrome.args=--headless --disable-gpu"
mvn test -X --debug
150 changes: 75 additions & 75 deletions src/test/java/SignUpTest.java
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
import com.github.javafaker.Faker;
import com.makersacademy.acebook.Application;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
public class SignUpTest {

WebDriver driver;
Faker faker;

@Before
public void setup() {
// use environment variable to get chromedriver location
// System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
//// System.setProperty("webdriver.chrome.driver", System.getenv("CHROME_DRIVER_LOCATION"));
//// DesiredCapabilities capabilities = new DesiredCapabilities();
//// capabilities.setCapability("chrome.options", new ChromeOptions().addArguments("--allowed-ips=18.196.138.205\t"));
//// WebDriver driver = new ChromeDriver(capabilities);
//// ChromeOptions options = new ChromeOptions();
//// options.addArguments("--headless");
//// options.addArguments("--no-sandbox");
//// options.addArguments("--disable-dev-shm-usage");
// driver = new ChromeDriver();
//import com.github.javafaker.Faker;
//import com.makersacademy.acebook.Application;
//import org.junit.After;
//import org.junit.Assert;
//import org.junit.Before;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.openqa.selenium.By;
//import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.chrome.ChromeOptions;
//import org.openqa.selenium.remote.DesiredCapabilities;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
//
//@RunWith(SpringJUnit4ClassRunner.class)
//@SpringBootTest(classes = Application.class)
//public class SignUpTest {
//
// WebDriver driver;
// Faker faker;
//
// @Before
// public void setup() {
//// use environment variable to get chromedriver location
//// System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
////// System.setProperty("webdriver.chrome.driver", System.getenv("CHROME_DRIVER_LOCATION"));
////// DesiredCapabilities capabilities = new DesiredCapabilities();
////// capabilities.setCapability("chrome.options", new ChromeOptions().addArguments("--allowed-ips=18.196.138.205\t"));
////// WebDriver driver = new ChromeDriver(capabilities);
////// ChromeOptions options = new ChromeOptions();
////// options.addArguments("--headless");
////// options.addArguments("--no-sandbox");
////// options.addArguments("--disable-dev-shm-usage");
//// driver = new ChromeDriver();
// faker = new Faker();
// Set the path to the ChromeDriver executable
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

// Configure Chrome options
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless"); // Run in headless mode for CI environments
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");

// Initialize the WebDriver
driver = new ChromeDriver(options);
}

@After
public void tearDown() {
driver.close();
}

@Test
public void successfulSignUpRedirectsToSignIn() {
driver.get("http://localhost:8080/");
driver.findElement(By.id("username")).sendKeys(faker.name().firstName());
driver.findElement(By.id("password")).sendKeys("password");
driver.findElement(By.id("submit")).click();
String title = driver.getTitle();
Assert.assertEquals("Please sign in", title);
}

@Test
public void successfulSignUpRedirectsToWelcome() {
// ... rest of the test code
String title = driver.getTitle();
Assert.assertEquals("Welcome", title); // assuming "Welcome" is the title of the welcome page
}
}



////// driver = new ChromeDriver();
//// faker = new Faker();
// // Set the path to the ChromeDriver executable
// System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
//
// // Configure Chrome options
// ChromeOptions options = new ChromeOptions();
// options.addArguments("--headless"); // Run in headless mode for CI environments
// options.addArguments("--disable-gpu");
// options.addArguments("--no-sandbox");
// options.addArguments("--disable-dev-shm-usage");
//
// // Initialize the WebDriver
// driver = new ChromeDriver(options);
// }
//
// @After
// public void tearDown() {
// driver.close();
// }
//
// @Test
// public void successfulSignUpRedirectsToSignIn() {
// driver.get("http://localhost:8080/");
// driver.findElement(By.id("username")).sendKeys(faker.name().firstName());
// driver.findElement(By.id("password")).sendKeys("password");
// driver.findElement(By.id("submit")).click();
// String title = driver.getTitle();
// Assert.assertEquals("Please sign in", title);
// }
//
// @Test
// public void successfulSignUpRedirectsToWelcome() {
// // ... rest of the test code
// String title = driver.getTitle();
// Assert.assertEquals("Welcome", title); // assuming "Welcome" is the title of the welcome page
// }
//}
//
//
//

0 comments on commit 89cddb4

Please sign in to comment.