record.pl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #! /usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Cwd qw/abs_path/;
  5. use FindBin;
  6. # We can only dzil from the root of the repository.
  7. my $this_folder = $FindBin::Bin . '/../../'; # t/bin/../../
  8. my $repo_root = abs_path($this_folder) . '/';
  9. reset_env();
  10. start_server();
  11. output_linux_help();
  12. my $built_lib = find_built_lib();
  13. my $export = $^O eq 'MSWin32' ? 'set' : 'export';
  14. my $wait = $^O eq 'MSWin32' ? 'START /WAIT' : '';
  15. print `$export WD_MOCKING_RECORD=1 && cd $repo_root && prove -I$built_lib -rv t/`;
  16. reset_env();
  17. sub find_built_lib {
  18. my $built_lib = glob($repo_root . 'Selenium-Remote-Driver-*/lib');
  19. if (not defined $built_lib) {
  20. print 'Building a dist.' . "\n";
  21. print `cd $repo_root && dzil build`;
  22. }
  23. # If built_lib wasn't around in the first place, we'll have to glob
  24. # for it again.
  25. $built_lib ||= glob($repo_root . 'Selenium-Remote-Driver-*/lib');
  26. return $built_lib;
  27. }
  28. sub output_linux_help {
  29. if ($^O eq 'linux') {
  30. print "Headless and need a webdriver server started? Try\n\n\tDISPLAY=:1 xvfb-run --auto-servernum java -jar /usr/lib/node_modules/protractor/selenium/selenium-server-standalone-2.42.2.jar\n\n";
  31. }
  32. }
  33. sub start_server {
  34. if ($^O eq 'MSWin32') {
  35. system('start "TEMP_HTTP_SERVER" /MIN perl ' . $repo_root . 't/http-server.pl');
  36. }
  37. else {
  38. system('perl ' . $repo_root . 't/http-server.pl > /dev/null &');
  39. }
  40. print 'Starting a new server.' . "\n";
  41. }
  42. sub kill_server {
  43. if ($^O eq 'MSWin32') {
  44. system("taskkill /FI \"WINDOWTITLE eq TEMP_HTTP_SERVER\"");
  45. }
  46. else {
  47. `ps aux | grep [h]ttp-server\.pl | awk '{print \$2}' | xargs kill`;
  48. }
  49. }
  50. sub reset_env {
  51. if (@ARGV && $ARGV[0] eq 'reset') {
  52. print 'Cleaning. ';
  53. `cd $repo_root && dzil clean`;
  54. }
  55. print 'Taking out any existing servers. ' . "\n";
  56. kill_server();
  57. }