parallel_flows.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Licensed to the Software Freedom Conservancy (SFC) under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. The SFC licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. /**
  18. * @fileoverview An example of starting multiple WebDriver clients that run
  19. * in parallel in separate control flows.
  20. *
  21. * This example will only work when the promise manager is enabled
  22. * (see <https://github.com/SeleniumHQ/selenium/issues/2969>).
  23. */
  24. const {Builder, By, Key, promise, until} = require('..');
  25. for (var i = 0; i < 3; i++) {
  26. (function(n) {
  27. var flow = new promise.ControlFlow()
  28. .on('uncaughtException', function(e) {
  29. console.log('uncaughtException in flow %d: %s', n, e);
  30. });
  31. var driver = new Builder().
  32. forBrowser('firefox').
  33. setControlFlow(flow). // Comment out this line to see the difference.
  34. build();
  35. // Position and resize window so it's easy to see them running together.
  36. driver.manage().window().setSize(600, 400);
  37. driver.manage().window().setPosition(300 * i, 400 * i);
  38. driver.get('http://www.google.com');
  39. driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
  40. driver.wait(until.titleIs('webdriver - Google Search'), 1000);
  41. driver.quit();
  42. })(i);
  43. }