record.pl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. my $built_lib = glob('Selenium-Remote-Driver-*/lib');
  12. if (not defined $built_lib) {
  13. print ' Building a dist.';
  14. print `cd $repo_root && dzil build`;
  15. }
  16. # If built_lib wasn't around in the first place, we'll have to glob
  17. # for it again.
  18. $built_lib = $repo_root . ($built_lib || glob('Selenium-Remote-Driver-*/lib'));
  19. if ($^O eq 'linux') {
  20. 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";
  21. }
  22. my $export = $^O eq 'MSWin32' ? 'set' : 'export';
  23. my $wait = $^O eq 'MSWin32' ? 'START /WAIT' : '';
  24. print `$export WD_MOCKING_RECORD=1 && cd $repo_root && prove -I$built_lib -rv t/`;
  25. reset_env();
  26. sub start_server {
  27. if ($^O eq 'MSWin32') {
  28. system('start "TEMP_HTTP_SERVER" /MIN perl ' . $repo_root . 't/http-server.pl');
  29. }
  30. else {
  31. system('perl ' . $repo_root . 't/http-server.pl > /dev/null &');
  32. }
  33. }
  34. sub kill_server {
  35. if ($^O eq 'MSWin32') {
  36. system("taskkill /FI \"WINDOWTITLE eq TEMP_HTTP_SERVER\"");
  37. }
  38. else {
  39. `ps aux | grep [h]ttp-server\.pl | awk '{print \$2}' | xargs kill`;
  40. }
  41. }
  42. sub reset_env {
  43. if (@ARGV && $ARGV[0] eq 'reset') {
  44. print 'Cleaning. ';
  45. `cd $repo_root && dzil clean`;
  46. }
  47. print 'Taking out any existing servers. ';
  48. kill_server();
  49. }