examples.test.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* globals Promise */
  2. import path from 'path';
  3. import SeleniumHelper from '../helpers/selenium-helper';
  4. const {
  5. clickButton,
  6. clickText,
  7. clickXpath,
  8. findByXpath,
  9. getDriver,
  10. getLogs,
  11. loadUri
  12. } = new SeleniumHelper();
  13. let driver;
  14. describe('player example', () => {
  15. const uri = path.resolve(__dirname, '../../build/player.html');
  16. beforeAll(() => {
  17. driver = getDriver();
  18. });
  19. afterAll(async () => {
  20. await driver.quit();
  21. });
  22. test.skip('Player: load a project by ID', async () => {
  23. const projectId = '96708228';
  24. await loadUri(`${uri}#${projectId}`);
  25. await clickXpath('//img[@title="Go"]');
  26. await new Promise(resolve => setTimeout(resolve, 2000));
  27. await clickXpath('//img[@title="Stop"]');
  28. const logs = await getLogs();
  29. await expect(logs).toEqual([]);
  30. const projectRequests = await driver.manage().logs()
  31. .get('performance')
  32. .then(pLogs => pLogs.map(log => JSON.parse(log.message).message)
  33. .filter(m => m.method === 'Network.requestWillBeSent')
  34. .map(m => m.params.request.url)
  35. .filter(url => url === 'https://projects.scratch.mit.edu/96708228')
  36. );
  37. await expect(projectRequests).toEqual(['https://projects.scratch.mit.edu/96708228']);
  38. });
  39. });
  40. describe('blocks example', () => {
  41. const uri = path.resolve(__dirname, '../../build/blocks-only.html');
  42. beforeAll(() => {
  43. driver = getDriver();
  44. });
  45. afterAll(async () => {
  46. await driver.quit();
  47. });
  48. test.skip('Blocks: load a project by ID', async () => {
  49. const projectId = '96708228';
  50. await loadUri(`${uri}#${projectId}`);
  51. await new Promise(resolve => setTimeout(resolve, 2000));
  52. await clickXpath('//img[@title="Go"]');
  53. await new Promise(resolve => setTimeout(resolve, 2000));
  54. await clickXpath('//img[@title="Stop"]');
  55. const logs = await getLogs();
  56. await expect(logs).toEqual([]);
  57. const projectRequests = await driver.manage().logs()
  58. .get('performance')
  59. .then(pLogs => pLogs.map(log => JSON.parse(log.message).message)
  60. .filter(m => m.method === 'Network.requestWillBeSent')
  61. .map(m => m.params.request.url)
  62. .filter(url => url === 'https://projects.scratch.mit.edu/96708228')
  63. );
  64. await expect(projectRequests).toEqual(['https://projects.scratch.mit.edu/96708228']);
  65. });
  66. // skipping per https://github.com/LLK/scratch-gui/issues/4902 until we have better approach
  67. test.skip('Change categories', async () => {
  68. await loadUri(`${uri}`);
  69. await clickText('Looks');
  70. await clickText('Sound');
  71. await clickText('Events');
  72. await clickText('Control');
  73. await clickText('Sensing');
  74. await clickText('Operators');
  75. await clickText('Variables');
  76. await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
  77. await clickText('Make a Variable');
  78. let el = await findByXpath("//input[@name='New variable name:']");
  79. await el.sendKeys('score');
  80. await clickButton('OK');
  81. await clickText('Make a Variable');
  82. el = await findByXpath("//input[@name='New variable name:']");
  83. await el.sendKeys('second variable');
  84. await clickButton('OK');
  85. const logs = await getLogs();
  86. await expect(logs).toEqual([]);
  87. });
  88. });