javascript
pdf保存如何带批注_带有批注的SpringSelenium测试
pdf保存如何帶批注
這篇文章描述了如何在Java中實現Selenium測試。 它的靈感來自Alex Collins的帖子,并帶有注釋。 該代碼可在GitHub的Spring-Selenium-Test目錄中找到。 一些替代方法和更輕巧的技術可用于對Spring MVC應用程序進行單元測試。 要進行單元測試服務,請參見此處 。
頁面,配置和控制器
我們使用“ Hello World”創建一個簡單的頁面:
<!doctype html> <html lang='en'> <head><meta charset='utf-8'><title>Welcome !!!</title> </head> <body><h1>Hello World !</h1> </body> </html>我們使控制器非常簡單:
@EnableWebMvc @Configuration @ComponentScan(basePackages = 'com.jverstry') public class WebConfig extends WebMvcConfigurerAdapter {@Beanpublic ViewResolver getViewResolver() {InternalResourceViewResolver resolver = new InternalResourceViewResolver();resolver.setPrefix('WEB-INF/pages/');resolver.setSuffix('.jsp');return resolver;}}還有我們的控制器:
@Controller public class MyController {@RequestMapping(value = '/')public String home() {return 'index';}}用于Selenium測試
我們創建一個測試配置。 它提供了用于在本地打開應用程序的URL。 該應用程序是使用Firefox打開的:
@Configuration public class TestConfig {@Beanpublic URI getSiteBase() throws URISyntaxException {return new URI('http://localhost:10001/spring-selenium-test-1.0.0');}@Bean(destroyMethod='quit')public FirefoxDriver getDrv() {return new FirefoxDriver();}}我們還定義了一個抽象類作為所有測試的基礎。 測試后,它將自動關閉Firefox:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes={ TestConfig.class }) public abstract class AbstractTestIT {@Autowiredprotected URI siteBase;@Autowiredprotected WebDriver drv;{Runtime.getRuntime().addShutdownHook(new Thread() {@Overridepublic void run() {drv.close();}});}}然后我們執行Selenium測試,以確保我們的頁面包含“ Hello World”:
public class SeleniumTestIT extends AbstractTestIT {@Testpublic void testWeSeeHelloWorld() {drv.get(siteBase.toString());assertTrue(drv.getPageSource().contains('Hello World'));}}Maven依賴項與Alex Collins帖子中描述的依賴項相同。
構建應用程序
如果您構建了該應用程序,它將自動打開和關閉Firefox。 測試將成功。
參考: 技術說明博客上的JCG合作伙伴 Jerome Versrynge提供的帶注釋的SpringSelenium測試 。
翻譯自: https://www.javacodegeeks.com/2013/01/spring-selenium-tests-with-annotations.html
pdf保存如何帶批注
總結
以上是生活随笔為你收集整理的pdf保存如何带批注_带有批注的SpringSelenium测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 常用电脑系统图标(常用电脑系统图标有哪些
- 下一篇: Spring教程:使用Spring框架和