5/24/2006
Integrating Selenium With Build Script
[Information Below is about Selenium-Core only]
When I was at TWU, michael used three days to put selenium tests into build script. I even don't know the cc.net is actually running the selenium tests finally. From that time, I know, this is not a easy problem.
Today it is my first time trying to setup a cc running selenium tests. It costs nearly a whole day to fight with resin and jdk bugs. Fortunately, I won the game at last:) Here is some tips I want to share:
Steps:
- Start server
- Run Tests
- Get Result
- Stop server
public class SeleniumResultServelet extends HttpServlet { private String result = null; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { OutputStream outputStream = response.getOutputStream(); if (result == null) { outputStream.write("pending".getBytes()); } else { outputStream.write(result.getBytes()); } outputStream.write("\r\n".getBytes()); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { result = request.getParameter("result"); } }ps: selenium use "POST" to access postResult URL, build script use "GET" to access postResult URL. Inside the building script, there is a loop:
while(true) { Thread.sleep(500); URL url = new URL(postResultURL); InputStream inputStream = url.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String status = reader.readLine().trim(); reader.close(); if ("failed".equals(status)) { throw new RuntimeException("Selenium Test Failed"); } if (!"pending".equals(status)) { break; } }Above it is my premature way to integrate selenium... ps: the reason why I write this part of build script in Java is not only because I need to integrate selenium, but mainly because Resin can not be stopped by ant under windows (I tried windows service, but failed). So please don't blame me about that...
Subscribe to Posts [Atom]