1
0

record.pl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #! /usr/bin/env 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. my $prove_opts = '-I' . $built_lib .' -j9 -r --verbose --trap --merge --state=save,slow';
  16. print `$export WD_MOCKING_RECORD=1 && cd $repo_root && prove $prove_opts t/`;
  17. reset_env();
  18. sub find_built_lib {
  19. my $built_lib = glob($repo_root . 'Selenium-Remote-Driver-*/lib');
  20. if (not defined $built_lib) {
  21. print 'Building a dist.' . "\n";
  22. print `cd $repo_root && dzil build`;
  23. }
  24. # If built_lib wasn't around in the first place, we'll have to glob
  25. # for it again.
  26. $built_lib ||= glob($repo_root . 'Selenium-Remote-Driver-*/lib');
  27. return $built_lib;
  28. }
  29. sub output_linux_help {
  30. if ($^O eq 'linux') {
  31. 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-*.jar\n\n";
  32. }
  33. }
  34. sub start_server {
  35. if ($^O eq 'MSWin32') {
  36. system('start "TEMP_HTTP_SERVER" /MIN perl ' . $repo_root . 't/http-server.pl');
  37. }
  38. else {
  39. system('perl ' . $repo_root . 't/http-server.pl > /dev/null &');
  40. }
  41. print 'Starting a new server.' . "\n";
  42. }
  43. sub kill_server {
  44. if ($^O eq 'MSWin32') {
  45. system("taskkill /FI \"WINDOWTITLE eq TEMP_HTTP_SERVER\"");
  46. }
  47. else {
  48. `ps aux | grep [h]ttp-server\.pl | awk '{print \$2}' | xargs kill`;
  49. }
  50. }
  51. sub reset_env {
  52. if (@ARGV && $ARGV[0] eq 'reset') {
  53. print 'Cleaning. ';
  54. `cd $repo_root && dzil clean`;
  55. }
  56. print 'Taking out any existing servers. ' . "\n";
  57. kill_server();
  58. }