🥝
Cypress Notlari
  • 🥑1. Cypress – Giriş
  • 📐2. Cypress Kurulum
  • 🥳3. Test Runner
  • 🔥4. Cypress ile İlk Test
  • ⚔️5. Cypress Destekleyen Tarayıcılar
  • 🦇6. Cypress Basit Komutlar
  • 👾7. Cypress Değişkenler (Variables)
  • 😎8. Cypress Aliases
  • 👻9. Cypress Locators
  • ☝️10. Cypress Assertions(iddia)
  • 📔11. Cypress Metin Doğrulaması
  • 🧞12. Cypress Eşzamansız Davranış(Asynchronous Behavior)
  • 🦊13. Cypress XHR ile çalışma
  • ✅14. Cypress Checkbox
  • 🍪15. Cypress Cookie İşlemleri
  • ☘️16. Cypress Get ve Post İşlemleri
  • 🦆17. Api Response Data Type Kontrolu
  • ☔18. Chai Json Schema
  • 🥳19. Chai ile Schema Oluşturma Örnekleri
  • 🇲🇬20. Cypress Fixtures
  • 🆓21. Cypress — Dashboard Hackliyoruz
  • 🎥22. Cypress Screenshotlar ve Videolar
  • 😋23. Cypress Debugging
  • 🛃24. Cypress Custom Commands
  • 📖25. Cypress Environment Variables
  • 🪝26. Cypress Hooks
  • 🎑27. Cypress Reports
  • ⛳28.Best Practices
  • Kaynakça
Powered by GitBook
On this page

13. Cypress XHR ile çalışma

XHR is XML HTTP Request.

XHR, XML HTTP İsteğidir. Bu bir Uygulama Programlama Arayüzüdür (API). yöntemleri bir web tarayıcısı ile sunucu arasında veri gönderen bir nesne olarak kullanılabilir. Bir nesnesi bir sunucudan yanıt biçiminde veri talep edebilir

//aliasing request
cy.request('https://jsonplaceholder.cypress.io/comments').as('c')

cy.get('@c').should((response) => {
   expect(response.body).to.have.length(100)
   expect(response).to.have.property('headers')
})

Mock api ile Response Api Kıyaslanması

Cypress/support/commands.js dizisi altında kodumuzu ekliyoruz.kul

Cypress.Commands.add("assertDeepEqual", (response, expectedData) => {
	const assertObject = (actual, expected, key) => {
		if (actual === undefined) {
			cy.log(`actual.${key} is undefined`);
		}

		if (actual === null) {
			cy.log(`actual.${key} is null`);
		}

		const actualType = typeof actual;
		const expectedType = typeof expected;

		if (actualType !== expectedType) {
			cy.log(`actual.${key} type ${actualType} is not equal to expected.${key} type ${expectedType}`);
		}

		try {
			expect(actualType).to.equal(expectedType);
		} catch (err) {
			throw new Error(`actual.${key} type ${actualType} is not equal to expected.${key} type ${expectedType}`);
		}

		if (actualType && actual && actualType === "object" && expectedType === "object") {
			const actualKeys = Object.keys(actual);
			const expectedKeys = Object.keys(expected);
			expect(actualKeys).to.deep.equal(expectedKeys);

			// eslint-disable-next-line no-shadow
			actualKeys.forEach((key) => {
				assertObject(actual[key], expected[key], key);
			});
		}
	};

	assertObject(response, expectedData);
});

Kullanım olarak mock datamızı alıyoruz ve dönen response ile oluşturduğumuz command'ı kullanıyoruz.

it("should data be match mock array", () => {
	cy.request({
		method: "GET",
		url: "https://porti.wtf/todo",
	}).then((response) => {
		cy.assertDeepEqual(response.body, mockTodoResponse);
	});
});
Previous12. Cypress Eşzamansız Davranış(Asynchronous Behavior)Next14. Cypress Checkbox

Last updated 2 years ago

🦊