at90

edit test book library

Nov 25th, 2021
3,844
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const {chromium} = require('playwright-chromium');
  2. const {expect} = require('chai');
  3.  
  4.  
  5. let browser, page;
  6.  
  7. describe('E2E tests', function () {
  8.     this.timeout(-1);
  9.     before(async () => {
  10.         browser = await chromium.launch()
  11.     });
  12.     after(async () => {
  13.         await browser.close();
  14.     });
  15.     beforeEach(async () => {
  16.         page = await browser.newPage();
  17.         await page.goto('http://127.0.0.1:8080');
  18.     });
  19.     afterEach(async () => {
  20.         await page.close();
  21.     });
  22.  
  23.     it('should load all books when LOAD ALL BOOKS is clicked', async () => {
  24.         await Promise.all([
  25.             page.waitForResponse('**/jsonstore/collections/books'),
  26.             page.click('text=Load All Books')
  27.         ]);
  28.         const books = await page.evaluate(() => document.querySelector('tbody').textContent);
  29.  
  30.         expect(books).to.include('Harry Potter and the Philosopher\'s Stone');
  31.         expect(books).to.include('J.K.Rowling');
  32.         expect(books).to.include('C# Fundamentals');
  33.         expect(books).to.include('Svetlin Nakov');
  34.     });
  35.  
  36.     it('should add new book when submit is clicked', async () => {
  37.         await page.fill('input[name=title]', 'Clean code');
  38.         await page.fill('input[name=author]', 'Uncle Bob');
  39.         const [request, response] = await Promise.all([
  40.             page.waitForRequest('**/jsonstore/collections/books'),
  41.             page.waitForResponse('**/jsonstore/collections/books'),
  42.             page.click('text=Submit')
  43.         ]);
  44.         expect('{"title":"Clean code","author":"Uncle Bob"}').to.be.equal(request.postData())
  45.         expect(response.status).to.be.ok;
  46.     });
  47.  
  48.     it.only('should edit selected book after submit ', async () => {
  49.         await Promise.all([
  50.             page.waitForResponse('**/jsonstore/collections/books'),
  51.             page.click('text=Load all books')
  52.         ]);
  53.  
  54.         await page.click('.editBtn:nth-child(1)');
  55.         await page.waitForSelector(('#editForm'));
  56.  
  57.         //Искам тук да изчакам да се попълнят и след това да продължава кода надолу
  58.         await page.waitForSelector('css=input >> text=C# Fundamentals');
  59.         await page.waitForSelector(`css=input >> text=Svetlin Nakov`);
  60.  
  61.         await page.fill('input[name=title]', 'Java Fundamentals');
  62.         const [request, response] = await Promise.all([
  63.             page.waitForRequest(req => {
  64.                 return req.url().includes('/jsonstore/collections/books') && req.method() === 'PUT';
  65.             }),
  66.             page.waitForResponse(res => {
  67.                 return res.url().includes('/jsonstore/collections/books');
  68.             }),
  69.             page.click('text=Save')
  70.         ]);
  71.         expect('{title: Java Fundamentals, author: Svetlin Nakov}').to.be.equal(request.postData());
  72.         expect(response.status).to.be.ok;
  73.     });
  74. })
RAW Paste Data