Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
6eaf0f7373
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -1,36 +1,48 @@
|
|||
<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>com.baeldung</groupId>
|
||||
<artifactId>selenium-junit-testng</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<version>2.53.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>6.9.10</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<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>com.baeldung</groupId>
|
||||
<artifactId>selenium-junit-testng</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.19.1</version>
|
||||
<configuration>
|
||||
<testSourceDirectory></testSourceDirectory>
|
||||
<includes>
|
||||
<include>Test*.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<version>2.53.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>6.9.10</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -6,9 +6,8 @@ import org.openqa.selenium.firefox.FirefoxDriver;
|
|||
public class SeleniumExample {
|
||||
|
||||
private WebDriver webDriver;
|
||||
private final String url = "http://www.baeldung.com/";
|
||||
private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
||||
|
||||
private String url = "http://www.baeldung.com/";
|
||||
|
||||
public SeleniumExample() {
|
||||
webDriver = new FirefoxDriver();
|
||||
webDriver.get(url);
|
||||
|
@ -18,12 +17,8 @@ public class SeleniumExample {
|
|||
webDriver.close();
|
||||
}
|
||||
|
||||
public String getActualTitle() {
|
||||
public String getTitle() {
|
||||
return webDriver.getTitle();
|
||||
}
|
||||
|
||||
public String getExpectedTitle() {
|
||||
return expectedTitle;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package test.java.com.baeldung.selenium.junit;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import main.java.com.baeldung.selenium.SeleniumExample;
|
||||
|
||||
import org.junit.After;
|
||||
|
@ -10,6 +11,7 @@ import org.junit.Test;
|
|||
public class TestSeleniumWithJUnit {
|
||||
|
||||
private SeleniumExample seleniumExample;
|
||||
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
@ -23,8 +25,8 @@ public class TestSeleniumWithJUnit {
|
|||
|
||||
@Test
|
||||
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
||||
String expectedTitle = seleniumExample.getExpectedTitle();
|
||||
String actualTitle = seleniumExample.getActualTitle();
|
||||
String actualTitle = seleniumExample.getTitle();
|
||||
assertNotNull(actualTitle);
|
||||
assertEquals(actualTitle, expectedTitle);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package test.java.com.baeldung.selenium.testng;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import main.java.com.baeldung.selenium.SeleniumExample;
|
||||
|
||||
import org.testng.annotations.AfterSuite;
|
||||
|
@ -10,6 +11,7 @@ import org.testng.annotations.Test;
|
|||
public class TestSeleniumWithTestNG {
|
||||
|
||||
private SeleniumExample seleniumExample;
|
||||
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
||||
|
||||
@BeforeSuite
|
||||
public void setUp() {
|
||||
|
@ -23,8 +25,8 @@ public class TestSeleniumWithTestNG {
|
|||
|
||||
@Test
|
||||
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
||||
String expectedTitle = seleniumExample.getExpectedTitle();
|
||||
String actualTitle = seleniumExample.getActualTitle();
|
||||
String actualTitle = seleniumExample.getTitle();
|
||||
assertNotNull(actualTitle);
|
||||
assertEquals(actualTitle, expectedTitle);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
package com.baeldun.selenium.testng;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
import org.testng.annotations.AfterSuite;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class TestSeleniumWithTestNG {
|
||||
|
||||
private WebDriver webDriver;
|
||||
private final String url = "http://www.baeldung.com/";
|
||||
private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
||||
|
||||
@BeforeSuite
|
||||
public void setUp() {
|
||||
webDriver = new FirefoxDriver();
|
||||
webDriver.get(url);
|
||||
}
|
||||
|
||||
@AfterSuite
|
||||
public void tearDown() {
|
||||
webDriver.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
||||
String actualTitleReturned = webDriver.getTitle();
|
||||
assertNotNull(actualTitleReturned);
|
||||
assertEquals(expectedTitle, actualTitleReturned);
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.baeldung.selenium.junit;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
|
||||
public class TestSeleniumWithJUnit {
|
||||
|
||||
private WebDriver webDriver;
|
||||
private final String url = "http://www.baeldung.com/";
|
||||
private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
webDriver = new FirefoxDriver();
|
||||
webDriver.get(url);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
webDriver.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
||||
String actualTitleReturned = webDriver.getTitle();
|
||||
assertNotNull(actualTitleReturned);
|
||||
assertEquals(expectedTitle, actualTitleReturned);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
package com.baeldung.thymeleaf.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
/**
|
||||
* Controller to test expression utility objects: dates,
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class ExpressionUtilityObjectsController {
|
||||
|
||||
@RequestMapping(value = "/objects", method = RequestMethod.GET)
|
||||
public String getDates(Model model) {
|
||||
model.addAttribute("date", new Date());
|
||||
model.addAttribute("calendar", Calendar.getInstance());
|
||||
model.addAttribute("num", Math.random() * 10);
|
||||
model.addAttribute("string", "new text");
|
||||
model.addAttribute("emptyString", "");
|
||||
model.addAttribute("nullString", null);
|
||||
model.addAttribute("array", new int[] { 1, 3, 4, 5 });
|
||||
model.addAttribute("set", new HashSet<Integer>(Arrays.asList(1, 3, 8)));
|
||||
return "objects.html";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Expression utility objects</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Date expression utility</h1>
|
||||
<p th:text="${#dates.formatISO(date)}"></p>
|
||||
<p th:text="${#dates.format(date, 'dd-MM-yyyy HH:mm')}"></p>
|
||||
<p th:text="${#dates.dayOfWeekName(date)}"></p>
|
||||
<p th:text="${#dates.createNow()}"></p>
|
||||
<p th:text="${#dates.createToday()}"></p>
|
||||
|
||||
<h1>Calendar expression utility</h1>
|
||||
<p th:text="${#calendars.formatISO(calendar)}"></p>
|
||||
<p th:text="${#calendars.format(calendar, 'dd-MM-yyyy HH:mm')}"></p>
|
||||
<p th:text="${#calendars.dayOfWeekName(calendar)}"></p>
|
||||
<p th:text="${#calendars.createNow().getTime()}"></p>
|
||||
<p th:text="${#calendars.createToday().getFirstDayOfWeek()}"></p>
|
||||
|
||||
<h1>Numbers expression utility</h1>
|
||||
<p th:text="${#numbers.formatDecimal(num,2,3)}"></p>
|
||||
<p th:text="${#numbers.formatDecimal(num,2,3,'COMMA')}"></p>
|
||||
<p th:each="number: ${#numbers.sequence(0,2)}">
|
||||
<span th:text="${number}"></span>
|
||||
</p>
|
||||
<p th:each="number: ${#numbers.sequence(0,4,2)}">
|
||||
<span th:text="${number}"></span>
|
||||
</p>
|
||||
|
||||
<h1>Calendar expression utility</h1>
|
||||
<p th:text="${#strings.isEmpty(string)}"></p>
|
||||
<p th:text="${#strings.isEmpty(nullString)}"></p>
|
||||
<p th:text="${#strings.defaultString(emptyString,'Empty String')}"></p>
|
||||
<p th:text="${#strings.containsIgnoreCase(string,'new')}"></p>
|
||||
<p th:text="${#strings.abbreviate(string,5)} "></p>
|
||||
<p th:text="${#strings.capitalizeWords(string)}"></p>
|
||||
|
||||
<h1>Aggregates expression utility</h1>
|
||||
<p th:text="${#aggregates.sum(array)}"></p>
|
||||
<p th:text="${#aggregates.avg(array)}"></p>
|
||||
<p th:text="${#aggregates.sum(set)}"></p>
|
||||
<p th:text="${#aggregates.avg(set)}"></p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,58 @@
|
|||
package com.baeldung.thymeleaf.controller;
|
||||
|
||||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
|
||||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.mock.web.MockHttpSession;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.RequestPostProcessor;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import com.baeldung.thymeleaf.config.InitSecurity;
|
||||
import com.baeldung.thymeleaf.config.WebApp;
|
||||
import com.baeldung.thymeleaf.config.WebMVCConfig;
|
||||
import com.baeldung.thymeleaf.config.WebMVCSecurity;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(classes = { WebApp.class, WebMVCConfig.class, WebMVCSecurity.class, InitSecurity.class })
|
||||
public class ExpressionUtilityObjectsControllerTest {
|
||||
|
||||
@Autowired
|
||||
WebApplicationContext wac;
|
||||
@Autowired
|
||||
MockHttpSession session;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Autowired
|
||||
private Filter springSecurityFilterChain;
|
||||
|
||||
protected RequestPostProcessor testUser() {
|
||||
return user("user1").password("user1Pass").roles("USER");
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
mockMvc = MockMvcBuilders.webAppContextSetup(wac).addFilters(springSecurityFilterChain).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDates() throws Exception{
|
||||
mockMvc.perform(get("/objects").with(testUser()).with(csrf())).andExpect(status().isOk()).andExpect(view().name("objects.html"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue