Hvernig á að fara með kex frá Selen WebDriver til að vera viss

Hvernig á að senda smákökur frá Selenium WebDriver til fullvissu? Þegar þú gerir sjálfvirkar prófanir á API og UI laginu gætu komið upp aðstæður þar sem þú ert að gera bæði og að þú þarft að láta eiginleika frá API prófinu þínu yfir í UI prófið þitt eða öfugt.

Í þessu dæmi sýnum við hvernig á að fara með smákökur frá Selenium WebDriver til Rest-assured með Java.



Sendu smákökur frá seleni til fullvissu

import io.restassured.RestAssured; import io.restassured.http.Cookies; import org.openqa.selenium.Cookie; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List; import java.util.Set; import static io.restassured.RestAssured.given; public class RestAssuredWebDriverCookie {
@Test
public void cookieTest() {
WebDriver driver = new ChromeDriver();

driver.navigate().to('http://www.someurl.com');

Set seleniumCookies = driver.manage().getCookies();

// This is where the Cookies will live going forward
List restAssuredCookies = new ArrayList();

// Simply pull all the cookies into Rest-Assured
for (org.openqa.selenium.Cookie cookie : seleniumCookies) {

restAssuredCookies.add(new io.restassured.http.Cookie.Builder(cookie.getName(), cookie.getValue()).build());
}

// Pass them into the Rest-Assured Call
given().spec(RestAssured.requestSpecification)


.basePath('/some-path')


.cookies(new Cookies(restAssuredCookies))


.queryParam('id', '1234')


.get()


.then().statusCode(200);
} }