Home Reference Source

lib/TimeoutSettings.js

  1. const util = require('util')
  2. const DEFAULT_TIMEOUT = 30000
  3.  
  4. class TimeoutSettings {
  5. constructor () {
  6. /**
  7. * The default timeout used for waits
  8. * @type {?number}
  9. * @private
  10. */
  11. this._defaultTimeout = null
  12.  
  13. /**
  14. * The default timeout used for navigation
  15. * @type {?number}
  16. * @private
  17. */
  18. this._defaultNavigationTimeout = null
  19. }
  20.  
  21. /**
  22. * Set the default timeout used for waits
  23. * @param {number} timeout
  24. */
  25. setDefaultTimeout (timeout) {
  26. this._defaultTimeout = timeout
  27. }
  28.  
  29. /**
  30. * Set the default timeout used for navigation
  31. * @param {number} timeout
  32. */
  33. setDefaultNavigationTimeout (timeout) {
  34. this._defaultNavigationTimeout = timeout
  35. }
  36.  
  37. /**
  38. * Retrieve the timeout amount used for navigation
  39. * @return {number}
  40. */
  41. navigationTimeout () {
  42. if (this._defaultNavigationTimeout != null) {
  43. return this._defaultNavigationTimeout
  44. }
  45. if (this._defaultTimeout != null) {
  46. return this._defaultTimeout
  47. }
  48. return DEFAULT_TIMEOUT
  49. }
  50.  
  51. /**
  52. * Retrieve the timeout amount used for waits
  53. * @return {number}
  54. */
  55. timeout () {
  56. if (this._defaultTimeout != null) {
  57. return this._defaultTimeout
  58. }
  59. return DEFAULT_TIMEOUT
  60. }
  61.  
  62. /** @ignore */
  63. // eslint-disable-next-line space-before-function-paren
  64. [util.inspect.custom](depth, options) {
  65. if (depth < 0) {
  66. return options.stylize('[TimeoutSettings]', 'special')
  67. }
  68.  
  69. const newOptions = Object.assign({}, options, {
  70. depth: options.depth == null ? null : options.depth - 1
  71. })
  72. const inner = util.inspect(
  73. {
  74. navigationTimeout: this.navigationTimeout(),
  75. timeout: this.timeout()
  76. },
  77. newOptions
  78. )
  79. return `${options.stylize('TimeoutSettings', 'special')} ${inner}`
  80. }
  81. }
  82.  
  83. /**
  84. * @type {TimeoutSettings}
  85. */
  86. module.exports = TimeoutSettings