How to use runcommand method in tox

Best Python code snippet using tox_python

command_runner.runCommand.test.js

Source:command_runner.runCommand.test.js Github

copy

Full Screen

1import fetchMock from 'fetch-mock'2import {3 runCommand,4 __RewireAPI__ as runCommandRewire5} from '../../src/command_runner'6const hookMock = {7 beforeCommand: {8 promise: async () => {}9 },10 onElement: {11 promise: async () => {}12 }13}14describe('runCommand', () => {15 const makeFakeElement = (fail = false, msg = 'fakeError') => ({16 waitForExist: timeout =>17 fail ? Promise.reject(msg) : Promise.resolve(true),18 waitForDisplayed: timeout =>19 fail ? Promise.reject(msg) : Promise.resolve(true)20 })21 beforeEach(() => {22 global.browser = {}23 // global.expect = expect24 // Setup mocks for other functions from testrunner25 runCommandRewire.__Rewire__('doReplace', s => Promise.resolve(s))26 runCommandRewire.__Rewire__('log', () => {}) // don't log for tests27 runCommandRewire.__Rewire__('getSelector', target => target)28 runCommandRewire.__Rewire__('getExecElString', sel => {29 return "document.querySelector('" + sel + "')"30 })31 })32 afterEach(() => {33 runCommandRewire.__ResetDependency__('doReplace')34 runCommandRewire.__ResetDependency__('getSelector')35 runCommandRewire.__ResetDependency__('getExecElString')36 runCommandRewire.__ResetDependency__('log')37 fetchMock.restore()38 })39 it('should throw error for unsupported command', () => {40 const c = {41 command: 'fakeCommand',42 parameters: {}43 }44 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()45 })46 describe('ASSERTIONS', () => {47 describe('assertAttribute', () => {48 it('should run assertAttribute command', () => {49 const c = {50 command: 'assertAttribute',51 parameters: {52 target: 'id=potato',53 attribute: 'name',54 expected: 'yams'55 }56 }57 const el = {58 ...makeFakeElement(),59 getAttribute: () => Promise.resolve('yams')60 }61 global.browser.$ = () => Promise.resolve(el)62 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()63 })64 it('should run assertAttribute command with regex', () => {65 const c = {66 command: 'assertAttribute',67 parameters: {68 target: 'id=potato',69 attribute: 'name',70 expected: '/y.*/'71 }72 }73 const el = {74 ...makeFakeElement(),75 getAttribute: () => Promise.resolve('yams')76 }77 global.browser.$ = () => Promise.resolve(el)78 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()79 })80 it('should reject assertAttribute command with regex that doesnt match', () => {81 const c = {82 command: 'assertAttribute',83 parameters: {84 target: 'id=potato',85 attribute: 'name',86 expected: '/ya{2}ms/'87 }88 }89 const el = {90 ...makeFakeElement(),91 getAttribute: () => Promise.resolve('yams')92 }93 global.browser.$ = () => Promise.resolve(el)94 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()95 })96 it('should reject assertAttribute command', () => {97 const c = {98 command: 'assertAttribute',99 parameters: {100 target: 'id=potato',101 attribute: 'name',102 expected: 'yams'103 }104 }105 const el = {106 ...makeFakeElement(),107 getAttribute: () => Promise.resolve('notyams')108 }109 global.browser.$ = () => Promise.resolve(el)110 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()111 })112 })113 describe('assertCheckboxState', () => {114 it('should run assertCheckboxState command', () => {115 const c = {116 command: 'assertCheckboxState',117 parameters: {118 target: 'id=test',119 expected: true120 }121 }122 const el = {123 ...makeFakeElement(),124 getAttribute: at => {125 switch (at) {126 case 'type':127 return Promise.resolve('checkbox')128 case 'checked':129 return Promise.resolve('true')130 }131 }132 }133 global.browser.$ = () => Promise.resolve(el)134 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()135 })136 it('should reject assertCheckboxState command', () => {137 const c = {138 command: 'assertCheckboxState',139 parameters: {140 target: 'id=test',141 expected: false142 }143 }144 const el = {145 ...makeFakeElement(),146 getAttribute: at => {147 switch (at) {148 case 'type':149 return Promise.resolve('checkbox')150 case 'checked':151 return Promise.resolve(true)152 }153 }154 }155 global.browser.$ = () => Promise.resolve(el)156 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()157 })158 it('should run assertCheckboxState command for false', () => {159 const c = {160 command: 'assertCheckboxState',161 parameters: {162 target: 'id=test',163 expected: false164 }165 }166 const el = {167 ...makeFakeElement(),168 getAttribute: at => {169 switch (at) {170 case 'type':171 return Promise.resolve('checkbox')172 case 'checked':173 return Promise.resolve(null)174 }175 }176 }177 global.browser.$ = () => Promise.resolve(el)178 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()179 })180 it('should reject assertCheckboxState command (inverted)', () => {181 const c = {182 command: 'assertCheckboxState',183 parameters: {184 target: 'id=test',185 expected: true186 }187 }188 const el = {189 ...makeFakeElement(),190 getAttribute: at => {191 switch (at) {192 case 'type':193 return Promise.resolve('checkbox')194 case 'checked':195 return Promise.resolve(null)196 }197 }198 }199 global.browser.$ = () => Promise.resolve(el)200 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()201 })202 it('should handle non checkbox elements', () => {203 const c = {204 command: 'assertCheckboxState',205 parameters: {206 target: 'id=test',207 expected: true208 }209 }210 const el = {211 ...makeFakeElement()212 }213 global.browser.$ = () => Promise.resolve(el)214 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()215 })216 })217 describe('assertClassDoesNotExist', () => {218 it('should run assertClassDoesNotExist command', () => {219 const c = {220 command: 'assertClassDoesNotExist',221 parameters: {222 target: 'id=test',223 class: 'test-class'224 }225 }226 const el = {227 ...makeFakeElement(),228 getAttribute: () =>229 Promise.resolve('not-test-class another-fake-class')230 }231 global.browser.$ = () => Promise.resolve(el)232 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()233 })234 it('should reject assertClassDoesNotExist command', () => {235 const c = {236 command: 'assertClassDoesNotExist',237 parameters: {238 target: 'id=test',239 class: 'test-class'240 }241 }242 const el = {243 ...makeFakeElement(),244 getAttribute: () => Promise.resolve('test-class another-fake-class')245 }246 global.browser.$ = () => Promise.resolve(el)247 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()248 })249 })250 describe('assertClassExists', () => {251 it('should run assertClassExists command', () => {252 const c = {253 command: 'assertClassExists',254 parameters: {255 target: 'id=test',256 class: 'test-class'257 }258 }259 const el = {260 ...makeFakeElement(),261 getAttribute: () => Promise.resolve('test-class another-fake-class')262 }263 global.browser.$ = () => Promise.resolve(el)264 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()265 })266 it('should reject assertClassExists command', () => {267 const c = {268 command: 'assertClassExists',269 parameters: {270 target: 'id=test',271 class: 'test-class'272 }273 }274 const el = {275 ...makeFakeElement(),276 getAttribute: () =>277 Promise.resolve('not-test-class another-fake-class')278 }279 global.browser.$ = () => Promise.resolve(el)280 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()281 })282 })283 describe('assertElementPresent', () => {284 it('should run assertElementPresent command', () => {285 const c = {286 command: 'assertElementPresent',287 parameters: {288 target: 'id=test'289 }290 }291 global.browser.$ = () => Promise.resolve(makeFakeElement())292 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()293 })294 it('should run assertElementPresent command with custom timeout', () => {295 const c = {296 command: 'assertElementPresent',297 parameters: {298 target: 'id=test',299 timeout: '2000'300 }301 }302 global.browser.$ = () => Promise.resolve(makeFakeElement())303 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()304 })305 it('should reject assertElementPresent command', () => {306 const c = {307 command: 'assertElementPresent',308 parameters: {309 target: 'id=test'310 }311 }312 global.browser.$ = () => Promise.resolve(makeFakeElement(true))313 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()314 })315 })316 describe('assertElementNotPresent', () => {317 it('should run assertElementNotPresent command', () => {318 const c = {319 command: 'assertElementNotPresent',320 parameters: {321 target: 'id=test'322 }323 }324 global.browser.$ = () => Promise.resolve(makeFakeElement())325 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()326 })327 it('should run assertElementNotPresent command with custom timeout', () => {328 const c = {329 command: 'assertElementNotPresent',330 parameters: {331 target: 'id=test',332 timeout: '2000'333 }334 }335 global.browser.$ = () => Promise.resolve(makeFakeElement())336 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()337 })338 it('should reject assertElementNotPresent command', () => {339 const c = {340 command: 'assertElementNotPresent',341 parameters: {342 target: 'id=test'343 }344 }345 global.browser.$ = () => Promise.resolve(makeFakeElement(true))346 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()347 })348 })349 describe('assertElementVisible', () => {350 it('should run assertElementVisible command', () => {351 const c = {352 command: 'assertElementVisible',353 parameters: {354 target: 'id=test'355 }356 }357 global.browser.$ = () => Promise.resolve(makeFakeElement())358 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()359 })360 it('should run assertElementVisible command with custom timeout', () => {361 const c = {362 command: 'assertElementVisible',363 parameters: {364 target: 'id=test',365 timeout: '2000'366 }367 }368 global.browser.$ = () => Promise.resolve(makeFakeElement())369 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()370 })371 it('should reject assertElementVisible command', () => {372 const c = {373 command: 'assertElementVisible',374 parameters: {375 target: 'id=test'376 }377 }378 global.browser.$ = () => Promise.resolve(makeFakeElement(true))379 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()380 })381 })382 describe('assertElementNotVisible', () => {383 it('should run assertElementNotVisible command', () => {384 const c = {385 command: 'assertElementNotVisible',386 parameters: {387 target: 'id=test'388 }389 }390 global.browser.$ = () => Promise.resolve(makeFakeElement())391 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()392 })393 it('should run assertElementNotVisible command with custom timeout', () => {394 const c = {395 command: 'assertElementNotVisible',396 parameters: {397 target: 'id=test',398 timeout: '2000'399 }400 }401 global.browser.$ = () => Promise.resolve(makeFakeElement())402 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()403 })404 it('should reject assertElementNotVisible command', () => {405 const c = {406 command: 'assertElementNotVisible',407 parameters: {408 target: 'id=test'409 }410 }411 global.browser.$ = () => Promise.resolve(makeFakeElement(true))412 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()413 })414 })415 describe('assertLocalStorage', () => {416 it('should run assertLocalStorage command', () => {417 const c = {418 command: 'assertLocalStorage',419 parameters: {420 key: 'test',421 expected: 'testValue'422 }423 }424 global.browser.execute = s => Promise.resolve('testValue')425 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()426 })427 it('should reject assertLocalStorage command', () => {428 const c = {429 command: 'assertLocalStorage',430 parameters: {431 key: 'test',432 expected: 'testValue'433 }434 }435 global.browser.execute = s => Promise.reject(new Error('key not found'))436 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()437 })438 })439 describe('assertSessionStorage', () => {440 it('should run assertSessionStorage command', () => {441 const c = {442 command: 'assertSessionStorage',443 parameters: {444 key: 'test',445 expected: 'testValue'446 }447 }448 global.browser.execute = s => Promise.resolve('testValue')449 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()450 })451 it('should reject assertSessionStorage command', () => {452 const c = {453 command: 'assertSessionStorage',454 parameters: {455 key: 'test',456 expected: 'testValue'457 }458 }459 global.browser.execute = s => Promise.reject(new Error('key not found'))460 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()461 })462 })463 describe('assertStyle', () => {464 it('should run assertStyle command', () => {465 const c = {466 command: 'assertStyle',467 parameters: {468 target: 'id=test',469 property: 'height',470 expected: 'testValue'471 }472 }473 global.browser.$ = () => Promise.resolve(makeFakeElement())474 global.browser.execute = s => Promise.resolve('testValue')475 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()476 })477 it('should run assertStyle command for non id', () => {478 const c = {479 command: 'assertStyle',480 parameters: {481 target: 'css=testClass',482 property: 'height',483 expected: 'testValue'484 }485 }486 global.browser.$ = () => Promise.resolve(makeFakeElement())487 global.browser.execute = s => Promise.resolve('testValue')488 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()489 })490 it('should reject assertStyle command if execute has an error', () => {491 const c = {492 command: 'assertStyle',493 parameters: {494 target: 'id=test',495 expected: 'testValue'496 }497 }498 global.browser.$ = () => Promise.resolve(makeFakeElement())499 global.browser.execute = s => Promise.reject(new Error('cssError'))500 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()501 })502 it('should reject assertStyle command if property does not exist', () => {503 const c = {504 command: 'assertStyle',505 parameters: {506 target: 'id=test',507 expected: 'testValue'508 }509 }510 global.browser.$ = () => Promise.resolve(makeFakeElement())511 global.browser.execute = s => Promise.resolve(undefined)512 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()513 })514 it('should reject assertStyle command if values do not match', () => {515 const c = {516 command: 'assertStyle',517 parameters: {518 target: 'id=test',519 expected: 'testValue'520 }521 }522 global.browser.$ = () => Promise.resolve(makeFakeElement())523 global.browser.execute = s => Promise.resolve('notTestValue')524 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()525 })526 })527 describe('assertText', () => {528 it('should run assertText command', () => {529 const c = {530 command: 'assertText',531 parameters: {532 target: 'id=test',533 expected: 'testText'534 }535 }536 const el = {537 ...makeFakeElement(),538 getText: () => Promise.resolve('testText'),539 getValue: () => Promise.resolve('')540 }541 global.browser.$ = () => Promise.resolve(el)542 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()543 })544 it('should run assertText command with default expectation', () => {545 const c = {546 command: 'assertText',547 parameters: {548 target: 'id=test'549 }550 }551 const el = {552 ...makeFakeElement(),553 getText: () => Promise.resolve(''),554 getValue: () => Promise.resolve('')555 }556 global.browser.$ = () => Promise.resolve(el)557 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()558 })559 it('should reject assertText command if getText fails', () => {560 const c = {561 command: 'assertText',562 parameters: {563 target: 'id=test',564 expected: 'testText'565 }566 }567 const el = {568 ...makeFakeElement(),569 getText: () => Promise.reject(new Error('notTestText')),570 getValue: () => Promise.resolve('')571 }572 global.browser.$ = () => Promise.resolve(el)573 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()574 })575 it('should reject assertText command if getValue fails', () => {576 const c = {577 command: 'assertText',578 parameters: {579 target: 'id=test',580 expected: 'testText'581 }582 }583 const el = {584 ...makeFakeElement(),585 getText: () => Promise.resolve('testText'),586 getValue: () => Promise.reject(new Error('notTestText'))587 }588 global.browser.$ = () => Promise.resolve(el)589 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()590 })591 it('should run assertText command with regex', () => {592 const c = {593 command: 'assertText',594 parameters: {595 target: 'id=test',596 expected: '/\\d/'597 }598 }599 const el = {600 ...makeFakeElement(),601 getText: () => Promise.resolve('9'),602 getValue: () => Promise.resolve('')603 }604 global.browser.$ = () => Promise.resolve(el)605 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()606 })607 it('should run assertText command with regex and an input field', () => {608 const c = {609 command: 'assertText',610 parameters: {611 target: 'id=test',612 expected: '/\\d/'613 }614 }615 const el = {616 ...makeFakeElement(),617 getText: () => Promise.resolve(''),618 getValue: () => Promise.resolve('9')619 }620 global.browser.$ = () => Promise.resolve(el)621 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()622 })623 it('should reject assertText command with regex and an input field and both are empty', () => {624 const c = {625 command: 'assertText',626 parameters: {627 target: 'id=test',628 expected: '/\\d/'629 }630 }631 const el = {632 ...makeFakeElement(),633 getText: () => Promise.resolve(''),634 getValue: () => Promise.resolve('')635 }636 global.browser.$ = () => Promise.resolve(el)637 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()638 })639 })640 describe('assertTitle', () => {641 it('should run assertTitle command', () => {642 const c = {643 command: 'assertTitle',644 parameters: {645 expected: 'testTitle'646 }647 }648 global.browser.getTitle = () => Promise.resolve('testTitle')649 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()650 })651 it('should reject assertTitle command', () => {652 const c = {653 command: 'assertTitle',654 parameters: {655 expected: 'testTitle'656 }657 }658 global.browser.getTitle = () =>659 Promise.reject(new Error('notTestTitle'))660 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()661 })662 })663 describe('assertUrl', () => {664 it('should run assertUrl command', () => {665 const c = {666 command: 'assertUrl',667 parameters: {668 expected: 'https://example.com'669 }670 }671 global.browser.getUrl = () => Promise.resolve('https://example.com')672 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()673 })674 it('should reject assertUrl command', () => {675 const c = {676 command: 'assertUrl',677 parameters: {678 expected: 'https://example.com'679 }680 }681 global.browser.getUrl = () =>682 Promise.reject(new Error('http://potato.com'))683 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()684 })685 })686 describe('assertJsonInContext', () => {687 it('should assert string in context', () => {688 const c = {689 command: 'assertJsonInContext',690 parameters: {691 key: 'testJson',692 expected: 'test'693 }694 }695 const ctx = {696 testJson: 'test'697 }698 return expect(runCommand(c, ctx, 1000, hookMock)).resolves.toBeTruthy()699 })700 it('should assert json in context', () => {701 const c = {702 command: 'assertJsonInContext',703 parameters: {704 key: 'testJson',705 expected: { color: 'red' }706 }707 }708 const ctx = {709 testJson: { color: 'red' }710 }711 return expect(runCommand(c, ctx, 1000, hookMock)).resolves.toBeTruthy()712 })713 it('should assert string', () => {714 const c = {715 command: 'assertJsonInContext',716 parameters: {717 key: 'testJson',718 expected: 'test2'719 }720 }721 const ctx = {722 testJson: 'test'723 }724 return expect(runCommand(c, ctx, 1000, hookMock)).rejects.toBeDefined()725 })726 })727 describe('filterJsonInContext', () => {728 it('should run filterJsonInContext command', () => {729 const c = {730 command: 'filterJsonInContext',731 parameters: {732 key: 'testJson',733 resultKey: 'filteredJson'734 }735 }736 const ctx = {737 testJson: {738 apple: { type: 'pome', color: 'red' },739 orange: { type: 'citrus', color: 'orange' }740 }741 }742 return runCommand(c, ctx, 1000, hookMock).then(() =>743 expect(JSON.stringify(ctx.filteredJson)).toEqual(744 JSON.stringify({745 apple: { type: 'pome', color: 'red' },746 orange: { type: 'citrus', color: 'orange' }747 })748 )749 )750 })751 it('should locate intermediate node', () => {752 const c = {753 command: 'filterJsonInContext',754 parameters: {755 key: 'testJson',756 resultKey: 'filteredJson',757 locateNode: ['apple']758 }759 }760 const ctx = {761 testJson: {762 apple: { type: 'pome', color: 'red' },763 orange: { type: 'citrus', color: 'orange' }764 }765 }766 return runCommand(c, ctx, 1000, hookMock).then(() =>767 expect(JSON.stringify(ctx.filteredJson)).toEqual(768 JSON.stringify({ type: 'pome', color: 'red' })769 )770 )771 })772 it('should locate leaf node', () => {773 const c = {774 command: 'filterJsonInContext',775 parameters: {776 key: 'testJson',777 resultKey: 'filteredJson',778 locateNode: ['apple', 'type']779 }780 }781 const ctx = {782 testJson: {783 apple: { type: 'pome', color: 'red' },784 orange: { type: 'citrus', color: 'orange' }785 }786 }787 return runCommand(c, ctx, 1000, hookMock).then(() =>788 expect(ctx.filteredJson).toEqual('pome')789 )790 })791 it('should ignore nodes', () => {792 const c = {793 command: 'filterJsonInContext',794 parameters: {795 key: 'testJson',796 resultKey: 'filteredJson',797 deleteNodes: [['apple', 'type'], ['orange', 'color']]798 }799 }800 const ctx = {801 testJson: {802 apple: { type: 'pome', color: 'red' },803 orange: { type: 'citrus', color: 'orange' }804 }805 }806 return runCommand(c, ctx, 1000, hookMock).then(() =>807 expect(JSON.stringify(ctx.filteredJson)).toEqual(808 JSON.stringify({809 apple: { color: 'red' },810 orange: { type: 'citrus' }811 })812 )813 )814 })815 it('should locate node & ignore nodes', () => {816 const c = {817 command: 'filterJsonInContext',818 parameters: {819 key: 'testJson',820 resultKey: 'filteredJson',821 locateNode: ['apple'],822 deleteNodes: [['type']]823 }824 }825 const ctx = {826 testJson: {827 apple: { type: 'pome', color: 'red' },828 orange: { type: 'citrus', color: 'orange' }829 }830 }831 return runCommand(c, ctx, 1000, hookMock).then(() =>832 expect(JSON.stringify(ctx.filteredJson)).toEqual(833 JSON.stringify({ color: 'red' })834 )835 )836 })837 })838 })839 describe('COMMANDS', () => {840 describe('captureScreenshot', () => {841 it('should run captureScreenshot command', () => {842 const c = {843 command: 'captureScreenshot',844 parameters: {}845 }846 global.browser.takeScreenshot = () => Promise.resolve('test.jpg')847 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()848 })849 it('should reject captureScreenshot command', () => {850 const c = {851 command: 'captureScreenshot',852 parameters: {}853 }854 global.browser.takeScreenshot = () =>855 Promise.reject(new Error('fakeError'))856 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()857 })858 })859 describe('clearValue', () => {860 it('should run clearValue command', () => {861 const c = {862 command: 'clearValue',863 parameters: {864 target: 'id=test'865 }866 }867 const el = {868 ...makeFakeElement(),869 clearValue: v => Promise.resolve(true)870 }871 global.browser.$ = () => Promise.resolve(el)872 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()873 })874 it('should reject clearValue command if browser.clearValue fails', () => {875 const c = {876 command: 'clearValue',877 parameters: {878 target: 'id=test'879 }880 }881 const el = {882 ...makeFakeElement(),883 clearValue: () => Promise.reject(new Error('fakeError'))884 }885 global.browser.$ = () => Promise.resolve(el)886 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()887 })888 })889 describe('click', () => {890 it('should run click command', () => {891 const c = {892 command: 'click',893 parameters: {894 target: 'id=test'895 }896 }897 const el = {898 ...makeFakeElement(),899 click: () => Promise.resolve(true)900 }901 global.browser.$ = () => Promise.resolve(el)902 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()903 })904 it('should reject click command if click throws error', () => {905 const c = {906 command: 'click',907 parameters: {908 target: 'id=test'909 }910 }911 const el = {912 ...makeFakeElement(),913 click: () => Promise.reject(new Error('fakeError'))914 }915 global.browser.$ = () => Promise.resolve(el)916 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()917 })918 })919 describe('debug', () => {920 afterEach(() => {})921 it('should run debug command', () => {922 const c = {923 command: 'debug',924 parameters: {}925 }926 global.browser.debug = () => Promise.resolve(true)927 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()928 })929 it('should reject debug command if browser.debug fails', () => {930 const c = {931 command: 'debug',932 parameters: {}933 }934 global.browser.debug = () => Promise.reject(new Error('fakeError'))935 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()936 })937 })938 describe('deleteAllCookies', () => {939 it('should run deleteAllCookies command', () => {940 const c = {941 command: 'deleteAllCookies',942 parameters: {}943 }944 global.browser.deleteCookies = () => Promise.resolve(true)945 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()946 })947 it('should reject deleteAllCookies command', () => {948 const c = {949 command: 'deleteAllCookies',950 parameters: {}951 }952 global.browser.deleteCookies = () =>953 Promise.reject(new Error('fakeError'))954 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()955 })956 })957 describe('dragAndDropToObject', () => {958 it('should run dragAndDropToObject command', () => {959 const c = {960 command: 'dragAndDropToObject',961 parameters: {962 startTarget: 'id=test1',963 endTarget: 'id=test2'964 }965 }966 const el = {967 ...makeFakeElement(),968 dragAndDrop: () => Promise.resolve(true)969 }970 global.browser.$ = () => Promise.resolve(el)971 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()972 })973 it('should reject dragAndDropToObject command', () => {974 const c = {975 command: 'dragAndDropToObject',976 parameters: {977 startTarget: 'id=test1',978 endTarget: 'id=test2'979 }980 }981 const el = {982 ...makeFakeElement(),983 dragAndDrop: () => Promise.reject(new Error('fakeError'))984 }985 global.browser.$ = () => Promise.resolve(el)986 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()987 })988 })989 describe('http', () => {990 it('should run GET http command and store result in context', () => {991 fetchMock.get('testUrl', {992 testResponse: true993 })994 const c = {995 command: 'http',996 parameters: {997 url: 'testUrl',998 key: 'testKey'999 }1000 }1001 const ctx = {}1002 return runCommand(c, ctx, 1000, hookMock).then(() =>1003 expect(ctx.testKey.testResponse).toBe(true)1004 )1005 })1006 it('should run POST http command and store result in context', () => {1007 fetchMock.post('testUrl', {1008 testResponse: true1009 })1010 const c = {1011 command: 'http',1012 parameters: {1013 method: 'POST',1014 url: 'testUrl',1015 key: 'testKey',1016 body: {1017 key1: 'value1'1018 }1019 }1020 }1021 const ctx = {}1022 return runCommand(c, ctx, 1000, hookMock).then(() =>1023 expect(ctx.testKey.testResponse).toBe(true)1024 )1025 })1026 it('should reject command if fetch fails', () => {1027 fetchMock.get('testUrl', 500)1028 const c = {1029 command: 'http',1030 parameters: {1031 url: 'testUrl',1032 key: 'testKey',1033 body: {1034 key1: 'value1'1035 }1036 }1037 }1038 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1039 })1040 })1041 describe('mouseOver', () => {1042 it('should run mouseOver command', () => {1043 const c = {1044 command: 'mouseOver',1045 parameters: {1046 target: 'id=test'1047 }1048 }1049 const el = {1050 ...makeFakeElement(),1051 moveTo: () => Promise.resolve(true)1052 }1053 global.browser.$ = () => Promise.resolve(el)1054 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()1055 })1056 it('should reject mouseOver command', () => {1057 const c = {1058 command: 'mouseOver',1059 parameters: {1060 target: 'id=test'1061 }1062 }1063 const el = {1064 ...makeFakeElement(),1065 dragAndDrop: () => Promise.reject(new Error('fakeError'))1066 }1067 global.browser.$ = () => Promise.resolve(el)1068 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1069 })1070 })1071 describe('mouseEvent', () => {1072 it('should run mouseEvent command', () => {1073 const c = {1074 command: 'mouseEvent',1075 parameters: {1076 target: 'id=test'1077 }1078 }1079 const events = []1080 global.browser.execute = s => {1081 events.push(s)1082 return Promise.resolve(true)1083 }1084 global.browser.$ = () => Promise.resolve(makeFakeElement())1085 // return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()1086 return runCommand(c, {}, 1000, hookMock)1087 .then(() =>1088 expect(events[0]).toEqual(1089 'document.querySelector(\'id=test\').dispatchEvent(new MouseEvent("mouseover", { bubbles: true }))'1090 )1091 )1092 .then(() =>1093 expect(events[1]).toEqual(1094 'document.querySelector(\'id=test\').dispatchEvent(new MouseEvent("mousedown", { bubbles: true }))'1095 )1096 )1097 .then(() =>1098 expect(events[2]).toEqual(1099 'document.querySelector(\'id=test\').dispatchEvent(new MouseEvent("mouseup", { bubbles: true }))'1100 )1101 )1102 .then(() =>1103 expect(events[3]).toEqual(1104 'document.querySelector(\'id=test\').dispatchEvent(new MouseEvent("click", { bubbles: true }))'1105 )1106 )1107 })1108 it('should reject mouseEvent command if execute fails', () => {1109 const c = {1110 command: 'mouseEvent',1111 parameters: {1112 target: 'id=test'1113 }1114 }1115 global.browser.execute = s => Promise.reject(new Error('fakeError'))1116 global.browser.$ = () => Promise.resolve(makeFakeElement())1117 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1118 })1119 it('should reject mouseEvent command if waitForExist and waitForVisible fail', () => {1120 const c = {1121 command: 'mouseEvent',1122 parameters: {1123 target: 'id=test'1124 }1125 }1126 const events = []1127 global.browser.execute = s => {1128 events.push(s)1129 return Promise.resolve(true)1130 }1131 global.browser.$ = () => Promise.resolve(makeFakeElement(true))1132 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1133 })1134 it('should run mouseEvent command even if target doesnt have dispatchEvent', () => {1135 const c = {1136 command: 'mouseEvent',1137 parameters: {1138 target: 'id=test'1139 }1140 }1141 global.browser.execute = s =>1142 Promise.reject(1143 new Error("Cannot read property 'dispatchEvent' of null")1144 )1145 global.browser.$ = () => Promise.resolve(makeFakeElement())1146 return expect(1147 runCommand(c, {}, 1000, hookMock)1148 ).resolves.toBeUndefined()1149 })1150 it('should reject mouseEvent command if error is not about dispatchEvent', () => {1151 const c = {1152 command: 'mouseEvent',1153 parameters: {1154 target: 'id=test'1155 }1156 }1157 global.browser.execute = s => Promise.reject(new Error('fakeError'))1158 global.browser.$ = () => Promise.resolve(makeFakeElement())1159 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1160 })1161 })1162 describe('open', () => {1163 it('should run open command', () => {1164 const c = {1165 command: 'open',1166 parameters: {1167 url: 'https://example.com'1168 }1169 }1170 global.browser.url = () => Promise.resolve(true)1171 global.browser.pause = () => Promise.resolve(true)1172 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()1173 })1174 it('should reject open command if browser.url fails', () => {1175 const c = {1176 command: 'open',1177 parameters: {1178 url: 'https://example.com'1179 }1180 }1181 global.browser.url = () => Promise.reject(new Error('fakeError'))1182 global.browser.pause = () => Promise.resolve(true)1183 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1184 })1185 it('should reject open command if browser.pause fails', () => {1186 const c = {1187 command: 'open',1188 parameters: {1189 url: 'https://example.com'1190 }1191 }1192 global.browser.url = () => Promise.resolve(true)1193 global.browser.pause = () => Promise.reject(new Error('fakeError'))1194 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1195 })1196 })1197 describe('pause', () => {1198 it('should run pause command', () => {1199 const c = {1200 command: 'pause',1201 parameters: {1202 millis: 10001203 }1204 }1205 global.browser.pause = t => Promise.resolve(t)1206 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toEqual(1000)1207 })1208 it('should run pause command with default value if value is not a number', () => {1209 const c = {1210 command: 'pause',1211 parameters: {1212 millis: '{}'1213 }1214 }1215 global.browser.pause = t => Promise.resolve(t)1216 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toEqual(3000)1217 })1218 it('should reject pause command if browser.pause fails', () => {1219 const c = {1220 command: 'pause',1221 parameters: {1222 millis: 10001223 }1224 }1225 global.browser.pause = () => Promise.reject(new Error('fakeError'))1226 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1227 })1228 })1229 describe('refresh', () => {1230 it('should run refresh command', () => {1231 const c = {1232 command: 'refresh',1233 parameters: {}1234 }1235 global.browser.refresh = () => Promise.resolve(true)1236 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()1237 })1238 it('should reject refresh command if browser.refresh fails', () => {1239 const c = {1240 command: 'refresh',1241 parameters: {}1242 }1243 global.browser.refresh = () => Promise.reject(new Error('fakeError'))1244 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1245 })1246 })1247 describe('select', () => {1248 it('should run select command', () => {1249 const c = {1250 command: 'select',1251 parameters: {1252 target: 'id=test',1253 value: 'testText'1254 }1255 }1256 const el = {1257 ...makeFakeElement(),1258 selectByVisibleText: t => Promise.resolve(t)1259 }1260 global.browser.$ = () => Promise.resolve(el)1261 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toEqual(1262 'testText'1263 )1264 })1265 it('should run select command and replace label=', () => {1266 const c = {1267 command: 'select',1268 parameters: {1269 target: 'id=test',1270 value: 'label=testText'1271 }1272 }1273 const el = {1274 ...makeFakeElement(),1275 selectByVisibleText: t => Promise.resolve(t)1276 }1277 global.browser.$ = () => Promise.resolve(el)1278 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toEqual(1279 'testText'1280 )1281 })1282 it('should reject select command if browser.selectByVisibleText fails', () => {1283 const c = {1284 command: 'select',1285 parameters: {1286 target: 'id=test',1287 value: 'testText'1288 }1289 }1290 const el = {1291 ...makeFakeElement(),1292 selectByVisibleText: t => Promise.reject(new Error('fakeError'))1293 }1294 global.browser.$ = () => Promise.resolve(el)1295 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1296 })1297 })1298 describe('selectAndWait', () => {1299 it('should run selectAndWait command', () => {1300 const c = {1301 command: 'selectAndWait',1302 parameters: {1303 target: 'id=test',1304 value: 'testText'1305 }1306 }1307 const el = {1308 ...makeFakeElement(),1309 selectByVisibleText: t => Promise.resolve(t)1310 }1311 global.browser.$ = () => Promise.resolve(el)1312 global.browser.pause = () => Promise.resolve(true)1313 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()1314 })1315 it('should run selectAndWait command and replace label=', () => {1316 const c = {1317 command: 'selectAndWait',1318 parameters: {1319 target: 'id=test',1320 value: 'label=testText'1321 }1322 }1323 const el = {1324 ...makeFakeElement(),1325 selectByVisibleText: t => Promise.resolve(t)1326 }1327 global.browser.$ = () => Promise.resolve(el)1328 global.browser.pause = () => Promise.resolve(true)1329 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()1330 })1331 it('should reject selectAndWait command if browser.selectByVisibleText fails', () => {1332 const c = {1333 command: 'selectAndWait',1334 parameters: {1335 target: 'id=test',1336 value: 'testText'1337 }1338 }1339 const el = {1340 ...makeFakeElement(),1341 selectByVisibleText: t => Promise.reject(new Error('fakeError'))1342 }1343 global.browser.$ = () => Promise.resolve(el)1344 global.browser.pause = () => Promise.resolve(true)1345 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1346 })1347 it('should reject selectAndWait command if browser.pause fails', () => {1348 const c = {1349 command: 'selectAndWait',1350 parameters: {1351 target: 'id=test',1352 value: 'testText'1353 }1354 }1355 const el = {1356 ...makeFakeElement(),1357 selectByVisibleText: t => Promise.resolve(t)1358 }1359 global.browser.$ = () => Promise.resolve(el)1360 global.browser.pause = () => Promise.reject(new Error('fakeError'))1361 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1362 })1363 })1364 describe('selectFrame', () => {1365 it('should run selectFrame command with id', () => {1366 const c = {1367 command: 'selectFrame',1368 parameters: {1369 target: 'id=test'1370 }1371 }1372 global.browser.$ = () => Promise.resolve(makeFakeElement())1373 global.browser.switchToFrame = t => Promise.resolve(true)1374 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()1375 })1376 it('should run selectFrame with index', () => {1377 const c = {1378 command: 'selectFrame',1379 parameters: {1380 target: 'index=2'1381 }1382 }1383 global.browser.switchToFrame = t => Promise.resolve(true)1384 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()1385 })1386 it('should run selectFrame with relative', () => {1387 const c = {1388 command: 'selectFrame',1389 parameters: {1390 target: 'relative=top'1391 }1392 }1393 global.browser.switchToFrame = t => Promise.resolve(true)1394 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()1395 })1396 it('should reject selectFrame command if element cant be found', () => {1397 const c = {1398 command: 'selectFrame',1399 parameters: {1400 target: 'id=test'1401 }1402 }1403 global.browser.$ = () => Promise.resolve(makeFakeElement(true))1404 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1405 })1406 it('should reject selectFrame command if browser.switchToFrame fails', () => {1407 const c = {1408 command: 'selectFrame',1409 parameters: {1410 target: 'id=test'1411 }1412 }1413 global.browser.$ = () => Promise.resolve(makeFakeElement())1414 global.browser.switchToFrame = () =>1415 Promise.reject(new Error('fakeError'))1416 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1417 })1418 })1419 describe('setContext', () => {1420 it('should run setContext command', () => {1421 const c = {1422 command: 'setContext',1423 parameters: {1424 key: 'testKey',1425 value: 'testValue'1426 }1427 }1428 const ctx = {}1429 return runCommand(c, ctx, 1000, hookMock).then(() =>1430 expect(ctx.testKey).toEqual('testValue')1431 )1432 })1433 })1434 describe('setCookie', () => {1435 it('should run setCookie command', () => {1436 const c = {1437 command: 'setCookie',1438 parameters: {1439 name: 'cookieName',1440 value: 'cookieValue'1441 }1442 }1443 global.browser.setCookies = cookie => Promise.resolve(cookie)1444 return Promise.all([1445 expect(runCommand(c, {}, 1000, hookMock)).resolves.toHaveProperty(1446 'name',1447 'cookieName'1448 ),1449 expect(runCommand(c, {}, 1000, hookMock)).resolves.toHaveProperty(1450 'value',1451 'cookieValue'1452 ),1453 expect(runCommand(c, {}, 1000, hookMock)).resolves.toHaveProperty(1454 'domain',1455 '.example.com'1456 )1457 ])1458 })1459 it('should run setCookie command with custom domain', () => {1460 const c = {1461 command: 'setCookie',1462 parameters: {1463 name: 'cookieName',1464 value: 'cookieValue',1465 domain: 'potatoes'1466 }1467 }1468 global.browser.setCookies = cookie => Promise.resolve(cookie)1469 return Promise.all([1470 expect(runCommand(c, {}, 1000, hookMock)).resolves.toHaveProperty(1471 'name',1472 'cookieName'1473 ),1474 expect(runCommand(c, {}, 1000, hookMock)).resolves.toHaveProperty(1475 'value',1476 'cookieValue'1477 ),1478 expect(runCommand(c, {}, 1000, hookMock)).resolves.toHaveProperty(1479 'domain',1480 'potatoes'1481 )1482 ])1483 })1484 it('should reject setCookie command if browser.setCookies fails', () => {1485 const c = {1486 command: 'setCookie',1487 parameters: {1488 name: 'cookieName',1489 value: 'cookieValue'1490 }1491 }1492 global.browser.setCookies = () => Promise.reject(new Error('fakeError'))1493 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1494 })1495 })1496 describe('setEnvironment', () => {1497 it('should run setEnvironment command', () => {1498 const c = {1499 command: 'setEnvironment',1500 parameters: {1501 testKey: 'testValue',1502 testKey2: 'testValue2'1503 }1504 }1505 const ctx = {}1506 return runCommand(c, ctx, 1000, hookMock)1507 .then(() => expect(ctx.testKey).toEqual('testValue'))1508 .then(() => expect(ctx.testKey2).toEqual('testValue2'))1509 })1510 })1511 describe('setLocalStorage', () => {1512 it('should run setLocalStorage command', () => {1513 const c = {1514 command: 'setLocalStorage',1515 parameters: {1516 key: 'testKey',1517 value: 'testValue'1518 }1519 }1520 global.browser.execute = () => Promise.resolve(true)1521 global.browser.refresh = () => Promise.resolve(true)1522 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()1523 })1524 it('should reject setLocalStorage command if browser.sessionStorage fails', () => {1525 const c = {1526 command: 'setLocalStorage',1527 parameters: {1528 key: 'testKey',1529 value: 'testValue'1530 }1531 }1532 global.browser.execute = () => Promise.reject(new Error('fakeError'))1533 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1534 })1535 })1536 describe('setSession', () => {1537 it('should run setSession command', () => {1538 const c = {1539 command: 'setSession',1540 parameters: {1541 key: 'testKey',1542 value: 'testValue'1543 }1544 }1545 global.browser.execute = () => Promise.resolve(true)1546 global.browser.refresh = () => Promise.resolve(true)1547 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()1548 })1549 it('should reject setSession command if browser.sessionStorage fails', () => {1550 const c = {1551 command: 'setSession',1552 parameters: {1553 key: 'testKey',1554 value: 'testValue'1555 }1556 }1557 global.browser.execute = () => Promise.reject(new Error('fakeError'))1558 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1559 })1560 })1561 describe('storeValue', () => {1562 it('should run storeValue command for text node', () => {1563 const c = {1564 command: 'storeValue',1565 parameters: {1566 target: 'id=potato',1567 key: 'potatoes'1568 }1569 }1570 const el = {1571 ...makeFakeElement(),1572 getText: () => Promise.resolve('yams'),1573 getValue: () => Promise.resolve('')1574 }1575 global.browser.$ = () => Promise.resolve(el)1576 const ctx = {}1577 return runCommand(c, ctx, 1000, hookMock).then(() =>1578 expect(ctx.potatoes).toEqual('yams')1579 )1580 })1581 it('should run storeValue command for input node', () => {1582 const c = {1583 command: 'storeValue',1584 parameters: {1585 target: 'id=potato',1586 key: 'potatoes'1587 }1588 }1589 const el = {1590 ...makeFakeElement(),1591 getText: () => Promise.resolve(''),1592 getValue: () => Promise.resolve('yams')1593 }1594 global.browser.$ = () => Promise.resolve(el)1595 const ctx = {}1596 return runCommand(c, ctx, 1000, hookMock).then(() =>1597 expect(ctx.potatoes).toEqual('yams')1598 )1599 })1600 it('should run storeValue command for input node and default text to empty string', () => {1601 const c = {1602 command: 'storeValue',1603 parameters: {1604 target: 'id=potato',1605 key: 'potatoes'1606 }1607 }1608 const el = {1609 ...makeFakeElement(),1610 getText: () => Promise.resolve(''),1611 getValue: () => Promise.resolve('')1612 }1613 global.browser.$ = () => Promise.resolve(el)1614 const ctx = {}1615 return runCommand(c, ctx, 1000, hookMock).then(() =>1616 expect(ctx.potatoes).toEqual('')1617 )1618 })1619 it('should reject storeValue command if browser.getText fails', () => {1620 const c = {1621 command: 'storeValue',1622 parameters: {1623 target: 'id=potato',1624 key: 'potatoes'1625 }1626 }1627 global.browser.waitForVisible = (s, t) => Promise.resolve(true)1628 global.browser.waitForExist = (s, t) => Promise.resolve(true)1629 global.browser.getText = () => Promise.reject(new Error('fakeError'))1630 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1631 })1632 })1633 describe('type', () => {1634 it('should run type command', () => {1635 const c = {1636 command: 'type',1637 parameters: {1638 target: 'id=test',1639 value: 'testValue'1640 }1641 }1642 const el = {1643 ...makeFakeElement(),1644 setValue: v => Promise.resolve(v)1645 }1646 global.browser.$ = () => Promise.resolve(el)1647 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toEqual(1648 'testValue'1649 )1650 })1651 it('should reject type command if browser.setValue fails', () => {1652 const c = {1653 command: 'type',1654 parameters: {1655 target: 'id=test',1656 value: 'testValue'1657 }1658 }1659 const el = {1660 ...makeFakeElement(),1661 setValue: () => Promise.reject(new Error('fakeError'))1662 }1663 global.browser.$ = () => Promise.resolve(el)1664 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1665 })1666 })1667 describe('Comment', () => {1668 it('should run comment command', () => {1669 const c = {1670 command: 'comment',1671 parameters: {1672 comment: 'Potato vs Superman'1673 }1674 }1675 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()1676 })1677 })1678 describe('assertTableExists', () => {1679 it('should run assertTableNotEmpty command', () => {1680 const c = {1681 command: 'assertTableNotEmpty',1682 parameters: {1683 target: 'id=test'1684 }1685 }1686 const el = {1687 ...makeFakeElement(),1688 getText: () => Promise.resolve('testHeader'),1689 getValue: () => Promise.resolve('')1690 }1691 const el1 = {1692 ...makeFakeElement(),1693 getText: () => Promise.resolve('testRow'),1694 getValue: () => Promise.resolve('')1695 }1696 global.browser.$$ = selector => {1697 if (selector.includes('th')) return Promise.resolve([el, el])1698 else return Promise.resolve([el1, el1])1699 }1700 global.browser.$ = () => Promise.resolve(makeFakeElement())1701 return expect(runCommand(c, {}, 1000, hookMock)).resolves.toBeTruthy()1702 })1703 it('should reject assertTableNotEmpty command', () => {1704 const c = {1705 command: 'assertTableNotEmpty',1706 parameters: {1707 target: 'id=test'1708 }1709 }1710 const el = {1711 ...makeFakeElement(),1712 getText: () => Promise.resolve(''),1713 getValue: () => Promise.resolve('')1714 }1715 global.browser.$$ = () => Promise.resolve([el, el])1716 global.browser.$ = () => Promise.resolve(makeFakeElement(true))1717 return expect(runCommand(c, {}, 1000, hookMock)).rejects.toBeDefined()1718 })1719 })1720 })...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1import React, { Component } from "react";2import Terminal from "terminal-in-react-quick123";3import RedisCommand from "@/utils/RedisCommand";4import intl from "react-intl-universal";5/**6 * 终端7 */8class HostTerminal extends Component {9 state = { redis: undefined };10 componentDidMount() {11 let redis = this.props.node.redis;12 this.setState({ redis: redis });13 }14 render() {15 return (16 <div>17 <Terminal18 color="#002766"19 backgroundColor="#fff"20 barColor="#002766"21 prompt="#002766"22 promptSymbol=">"23 style={{24 fontWeight: "bold",25 fontSize: "16px",26 fontFamily: "Courier New",27 paddingLeft: "20px",28 paddingRight: "20px",29 height: "90vh",30 // width: "90vw",31 }}32 commands={{33 append: (args, print, runCommand) => {34 RedisCommand.invoke(this.state.redis, print, args);35 },36 asking: (args, print, runCommand) => {37 RedisCommand.invoke(this.state.redis, print, args);38 },39 bgrewriteaof: (args, print, runCommand) => {40 RedisCommand.invoke(this.state.redis, print, args);41 },42 bgsave: (args, print, runCommand) => {43 RedisCommand.invoke(this.state.redis, print, args);44 },45 bitcount: (args, print, runCommand) => {46 RedisCommand.invoke(this.state.redis, print, args);47 },48 bitfield: (args, print, runCommand) => {49 RedisCommand.invoke(this.state.redis, print, args);50 },51 bitop: (args, print, runCommand) => {52 RedisCommand.invoke(this.state.redis, print, args);53 },54 bitpos: (args, print, runCommand) => {55 RedisCommand.invoke(this.state.redis, print, args);56 },57 blpop: (args, print, runCommand) => {58 RedisCommand.invoke(this.state.redis, print, args);59 },60 brpop: (args, print, runCommand) => {61 RedisCommand.invoke(this.state.redis, print, args);62 },63 brpoplpush: (args, print, runCommand) => {64 RedisCommand.invoke(this.state.redis, print, args);65 },66 bzpopmax: (args, print, runCommand) => {67 RedisCommand.invoke(this.state.redis, print, args);68 },69 bzpopmin: (args, print, runCommand) => {70 RedisCommand.invoke(this.state.redis, print, args);71 },72 client: (args, print, runCommand) => {73 RedisCommand.invoke(this.state.redis, print, args);74 },75 cluster: (args, print, runCommand) => {76 RedisCommand.invoke(this.state.redis, print, args);77 },78 command: (args, print, runCommand) => {79 RedisCommand.invoke(this.state.redis, print, args);80 },81 config: (args, print, runCommand) => {82 RedisCommand.invoke(this.state.redis, print, args);83 },84 dbsize: (args, print, runCommand) => {85 RedisCommand.invoke(this.state.redis, print, args);86 },87 debug: (args, print, runCommand) => {88 RedisCommand.invoke(this.state.redis, print, args);89 },90 decr: (args, print, runCommand) => {91 RedisCommand.invoke(this.state.redis, print, args);92 },93 decrby: (args, print, runCommand) => {94 RedisCommand.invoke(this.state.redis, print, args);95 },96 del: (args, print, runCommand) => {97 RedisCommand.invoke(this.state.redis, print, args);98 },99 discard: (args, print, runCommand) => {100 RedisCommand.invoke(this.state.redis, print, args);101 },102 dump: (args, print, runCommand) => {103 RedisCommand.invoke(this.state.redis, print, args);104 },105 echo: (args, print, runCommand) => {106 RedisCommand.invoke(this.state.redis, print, args);107 },108 eval: (args, print, runCommand) => {109 RedisCommand.invoke(this.state.redis, print, args);110 },111 evalsha: (args, print, runCommand) => {112 RedisCommand.invoke(this.state.redis, print, args);113 },114 exec: (args, print, runCommand) => {115 RedisCommand.invoke(this.state.redis, print, args);116 },117 exists: (args, print, runCommand) => {118 RedisCommand.invoke(this.state.redis, print, args);119 },120 expire: (args, print, runCommand) => {121 RedisCommand.invoke(this.state.redis, print, args);122 },123 expireat: (args, print, runCommand) => {124 RedisCommand.invoke(this.state.redis, print, args);125 },126 flushall: (args, print, runCommand) => {127 RedisCommand.invoke(this.state.redis, print, args);128 },129 flushdb: (args, print, runCommand) => {130 RedisCommand.invoke(this.state.redis, print, args);131 },132 geoadd: (args, print, runCommand) => {133 RedisCommand.invoke(this.state.redis, print, args);134 },135 geodist: (args, print, runCommand) => {136 RedisCommand.invoke(this.state.redis, print, args);137 },138 geohash: (args, print, runCommand) => {139 RedisCommand.invoke(this.state.redis, print, args);140 },141 geopos: (args, print, runCommand) => {142 RedisCommand.invoke(this.state.redis, print, args);143 },144 georadius: (args, print, runCommand) => {145 RedisCommand.invoke(this.state.redis, print, args);146 },147 georadius_ro: (args, print, runCommand) => {148 RedisCommand.invoke(this.state.redis, print, args);149 },150 georadiusbymember: (args, print, runCommand) => {151 RedisCommand.invoke(this.state.redis, print, args);152 },153 georadiusbymember_ro: (args, print, runCommand) => {154 RedisCommand.invoke(this.state.redis, print, args);155 },156 get: (args, print, runCommand) => {157 RedisCommand.invoke(this.state.redis, print, args);158 },159 getbit: (args, print, runCommand) => {160 RedisCommand.invoke(this.state.redis, print, args);161 },162 getrange: (args, print, runCommand) => {163 RedisCommand.invoke(this.state.redis, print, args);164 },165 getset: (args, print, runCommand) => {166 RedisCommand.invoke(this.state.redis, print, args);167 },168 hdel: (args, print, runCommand) => {169 RedisCommand.invoke(this.state.redis, print, args);170 },171 hexists: (args, print, runCommand) => {172 RedisCommand.invoke(this.state.redis, print, args);173 },174 hget: (args, print, runCommand) => {175 RedisCommand.invoke(this.state.redis, print, args);176 },177 hgetall: (args, print, runCommand) => {178 RedisCommand.invoke(this.state.redis, print, args);179 },180 hincrby: (args, print, runCommand) => {181 RedisCommand.invoke(this.state.redis, print, args);182 },183 hincrbyfloat: (args, print, runCommand) => {184 RedisCommand.invoke(this.state.redis, print, args);185 },186 hkeys: (args, print, runCommand) => {187 RedisCommand.invoke(this.state.redis, print, args);188 },189 hlen: (args, print, runCommand) => {190 RedisCommand.invoke(this.state.redis, print, args);191 },192 hmget: (args, print, runCommand) => {193 RedisCommand.invoke(this.state.redis, print, args);194 },195 hmset: (args, print, runCommand) => {196 RedisCommand.invoke(this.state.redis, print, args);197 },198 hscan: (args, print, runCommand) => {199 RedisCommand.invoke(this.state.redis, print, args);200 },201 hset: (args, print, runCommand) => {202 RedisCommand.invoke(this.state.redis, print, args);203 },204 hsetnx: (args, print, runCommand) => {205 RedisCommand.invoke(this.state.redis, print, args);206 },207 hstrlen: (args, print, runCommand) => {208 RedisCommand.invoke(this.state.redis, print, args);209 },210 hvals: (args, print, runCommand) => {211 RedisCommand.invoke(this.state.redis, print, args);212 },213 incr: (args, print, runCommand) => {214 RedisCommand.invoke(this.state.redis, print, args);215 },216 incrby: (args, print, runCommand) => {217 RedisCommand.invoke(this.state.redis, print, args);218 },219 incrbyfloat: (args, print, runCommand) => {220 RedisCommand.invoke(this.state.redis, print, args);221 },222 info: (args, print, runCommand) => {223 RedisCommand.invoke(this.state.redis, print, args);224 },225 keys: (args, print, runCommand) => {226 RedisCommand.invoke(this.state.redis, print, args);227 },228 lastsave: (args, print, runCommand) => {229 RedisCommand.invoke(this.state.redis, print, args);230 },231 latency: (args, print, runCommand) => {232 RedisCommand.invoke(this.state.redis, print, args);233 },234 lindex: (args, print, runCommand) => {235 RedisCommand.invoke(this.state.redis, print, args);236 },237 linsert: (args, print, runCommand) => {238 RedisCommand.invoke(this.state.redis, print, args);239 },240 llen: (args, print, runCommand) => {241 RedisCommand.invoke(this.state.redis, print, args);242 },243 lolwut: (args, print, runCommand) => {244 RedisCommand.invoke(this.state.redis, print, args);245 },246 lpop: (args, print, runCommand) => {247 RedisCommand.invoke(this.state.redis, print, args);248 },249 lpush: (args, print, runCommand) => {250 RedisCommand.invoke(this.state.redis, print, args);251 },252 lpushx: (args, print, runCommand) => {253 RedisCommand.invoke(this.state.redis, print, args);254 },255 lrange: (args, print, runCommand) => {256 RedisCommand.invoke(this.state.redis, print, args);257 },258 lrem: (args, print, runCommand) => {259 RedisCommand.invoke(this.state.redis, print, args);260 },261 lset: (args, print, runCommand) => {262 RedisCommand.invoke(this.state.redis, print, args);263 },264 ltrim: (args, print, runCommand) => {265 RedisCommand.invoke(this.state.redis, print, args);266 },267 memory: (args, print, runCommand) => {268 RedisCommand.invoke(this.state.redis, print, args);269 },270 mget: (args, print, runCommand) => {271 RedisCommand.invoke(this.state.redis, print, args);272 },273 migrate: (args, print, runCommand) => {274 RedisCommand.invoke(this.state.redis, print, args);275 },276 module: (args, print, runCommand) => {277 RedisCommand.invoke(this.state.redis, print, args);278 },279 monitor: (args, print, runCommand) => {280 RedisCommand.invoke(this.state.redis, print, args);281 },282 move: (args, print, runCommand) => {283 RedisCommand.invoke(this.state.redis, print, args);284 },285 mset: (args, print, runCommand) => {286 RedisCommand.invoke(this.state.redis, print, args);287 },288 msetnx: (args, print, runCommand) => {289 RedisCommand.invoke(this.state.redis, print, args);290 },291 multi: (args, print, runCommand) => {292 RedisCommand.invoke(this.state.redis, print, args);293 },294 object: (args, print, runCommand) => {295 RedisCommand.invoke(this.state.redis, print, args);296 },297 persist: (args, print, runCommand) => {298 RedisCommand.invoke(this.state.redis, print, args);299 },300 pexpire: (args, print, runCommand) => {301 RedisCommand.invoke(this.state.redis, print, args);302 },303 pexpireat: (args, print, runCommand) => {304 RedisCommand.invoke(this.state.redis, print, args);305 },306 pfadd: (args, print, runCommand) => {307 RedisCommand.invoke(this.state.redis, print, args);308 },309 pfcount: (args, print, runCommand) => {310 RedisCommand.invoke(this.state.redis, print, args);311 },312 pfdebug: (args, print, runCommand) => {313 RedisCommand.invoke(this.state.redis, print, args);314 },315 pfmerge: (args, print, runCommand) => {316 RedisCommand.invoke(this.state.redis, print, args);317 },318 pfselftest: (args, print, runCommand) => {319 RedisCommand.invoke(this.state.redis, print, args);320 },321 ping: (args, print, runCommand) => {322 RedisCommand.invoke(this.state.redis, print, args);323 },324 post: (args, print, runCommand) => {325 RedisCommand.invoke(this.state.redis, print, args);326 },327 psetex: (args, print, runCommand) => {328 RedisCommand.invoke(this.state.redis, print, args);329 },330 psubscribe: (args, print, runCommand) => {331 RedisCommand.invoke(this.state.redis, print, args);332 },333 psync: (args, print, runCommand) => {334 RedisCommand.invoke(this.state.redis, print, args);335 },336 pttl: (args, print, runCommand) => {337 RedisCommand.invoke(this.state.redis, print, args);338 },339 publish: (args, print, runCommand) => {340 RedisCommand.invoke(this.state.redis, print, args);341 },342 pubsub: (args, print, runCommand) => {343 RedisCommand.invoke(this.state.redis, print, args);344 },345 punsubscribe: (args, print, runCommand) => {346 RedisCommand.invoke(this.state.redis, print, args);347 },348 randomkey: (args, print, runCommand) => {349 RedisCommand.invoke(this.state.redis, print, args);350 },351 readonly: (args, print, runCommand) => {352 RedisCommand.invoke(this.state.redis, print, args);353 },354 readwrite: (args, print, runCommand) => {355 RedisCommand.invoke(this.state.redis, print, args);356 },357 rename: (args, print, runCommand) => {358 RedisCommand.invoke(this.state.redis, print, args);359 },360 renamenx: (args, print, runCommand) => {361 RedisCommand.invoke(this.state.redis, print, args);362 },363 replconf: (args, print, runCommand) => {364 RedisCommand.invoke(this.state.redis, print, args);365 },366 replicaof: (args, print, runCommand) => {367 RedisCommand.invoke(this.state.redis, print, args);368 },369 restore: (args, print, runCommand) => {370 RedisCommand.invoke(this.state.redis, print, args);371 },372 role: (args, print, runCommand) => {373 RedisCommand.invoke(this.state.redis, print, args);374 },375 rpop: (args, print, runCommand) => {376 RedisCommand.invoke(this.state.redis, print, args);377 },378 rpoplpush: (args, print, runCommand) => {379 RedisCommand.invoke(this.state.redis, print, args);380 },381 rpush: (args, print, runCommand) => {382 RedisCommand.invoke(this.state.redis, print, args);383 },384 rpushx: (args, print, runCommand) => {385 RedisCommand.invoke(this.state.redis, print, args);386 },387 sadd: (args, print, runCommand) => {388 RedisCommand.invoke(this.state.redis, print, args);389 },390 save: (args, print, runCommand) => {391 RedisCommand.invoke(this.state.redis, print, args);392 },393 scan: (args, print, runCommand) => {394 RedisCommand.invoke(this.state.redis, print, args);395 },396 scard: (args, print, runCommand) => {397 RedisCommand.invoke(this.state.redis, print, args);398 },399 script: (args, print, runCommand) => {400 RedisCommand.invoke(this.state.redis, print, args);401 },402 sdiff: (args, print, runCommand) => {403 RedisCommand.invoke(this.state.redis, print, args);404 },405 sdiffstore: (args, print, runCommand) => {406 RedisCommand.invoke(this.state.redis, print, args);407 },408 select: (args, print, runCommand) => {409 RedisCommand.invoke(this.state.redis, print, args);410 },411 set: (args, print, runCommand) => {412 RedisCommand.invoke(this.state.redis, print, args);413 },414 setbit: (args, print, runCommand) => {415 RedisCommand.invoke(this.state.redis, print, args);416 },417 setex: (args, print, runCommand) => {418 RedisCommand.invoke(this.state.redis, print, args);419 },420 setnx: (args, print, runCommand) => {421 RedisCommand.invoke(this.state.redis, print, args);422 },423 setrange: (args, print, runCommand) => {424 RedisCommand.invoke(this.state.redis, print, args);425 },426 shutdown: (args, print, runCommand) => {427 RedisCommand.invoke(this.state.redis, print, args);428 },429 sinter: (args, print, runCommand) => {430 RedisCommand.invoke(this.state.redis, print, args);431 },432 sinterstore: (args, print, runCommand) => {433 RedisCommand.invoke(this.state.redis, print, args);434 },435 sismember: (args, print, runCommand) => {436 RedisCommand.invoke(this.state.redis, print, args);437 },438 slaveof: (args, print, runCommand) => {439 RedisCommand.invoke(this.state.redis, print, args);440 },441 slowlog: (args, print, runCommand) => {442 RedisCommand.invoke(this.state.redis, print, args);443 },444 smembers: (args, print, runCommand) => {445 RedisCommand.invoke(this.state.redis, print, args);446 },447 smove: (args, print, runCommand) => {448 RedisCommand.invoke(this.state.redis, print, args);449 },450 sort: (args, print, runCommand) => {451 RedisCommand.invoke(this.state.redis, print, args);452 },453 spop: (args, print, runCommand) => {454 RedisCommand.invoke(this.state.redis, print, args);455 },456 srandmember: (args, print, runCommand) => {457 RedisCommand.invoke(this.state.redis, print, args);458 },459 srem: (args, print, runCommand) => {460 RedisCommand.invoke(this.state.redis, print, args);461 },462 sscan: (args, print, runCommand) => {463 RedisCommand.invoke(this.state.redis, print, args);464 },465 strlen: (args, print, runCommand) => {466 RedisCommand.invoke(this.state.redis, print, args);467 },468 subscribe: (args, print, runCommand) => {469 RedisCommand.invoke(this.state.redis, print, args);470 },471 substr: (args, print, runCommand) => {472 RedisCommand.invoke(this.state.redis, print, args);473 },474 sunion: (args, print, runCommand) => {475 RedisCommand.invoke(this.state.redis, print, args);476 },477 sunionstore: (args, print, runCommand) => {478 RedisCommand.invoke(this.state.redis, print, args);479 },480 swapdb: (args, print, runCommand) => {481 RedisCommand.invoke(this.state.redis, print, args);482 },483 sync: (args, print, runCommand) => {484 RedisCommand.invoke(this.state.redis, print, args);485 },486 time: (args, print, runCommand) => {487 RedisCommand.invoke(this.state.redis, print, args);488 },489 touch: (args, print, runCommand) => {490 RedisCommand.invoke(this.state.redis, print, args);491 },492 ttl: (args, print, runCommand) => {493 RedisCommand.invoke(this.state.redis, print, args);494 },495 type: (args, print, runCommand) => {496 RedisCommand.invoke(this.state.redis, print, args);497 },498 unlink: (args, print, runCommand) => {499 RedisCommand.invoke(this.state.redis, print, args);500 },501 unsubscribe: (args, print, runCommand) => {502 RedisCommand.invoke(this.state.redis, print, args);503 },504 unwatch: (args, print, runCommand) => {505 RedisCommand.invoke(this.state.redis, print, args);506 },507 wait: (args, print, runCommand) => {508 RedisCommand.invoke(this.state.redis, print, args);509 },510 watch: (args, print, runCommand) => {511 RedisCommand.invoke(this.state.redis, print, args);512 },513 xack: (args, print, runCommand) => {514 RedisCommand.invoke(this.state.redis, print, args);515 },516 xadd: (args, print, runCommand) => {517 RedisCommand.invoke(this.state.redis, print, args);518 },519 xclaim: (args, print, runCommand) => {520 RedisCommand.invoke(this.state.redis, print, args);521 },522 xdel: (args, print, runCommand) => {523 RedisCommand.invoke(this.state.redis, print, args);524 },525 xgroup: (args, print, runCommand) => {526 RedisCommand.invoke(this.state.redis, print, args);527 },528 xinfo: (args, print, runCommand) => {529 RedisCommand.invoke(this.state.redis, print, args);530 },531 xlen: (args, print, runCommand) => {532 RedisCommand.invoke(this.state.redis, print, args);533 },534 xpending: (args, print, runCommand) => {535 RedisCommand.invoke(this.state.redis, print, args);536 },537 xrange: (args, print, runCommand) => {538 RedisCommand.invoke(this.state.redis, print, args);539 },540 xread: (args, print, runCommand) => {541 RedisCommand.invoke(this.state.redis, print, args);542 },543 xreadgroup: (args, print, runCommand) => {544 RedisCommand.invoke(this.state.redis, print, args);545 },546 xrevrange: (args, print, runCommand) => {547 RedisCommand.invoke(this.state.redis, print, args);548 },549 xsetid: (args, print, runCommand) => {550 RedisCommand.invoke(this.state.redis, print, args);551 },552 xtrim: (args, print, runCommand) => {553 RedisCommand.invoke(this.state.redis, print, args);554 },555 zadd: (args, print, runCommand) => {556 RedisCommand.invoke(this.state.redis, print, args);557 },558 zcard: (args, print, runCommand) => {559 RedisCommand.invoke(this.state.redis, print, args);560 },561 zcount: (args, print, runCommand) => {562 RedisCommand.invoke(this.state.redis, print, args);563 },564 zincrby: (args, print, runCommand) => {565 RedisCommand.invoke(this.state.redis, print, args);566 },567 zinterstore: (args, print, runCommand) => {568 RedisCommand.invoke(this.state.redis, print, args);569 },570 zlexcount: (args, print, runCommand) => {571 RedisCommand.invoke(this.state.redis, print, args);572 },573 zpopmax: (args, print, runCommand) => {574 RedisCommand.invoke(this.state.redis, print, args);575 },576 zpopmin: (args, print, runCommand) => {577 RedisCommand.invoke(this.state.redis, print, args);578 },579 zrange: (args, print, runCommand) => {580 RedisCommand.invoke(this.state.redis, print, args);581 },582 zrangebylex: (args, print, runCommand) => {583 RedisCommand.invoke(this.state.redis, print, args);584 },585 zrangebyscore: (args, print, runCommand) => {586 RedisCommand.invoke(this.state.redis, print, args);587 },588 zrank: (args, print, runCommand) => {589 RedisCommand.invoke(this.state.redis, print, args);590 },591 zrem: (args, print, runCommand) => {592 RedisCommand.invoke(this.state.redis, print, args);593 },594 zremrangebylex: (args, print, runCommand) => {595 RedisCommand.invoke(this.state.redis, print, args);596 },597 zremrangebyrank: (args, print, runCommand) => {598 RedisCommand.invoke(this.state.redis, print, args);599 },600 zremrangebyscore: (args, print, runCommand) => {601 RedisCommand.invoke(this.state.redis, print, args);602 },603 zrevrange: (args, print, runCommand) => {604 RedisCommand.invoke(this.state.redis, print, args);605 },606 zrevrangebylex: (args, print, runCommand) => {607 RedisCommand.invoke(this.state.redis, print, args);608 },609 zrevrangebyscore: (args, print, runCommand) => {610 RedisCommand.invoke(this.state.redis, print, args);611 },612 zrevrank: (args, print, runCommand) => {613 RedisCommand.invoke(this.state.redis, print, args);614 },615 zscan: (args, print, runCommand) => {616 RedisCommand.invoke(this.state.redis, print, args);617 },618 zscore: (args, print, runCommand) => {619 RedisCommand.invoke(this.state.redis, print, args);620 },621 zunionstore: (args, print, runCommand) => {622 RedisCommand.invoke(this.state.redis, print, args);623 },624 }}625 commandPassThrough={(cmd) =>626 `(error) ERR unknown command '${cmd}'`627 }628 descriptions={{629 show: false,630 append: "usage: append key value",631 asking: "",632 bgrewriteaof: "usage: bgrewriteaof ",633 bgsave: "usage: bgsave [SCHEDULE]",634 bitcount: "usage: bitcount key [start end]",635 bitfield:636 "usage: bitfield key [GET type offset] [SET type offset value] [INCRBY type offset increment] [OVERFLOW WRAP|SAT|FAIL]",637 bitop: "usage: bitop operation destkey key [key ...]",638 bitpos: "usage: bitpos key bit [start] [end]",639 blpop: "usage: blpop key [key ...] timeout",640 brpop: "usage: brpop key [key ...] timeout",641 brpoplpush:642 "usage: brpoplpush source destination timeout",643 bzpopmax: "usage: bzpopmax key [key ...] timeout",644 bzpopmin: "usage: bzpopmin key [key ...] timeout",645 client: "",646 cluster: "",647 command: "usage: command ",648 config: "",649 dbsize: "usage: dbsize ",650 debug: "",651 decr: "usage: decr key",652 decrby: "usage: decrby key decrement",653 del: "usage: del key [key ...]",654 discard: "usage: discard ",655 dump: "usage: dump key",656 echo: "usage: echo message",657 eval:658 "usage: eval script numkeys key [key ...] arg [arg ...]",659 evalsha:660 "usage: evalsha sha1 numkeys key [key ...] arg [arg ...]",661 exec: "usage: exec ",662 exists: "usage: exists key [key ...]",663 expire: "usage: expire key seconds",664 expireat: "usage: expireat key timestamp",665 flushall: "usage: flushall [ASYNC]",666 flushdb: "usage: flushdb [ASYNC]",667 geoadd:668 "usage: geoadd key longitude latitude member [longitude latitude member ...]",669 geodist:670 "usage: geodist key member1 member2 [m|km|ft|mi]",671 geohash: "usage: geohash key member [member ...]",672 geopos: "usage: geopos key member [member ...]",673 georadius:674 "usage: georadius key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key]",675 georadius_ro: "",676 georadiusbymember:677 "usage: georadiusbymember key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key]",678 georadiusbymember_ro: "",679 get: "usage: get key",680 getbit: "usage: getbit key offset",681 getrange: "usage: getrange key start end",682 getset: "usage: getset key value",683 hdel: "usage: hdel key field [field ...]",684 hexists: "usage: hexists key field",685 hget: "usage: hget key field",686 hgetall: "usage: hgetall key",687 hincrby: "usage: hincrby key field increment",688 hincrbyfloat: "usage: hincrbyfloat key field increment",689 hkeys: "usage: hkeys key",690 hlen: "usage: hlen key",691 hmget: "usage: hmget key field [field ...]",692 hmset: "usage: hmset key field value [field value ...]",693 hscan:694 "usage: hscan key cursor [MATCH pattern] [COUNT count]",695 hset: "usage: hset key field value [field value ...]",696 hsetnx: "usage: hsetnx key field value",697 hstrlen: "usage: hstrlen key field",698 hvals: "usage: hvals key",699 incr: "usage: incr key",700 incrby: "usage: incrby key increment",701 incrbyfloat: "usage: incrbyfloat key increment",702 info: "usage: info [section]",703 keys: "usage: keys pattern",704 lastsave: "usage: lastsave ",705 latency: "",706 lindex: "usage: lindex key index",707 linsert:708 "usage: linsert key BEFORE|AFTER pivot element",709 llen: "usage: llen key",710 lolwut: "usage: lolwut [VERSION version]",711 lpop: "usage: lpop key",712 lpush: "usage: lpush key element [element ...]",713 lpushx: "usage: lpushx key element [element ...]",714 lrange: "usage: lrange key start stop",715 lrem: "usage: lrem key count element",716 lset: "usage: lset key index element",717 ltrim: "usage: ltrim key start stop",718 memory: "",719 mget: "usage: mget key [key ...]",720 migrate: "usage: migrate host port key",721 module: "",722 monitor: "usage: monitor ",723 move: "usage: move key db",724 mset: "usage: mset key value [key value ...]",725 msetnx: "usage: msetnx key value [key value ...]",726 multi: "usage: multi ",727 object:728 "usage: object subcommand [arguments [arguments ...]]",729 persist: "usage: persist key",730 pexpire: "usage: pexpire key milliseconds",731 pexpireat:732 "usage: pexpireat key milliseconds-timestamp",733 pfadd: "usage: pfadd key element [element ...]",734 pfcount: "usage: pfcount key [key ...]",735 pfdebug: "",736 pfmerge:737 "usage: pfmerge destkey sourcekey [sourcekey ...]",738 pfselftest: "",739 ping: "usage: ping [message]",740 post: "",741 psetex: "usage: psetex key milliseconds value",742 psubscribe: "usage: psubscribe pattern [pattern ...]",743 psync: "usage: psync replicationid offset",744 pttl: "usage: pttl key",745 publish: "usage: publish channel message",746 pubsub:747 "usage: pubsub subcommand [argument [argument ...]]",748 punsubscribe:749 "usage: punsubscribe [pattern [pattern ...]]",750 randomkey: "usage: randomkey ",751 readonly: "usage: readonly ",752 readwrite: "usage: readwrite ",753 rename: "usage: rename key newkey",754 renamenx: "usage: renamenx key newkey",755 replconf: "",756 replicaof: "usage: replicaof host port",757 restore:758 "usage: restore key ttl serialized-value [REPLACE] [ABSTTL] [IDLETIME seconds] [FREQ frequency]",759 role: "usage: role ",760 rpop: "usage: rpop key",761 rpoplpush: "usage: rpoplpush source destination",762 rpush: "usage: rpush key element [element ...]",763 rpushx: "usage: rpushx key element [element ...]",764 sadd: "usage: sadd key member [member ...]",765 save: "usage: save ",766 scan:767 "usage: scan cursor [MATCH pattern] [COUNT count] [TYPE type]",768 scard: "usage: scard key",769 script: "",770 sdiff: "usage: sdiff key [key ...]",771 sdiffstore:772 "usage: sdiffstore destination key [key ...]",773 select: "usage: select index",774 set:775 "usage: set key value [EX seconds|PX milliseconds] [NX|XX] [KEEPTTL]",776 setbit: "usage: setbit key offset value",777 setex: "usage: setex key seconds value",778 setnx: "usage: setnx key value",779 setrange: "usage: setrange key offset value",780 shutdown: "usage: shutdown [NOSAVE|SAVE]",781 sinter: "usage: sinter key [key ...]",782 sinterstore:783 "usage: sinterstore destination key [key ...]",784 sismember: "usage: sismember key member",785 slaveof: "usage: slaveof host port",786 slowlog: "usage: slowlog subcommand [argument]",787 smembers: "usage: smembers key",788 smove: "usage: smove source destination member",789 sort:790 "usage: sort key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE destination]",791 spop: "usage: spop key [count]",792 srandmember: "usage: srandmember key [count]",793 srem: "usage: srem key member [member ...]",794 sscan:795 "usage: sscan key cursor [MATCH pattern] [COUNT count]",796 strlen: "usage: strlen key",797 subscribe: "usage: subscribe channel [channel ...]",798 substr: "",799 sunion: "usage: sunion key [key ...]",800 sunionstore:801 "usage: sunionstore destination key [key ...]",802 swapdb: "usage: swapdb index1 index2",803 sync: "usage: sync ",804 time: "usage: time ",805 touch: "usage: touch key [key ...]",806 ttl: "usage: ttl key",807 type: "usage: type key",808 unlink: "usage: unlink key [key ...]",809 unsubscribe:810 "usage: unsubscribe [channel [channel ...]]",811 unwatch: "usage: unwatch ",812 wait: "usage: wait numreplicas timeout",813 watch: "usage: watch key [key ...]",814 xack: "usage: xack key group ID [ID ...]",815 xadd:816 "usage: xadd key ID field value [field value ...]",817 xclaim:818 "usage: xclaim key group consumer min-idle-time ID [ID ...] [IDLE ms] [TIME ms-unix-time] [RETRYCOUNT count] [FORCE] [JUSTID]",819 xdel: "usage: xdel key ID [ID ...]",820 xgroup:821 "usage: xgroup [CREATE key groupname id-or-$] [SETID key groupname id-or-$] [DESTROY key groupname] [DELCONSUMER key groupname consumername]",822 xinfo:823 "usage: xinfo [CONSUMERS key groupname] [GROUPS key] [STREAM key] [HELP]",824 xlen: "usage: xlen key",825 xpending:826 "usage: xpending key group [start end count] [consumer]",827 xrange: "usage: xrange key start end [COUNT count]",828 xread:829 "usage: xread [COUNT count] [BLOCK milliseconds] STREAMS key [key ...] id [id ...]",830 xreadgroup:831 "usage: xreadgroup GROUP group consumer [COUNT count] [BLOCK milliseconds] [NOACK] STREAMS key [key ...] ID [ID ...]",832 xrevrange:833 "usage: xrevrange key end start [COUNT count]",834 xsetid: "",835 xtrim: "usage: xtrim key MAXLEN [~] count",836 zadd:837 "usage: zadd key [NX|XX] [CH] [INCR] score member [score member ...]",838 zcard: "usage: zcard key",839 zcount: "usage: zcount key min max",840 zincrby: "usage: zincrby key increment member",841 zinterstore:842 "usage: zinterstore destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]",843 zlexcount: "usage: zlexcount key min max",844 zpopmax: "usage: zpopmax key [count]",845 zpopmin: "usage: zpopmin key [count]",846 zrange: "usage: zrange key start stop [WITHSCORES]",847 zrangebylex:848 "usage: zrangebylex key min max [LIMIT offset count]",849 zrangebyscore:850 "usage: zrangebyscore key min max [WITHSCORES] [LIMIT offset count]",851 zrank: "usage: zrank key member",852 zrem: "usage: zrem key member [member ...]",853 zremrangebylex: "usage: zremrangebylex key min max",854 zremrangebyrank:855 "usage: zremrangebyrank key start stop",856 zremrangebyscore: "usage: zremrangebyscore key min max",857 zrevrange:858 "usage: zrevrange key start stop [WITHSCORES]",859 zrevrangebylex:860 "usage: zrevrangebylex key max min [LIMIT offset count]",861 zrevrangebyscore:862 "usage: zrevrangebyscore key max min [WITHSCORES] [LIMIT offset count]",863 zrevrank: "usage: zrevrank key member",864 zscan:865 "usage: zscan key cursor [MATCH pattern] [COUNT count]",866 zscore: "usage: zscore key member",867 zunionstore:868 "usage: zunionstore destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]",869 }}870 closedTitle="You closed the window."871 closedMessage="Click on the icon to reopen."872 allowTabs={false}873 hideTopBar={true}874 startState="maximised"875 msg= {intl.get("HostTerminal.descriptions.msg")}876 />877 </div>878 );879 }880}...

Full Screen

Full Screen

auth_user_pwd.spec.js

Source:auth_user_pwd.spec.js Github

copy

Full Screen

1// MIT License2//3// Copyright 2018 Electric Imp4//5// SPDX-License-Identifier: MIT6//7// Permission is hereby granted, free of charge, to any person obtaining a copy8// of this software and associated documentation files (the "Software"), to deal9// in the Software without restriction, including without limitation the rights10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell11// copies of the Software, and to permit persons to whom the Software is12// furnished to do so, subject to the following conditions:13//14// The above copyright notice and this permission notice shall be15// included in all copies or substantial portions of the Software.16//17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,18// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO20// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES21// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,22// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR23// OTHER DEALINGS IN THE SOFTWARE.24'use strict';25require('jasmine-expect');26const FS = require('fs');27const config = require('../config');28const ImptTestHelper = require('../ImptTestHelper');29const ImptAuthCommandsHelper = require('./ImptAuthCommandsHelper');30const Identifier = require('../../lib/util/Identifier');31const UserInterractor = require('../../lib/util/UserInteractor');32const Util = require('util');33const MessageHelper = require('../MessageHelper');34const DEFAULT_ENDPOINT = 'https://api.electricimp.com/v5';35// Test suite for 'impt auth login --user <user_id> --pwd <password>', 'impt auth logout', 'impt auth info' commands.36// Runs impt auth commands with different combinations of options.37ImptTestHelper.OUTPUT_MODES.forEach((outputMode) => {38 describe(`impt auth login by user/password test suite (output: ${outputMode ? outputMode : 'default'}) >`, () => {39 const auth = `--user ${config.username} --pwd "${config.password}"`;40 const endpoint = config.apiEndpoint ? `${config.apiEndpoint}` : `${DEFAULT_ENDPOINT}`;41 beforeAll((done) => {42 ImptTestHelper.init(false).43 then(done).44 catch(error => done.fail(error));45 }, ImptTestHelper.TIMEOUT);46 afterAll((done) => {47 ImptTestHelper.cleanUp().48 then(done).49 catch(error => done.fail(error));50 }, ImptTestHelper.TIMEOUT);51 describe('Tests with not auth preconditions >', () => {52 beforeAll((done) => {53 ImptAuthCommandsHelper.globalLogout().54 then(ImptAuthCommandsHelper.localLogout).55 then(done).56 catch(error => done.fail(error));57 }, ImptTestHelper.TIMEOUT);58 it('auth info without login', (done) => {59 ImptTestHelper.runCommand(`impt auth info ${outputMode}`, (commandOut) => {60 ImptTestHelper.checkFailStatus(commandOut);61 }).62 then(done).63 catch(error => done.fail(error));64 });65 it('login without user/password', (done) => {66 ImptTestHelper.runCommand('impt auth login', ImptTestHelper.checkFailStatus).67 then(() => ImptTestHelper.runCommand('impt auth login --local', ImptTestHelper.checkFailStatus)).68 then(() => ImptTestHelper.runCommand('impt auth login -l -u', ImptTestHelper.checkFailStatus)).69 then(() => ImptTestHelper.runCommand('impt auth login -l -w', ImptTestHelper.checkFailStatus)).70 then(() => ImptTestHelper.runCommand(`impt auth login -l -u ${config.username}`, ImptTestHelper.checkFailStatus)).71 then(() => ImptTestHelper.runCommand(`impt auth login -l -w "${config.password}"`, ImptTestHelper.checkFailStatus)).72 then(done).73 catch(error => done.fail(error));74 });75 it('login without output argument', (done) => {76 ImptTestHelper.runCommand('impt auth login -z', ImptTestHelper.checkFailStatus).77 then(() => ImptTestHelper.runCommand('impt auth login --output undefined', ImptTestHelper.checkFailStatus)).78 then(done).79 catch(error => done.fail(error));80 });81 it('login without endpoint argument', (done) => {82 ImptTestHelper.runCommand('impt auth login --endpoint', ImptTestHelper.checkFailStatus).83 then(done).84 catch(error => done.fail(error));85 });86 it('global logout without login', (done) => {87 ImptTestHelper.runCommand('impt auth logout', ImptTestHelper.checkFailStatus).88 then(done).89 catch(error => done.fail(error));90 });91 it('local logout without login', (done) => {92 ImptTestHelper.runCommand('impt auth logout -l', ImptTestHelper.checkFailStatus).93 then(done).94 catch(error => done.fail(error));95 });96 describe('global login test suite >', () => {97 afterEach((done) => {98 ImptAuthCommandsHelper.globalLogout().99 then(done).100 catch(error => done.fail(error));101 }, ImptTestHelper.TIMEOUT);102 it('global login', (done) => {103 ImptTestHelper.runCommand(`impt auth login ${auth} ${outputMode}`, ImptTestHelper.checkSuccessStatus).104 then(done).105 catch(error => done.fail(error));106 });107 it('global login with confirm', (done) => {108 ImptTestHelper.runCommand(`impt auth login ${auth} -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).109 then(done).110 catch(error => done.fail(error));111 });112 it('global temp login temporarily', (done) => {113 ImptTestHelper.runCommand(`impt auth login ${auth} --temp ${outputMode}`, ImptTestHelper.checkSuccessStatus).114 then(done).115 catch(error => done.fail(error));116 });117 it('global temp login with confirm', (done) => {118 ImptTestHelper.runCommand(`impt auth login ${auth} -t -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).119 then(done).120 catch(error => done.fail(error));121 });122 it('global temp login with endpoint', (done) => {123 ImptTestHelper.runCommand(`impt auth login ${auth} -t -e ${endpoint} ${outputMode}`, ImptTestHelper.checkSuccessStatus).124 then(done).125 catch(error => done.fail(error));126 });127 it('global temp login with endpoint and confirm', (done) => {128 ImptTestHelper.runCommand(`impt auth login ${auth} -t -e ${endpoint} -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).129 then(done).130 catch(error => done.fail(error));131 });132 it('global login with endpoint', (done) => {133 ImptTestHelper.runCommand(`impt auth login ${auth} -e ${endpoint} ${outputMode}`, ImptTestHelper.checkSuccessStatus).134 then(done).135 catch(error => done.fail(error));136 });137 it('global login with endpoint and confirm', (done) => {138 ImptTestHelper.runCommand(`impt auth login ${auth} -e ${endpoint} -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).139 then(done).140 catch(error => done.fail(error));141 });142 });143 describe('local login test suite >', () => {144 afterEach((done) => {145 ImptAuthCommandsHelper.localLogout().146 then(done).147 catch(error => done.fail(error));148 }, ImptTestHelper.TIMEOUT);149 it('local login', (done) => {150 ImptTestHelper.runCommand(`impt auth login -l ${auth} ${outputMode}`, ImptTestHelper.checkSuccessStatus).151 then(done).152 catch(error => done.fail(error));153 });154 it('local login with confirm', (done) => {155 ImptTestHelper.runCommand(`impt auth login -l ${auth} -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).156 then(done).157 catch(error => done.fail(error));158 });159 it('local temp login temporarily', (done) => {160 ImptTestHelper.runCommand(`impt auth login -l ${auth} -t ${outputMode}`, ImptTestHelper.checkSuccessStatus).161 then(done).162 catch(error => done.fail(error));163 });164 it('local temp login with confirm', (done) => {165 ImptTestHelper.runCommand(`impt auth login -l ${auth} -t -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).166 then(done).167 catch(error => done.fail(error));168 });169 it('local temp login with endpoint', (done) => {170 ImptTestHelper.runCommand(`impt auth login -l ${auth} -t -e ${endpoint} ${outputMode}`, ImptTestHelper.checkSuccessStatus).171 then(done).172 catch(error => done.fail(error));173 });174 it('local temp login with endpoint and confirm', (done) => {175 ImptTestHelper.runCommand(`impt auth login -l ${auth} -t -e ${endpoint} -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).176 then(done).177 catch(error => done.fail(error));178 });179 it('local login with endpoint', (done) => {180 ImptTestHelper.runCommand(`impt auth login -l ${auth} -e ${endpoint} ${outputMode}`, ImptTestHelper.checkSuccessStatus).181 then(done).182 catch(error => done.fail(error));183 });184 it('local login with endpoint and confirm', (done) => {185 ImptTestHelper.runCommand(`impt auth login -l ${auth} -e ${endpoint} -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).186 then(done).187 catch(error => done.fail(error));188 });189 });190 });191 describe('Tests with global auth preconditions >', () => {192 beforeAll((done) => {193 ImptAuthCommandsHelper.localLogout().194 then(ImptAuthCommandsHelper.globalLogin).195 then(done).196 catch(error => done.fail(error));197 }, ImptTestHelper.TIMEOUT);198 it('repeat global login with confirm', (done) => {199 ImptTestHelper.runCommand(`impt auth login ${auth} -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).200 then(done).201 catch(error => done.fail(error));202 });203 it('repeat global temp login with confirm', (done) => {204 ImptTestHelper.runCommand(`impt auth login ${auth} -t -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).205 then(done).206 catch(error => done.fail(error));207 });208 it('repeat global temp login with endpoint and confirm', (done) => {209 ImptTestHelper.runCommand(`impt auth login ${auth} -q -e ${endpoint} -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).210 then(done).211 catch(error => done.fail(error));212 });213 it('repeat global login with endpoint and confirm', (done) => {214 ImptTestHelper.runCommand(`impt auth login ${auth} -e ${endpoint} --confirmed ${outputMode}`, ImptTestHelper.checkSuccessStatus).215 then(done).216 catch(error => done.fail(error));217 });218 it('local logout with global login', (done) => {219 ImptTestHelper.runCommand(`impt auth logout -l ${outputMode}`, ImptTestHelper.checkFailStatus).220 then(done).221 catch(error => done.fail(error));222 });223 it('global auth info', (done) => {224 ImptTestHelper.runCommand(`impt auth info ${outputMode}`, (commandOut) => {225 ImptTestHelper.checkAttribute(commandOut, 'auto refresh', 'true');226 ImptTestHelper.checkAttribute(commandOut, 'endpoint', `${endpoint}`);227 ImptTestHelper.checkAttribute(commandOut, 'Auth type', 'Global Auth file');228 ImptTestHelper.checkAttribute(commandOut, 'Login method', 'User/Password');229 ImptTestHelper.checkAttribute(commandOut, 'Username', config.username);230 ImptTestHelper.checkSuccessStatus(commandOut);231 }).232 then(done).233 catch(error => done.fail(error));234 });235 describe('Test with global auth preconditions and restore>', () => {236 afterEach((done) => {237 ImptAuthCommandsHelper.globalLogin().238 then(done).239 catch(error => done.fail(error));240 }, ImptTestHelper.TIMEOUT);241 it('global logout', (done) => {242 ImptTestHelper.runCommand(`impt auth logout`, (commandOut) => {243 ImptTestHelper.checkSuccessStatus(commandOut);244 }).245 then(done).246 catch(error => done.fail(error));247 });248 });249 });250 describe('Tests with global temp auth preconditions >', () => {251 beforeAll((done) => {252 ImptTestHelper.runCommand(`impt auth login ${auth} -t -q`, ImptTestHelper.emptyCheck).253 then(ImptAuthCommandsHelper.localLogout).254 then(done).255 catch(error => done.fail(error));256 }, ImptTestHelper.TIMEOUT);257 it('global temp auth info', (done) => {258 ImptTestHelper.runCommand(`impt auth info`, (commandOut) => {259 ImptTestHelper.checkAttribute(commandOut, 'auto refresh', 'false');260 ImptTestHelper.checkSuccessStatus(commandOut);261 }).262 then(done).263 catch(error => done.fail(error));264 });265 describe('Tests with global temp auth preconditions and restore >', () => {266 afterEach((done) => {267 ImptTestHelper.runCommand(`impt auth login ${auth} -t -q`, ImptTestHelper.emptyCheck).268 then(ImptAuthCommandsHelper.localLogout).269 then(done).270 catch(error => done.fail(error));271 }, ImptTestHelper.TIMEOUT);272 it('global logout with temp login', (done) => {273 ImptTestHelper.runCommand('impt auth logout', ImptTestHelper.checkSuccessStatus).274 then(done).275 catch(error => done.fail(error));276 });277 });278 });279 describe('Tests with global auth and endpoint preconditions >', () => {280 beforeAll((done) => {281 ImptTestHelper.runCommand(`impt auth login ${auth} -e ${endpoint} -q`, ImptTestHelper.emptyCheck).282 then(ImptAuthCommandsHelper.localLogout).283 then(done).284 catch(error => done.fail(error));285 }, ImptTestHelper.TIMEOUT);286 it('global endpoint auth info', (done) => {287 ImptTestHelper.runCommand(`impt auth info`, (commandOut) => {288 expect(commandOut.output).toMatch(endpoint);289 ImptTestHelper.checkSuccessStatus(commandOut);290 }).291 then(done).292 catch(error => done.fail(error));293 });294 describe('Tests with global auth , endpoint preconditions and restore >', () => {295 afterEach((done) => {296 ImptTestHelper.runCommand(`impt auth login ${auth} -e ${endpoint} -q`, ImptTestHelper.emptyCheck).297 then(ImptAuthCommandsHelper.localLogout).298 then(done).299 catch(error => done.fail(error));300 }, ImptTestHelper.TIMEOUT);301 it('global logout with endpoint login', (done) => {302 ImptTestHelper.runCommand('impt auth logout', ImptTestHelper.checkSuccessStatus).303 then(done).304 catch(error => done.fail(error));305 });306 });307 });308 describe('Tests with local auth preconditions >', () => {309 beforeAll((done) => {310 ImptAuthCommandsHelper.globalLogout().311 then(ImptAuthCommandsHelper.localLogin).312 then(done).313 catch(error => done.fail(error));314 }, ImptTestHelper.TIMEOUT);315 it('repeat local login with confirm', (done) => {316 ImptTestHelper.runCommand(`impt auth login -l ${auth} -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).317 then(done).318 catch(error => done.fail(error));319 });320 it('repeat local temp login with confirm', (done) => {321 ImptTestHelper.runCommand(`impt auth login -l ${auth} -t -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).322 then(done).323 catch(error => done.fail(error));324 });325 it('repeat local temp login with endpoint and confirm', (done) => {326 ImptTestHelper.runCommand(`impt auth login -l ${auth} -t -e ${endpoint} -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).327 then(done).328 catch(error => done.fail(error));329 });330 it('repeat local login with endpoint and confirm', (done) => {331 ImptTestHelper.runCommand(`impt auth login -l ${auth} -e ${endpoint} -q ${outputMode}`, ImptTestHelper.checkSuccessStatus).332 then(done).333 catch(error => done.fail(error));334 });335 it('global logout with local login', (done) => {336 ImptTestHelper.runCommand(`impt auth logout ${outputMode}`, ImptTestHelper.checkFailStatus).337 then(done).338 catch(error => done.fail(error));339 });340 it('global logout without output value', (done) => {341 ImptTestHelper.runCommand(`impt auth logout -z`, ImptTestHelper.checkFailStatus).342 then(done).343 catch(error => done.fail(error));344 });345 it('local auth info ', (done) => {346 ImptTestHelper.runCommand(`impt auth info`, (commandOut) => {347 ImptTestHelper.checkAttribute(commandOut, 'Auth type', 'Local Auth file');348 ImptTestHelper.checkSuccessStatus(commandOut);349 }).350 then(done).351 catch(error => done.fail(error));352 });353 it('auth info without output value', (done) => {354 ImptTestHelper.runCommand(`impt auth info -z`, ImptTestHelper.checkFailStatus).355 then(done).356 catch(error => done.fail(error));357 });358 describe('Tests with local auth preconditions and restore>', () => {359 afterEach((done) => {360 ImptAuthCommandsHelper.localLogin().361 then(done).362 catch(error => done.fail(error));363 }, ImptTestHelper.TIMEOUT);364 it('local logout', (done) => {365 ImptTestHelper.runCommand(`impt auth logout -l`, (commandOut) => {366 ImptTestHelper.checkSuccessStatus(commandOut);367 }).368 then(done).369 catch(error => done.fail(error));370 });371 });372 });373 });...

Full Screen

Full Screen

adb-e2e-specs.js

Source:adb-e2e-specs.js Github

copy

Full Screen

1// transpile:mocha2import ADB from "../../adb";3import path from 'path';4import chai from 'chai';5import chaiAsPromised from 'chai-as-promised';6import { fs } from 'appium-support';7import { CONNECTION_TYPES, FILE_TYPES } from '../../lib/constants';8import { sleep } from 'asyncbox';9process.env.NODE_ENV = 'test';10chai.use(chaiAsPromised);11chai.should();12// these test require a device connected via usb13describe('adb-e2e', () => {14 let device = null;15 let availableDevices = null;16 const packageName = "com.example.android.contactmanager";17 const activityName = ".ContactManager";18 before(async () => {19 availableDevices = await ADB.findAdbDevices();20 // just select the first device21 device = new ADB(CONNECTION_TYPES.USB, availableDevices[0]);22 await device.connect();23 });24 after(async () => {25 await device.closeConnection();26 });27 describe('shell', async () => {28 it('should return a not found message for an unknown command', async () => {29 let commandString = "asdf";30 let expectedReturnString = `/system/bin/sh: ${commandString}: not found`;31 let command = { // set print to false so we get the data back as a string32 type: "shell"33 , string: commandString34 , print: false35 };36 let output = await device.runCommand(command);37 output.indexOf(expectedReturnString).should.not.equal(-1);38 });39 it('should return an error message if we run a shell command incorrectly', async () => {40 let commandString = "touch";41 let expectedReturnString = "touch: no file specified";42 let command = { // set print to false so we get the data back as a string43 type: "shell"44 , string: commandString45 , print: false46 };47 let output = await device.runCommand(command);48 output.indexOf(expectedReturnString).should.not.equal(-1);49 });50 it('should return successful output if we run a shell command correctly', async () => {51 let commandString = "cd sdcard; pwd";52 let expectedReturnString = "/sdcard";53 let command = { // set print to false so we get the data back as a string54 type: "shell"55 , string: commandString56 , print: false57 };58 let output = await device.runCommand(command);59 output.indexOf(expectedReturnString).should.not.equal(-1);60 });61 });62 describe('push', () => {63 const smallFile = path.resolve(__dirname64 , '..'65 , '..'66 , '..'67 , 'test'68 , 'fixtures'69 , 'smallFile');70 const largeFile = path.resolve(__dirname71 , '..'72 , '..'73 , '..'74 , 'test'75 , 'fixtures'76 , 'largeFile');77 const destination = "sdcard/";78 it('should upload smallFile to device', async () => {79 const stats = await fs.stat(smallFile);80 const smallFileSize = stats.size.toString();81 let command = {82 type: "push"83 , source: smallFile84 , destination: destination85 };86 await device.runCommand(command);87 let lsCommand = {88 type: "shell"89 , string: "ls -al sdcard/ | grep smallFile"90 , print: false91 };92 let output = await device.runCommand(lsCommand);93 output.indexOf(smallFileSize).should.not.equal(-1);94 });95 it('should upload largeFile to device', async () => {96 const stats = await fs.stat(largeFile);97 const largeFileSize = stats.size.toString();98 let command = {99 type: "push"100 , source: largeFile101 , destination: destination102 };103 await device.runCommand(command);104 let lsCommand = {105 type: "shell"106 , string: "ls -al sdcard/ | grep largeFile"107 , print: false108 };109 let output = await device.runCommand(lsCommand);110 output.indexOf(largeFileSize).should.not.equal(-1);111 });112 it('should return -1 if the source file does not exist', async () => {113 let command = {114 type: "push"115 , source: path.resolve(__dirname, 'nonExistantFile')116 , destination: destination117 };118 let retValue = await device.runCommand(command);119 retValue.should.equal(-1);120 });121 });122 describe('pull', () => {123 const smallFile = path.resolve(__dirname, '..', '..', '..', 'test', 'fixtures', 'smallFile');124 const largeFile = path.resolve(__dirname, '..', '..', '..', 'test', 'fixtures', 'largeFile');125 const tempTestPath = path.resolve(__dirname, '..', '..', '..', 'tempTest');126 const push_destination = "sdcard/";127 before(async () => {128 await fs.mkdir(tempTestPath);129 });130 after(async () => {131 await fs.rimraf(tempTestPath);132 });133 it('should pull down all of smallFile', async () => {134 // push smallfile before trying to pull it135 let push_command = {136 type: "push"137 , source: smallFile138 , destination: push_destination139 };140 await device.runCommand(push_command);141 let destination = `${tempTestPath}/smallFile`;142 let command = {143 type: "pull"144 , source: "sdcard/smallFile"145 , destination: destination146 };147 let fileSize = await device.runCommand(command);148 let stats = await fs.stat(destination);149 fileSize.should.equal(stats.size);150 });151 it('should pull down all of largeFile', async () => {152 // push largefile before trying to pull it153 let push_command = {154 type: "push"155 , source: largeFile156 , destination: push_destination157 };158 await device.runCommand(push_command);159 let destination = `${tempTestPath}/largeFile`;160 let command = {161 type: "pull"162 , source: "sdcard/largeFile"163 , destination: destination164 };165 let fileSize = await device.runCommand(command);166 let stats = await fs.stat(destination);167 fileSize.should.equal(stats.size);168 });169 it('should return a filesize of -1 if the file does not exist', async () => {170 // try and pull a file we just pushed to the device171 // except leave off the file extension172 let command = {173 type: "pull"174 , source: "sdcard/adbCapture"175 , destination: path.resolve(__dirname, '..', '..', '..')176 };177 let output = await device.runCommand(command);178 output.should.equal(-1);179 });180 });181 describe('list', () => {182 it('should return a list of files in a folder', async () => {183 // Hard to test symlinks because we can't create them on an un-rooted phone184 let commandString = "cd sdcard; mkdir tmp; cd tmp; touch file1; touch file2; mkdir folder1";185 let command = { // set print to false so we get the data back as a string186 type: "shell"187 , string: commandString188 , print: false189 };190 await device.runCommand(command);191 command = {192 type: "list"193 , remotePath: "sdcard/tmp"194 };195 let output = await device.runCommand(command);196 let filenames = output.map(file => file.filename);197 filenames.should.deep.equal(['file1', 'file2', 'folder1']);198 let filetypes = output.map(file => file.type);199 filetypes.should.deep.equal([200 FILE_TYPES.FILE201 , FILE_TYPES.FILE202 , FILE_TYPES.DIRECTORY203 ]);204 });205 it('should return an empty array for an empty folder', async () => {206 let command = {207 type: "list"208 , remotePath: "sdcard/tmp/folder1"209 };210 let output = await device.runCommand(command);211 output.length.should.equal(0);212 });213 it('should return an empty array when called on a file', async () => {214 let command = {215 type: "list"216 , remotePath: "sdcard/tmp/file1"217 };218 let output = await device.runCommand(command);219 output.length.should.equal(0);220 });221 it('should return an empty array when called on a non-existent remote path', async () => {222 let command = {223 type: "list"224 , remotePath: "sdcard/tmp/" + Date.now()225 };226 let output = await device.runCommand(command);227 output.length.should.equal(0);228 });229 });230 describe('install', () => {231 it('should be able to install and run an app', async function () {232 this.timeout(8000);233 const source = path.resolve(__dirname, '..', '..', '..', 'test', 'fixtures', 'ContactManager.apk');234 const runApp = `${packageName}/${activityName}`;235 await device.runCommand({ type: "install", source: source });236 let output = await device.runCommand({ type: "shell"237 , string: runApp238 , print: false });239 let errorMsg = `Error: Activity class {${packageName}/${packageName}.${activityName}} does not exist.`;240 output.indexOf(errorMsg).should.equal(-1);241 });242 });243 describe('uninstall', () => {244 before(async () => {245 const source = path.resolve(__dirname, '..', '..', '..', 'test', 'fixtures', 'ContactManager.apk');246 const runApp = `${packageName}/${activityName}`;247 await device.runCommand({ type: "install", source: source });248 await device.runCommand({ type: "shell"249 , string: runApp250 , print: false });251 });252 it('should uninstall the app we have installed', async () => {253 let output = await device.runCommand({ type: "uninstall", packageName: packageName });254 output.indexOf(`Success`).should.not.equal(-1);255 });256 });257 describe('reboot', () => {258 // not using an arrow function so that the this context is correct for this.timeout259 it('should (the device) be available for commands after reboot', async function () {260 // override default timeout since we need to wait for the device to reboot261 this.timeout(30000);262 let command = {263 type: "reboot"264 };265 await device.runCommand(command);266 // sleep then connect to the device again267 await sleep(20000); // time required before an S4 running Android 5 is available268 availableDevices = await ADB.findAdbDevices();269 // just select the first device270 device = new ADB(CONNECTION_TYPES.USB, availableDevices[0]);271 await device.connect();272 // run a very basic command to confirm device is okay273 let commandString = "cd sdcard/ ; pwd";274 let expectedReturnString = "/sdcard";275 let checkCommand = { // set print to false so we get the data back as a string276 type: "shell"277 , string: commandString278 , print: false279 };280 let output = await device.runCommand(checkCommand);281 output.trim().should.equal(expectedReturnString);282 });283 });...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful