Mar a bheir thu seachad briosgaidean bho Selenium WebDriver gu Ath-dhearbhadh

Mar a bheir thu seachad briosgaidean bho Selenium WebDriver gu Rest-Assured? Nuair a bhios tu a ’dèanamh deuchainnean fèin-ghluasadach aig ìre API agus UI, dh’ fhaodadh suidheachaidhean a bhith ann far a bheil thu a ’dèanamh an dà chuid agus gum feum thu togalaichean a thoirt seachad bhon deuchainn API agad gu deuchainn UI no a chaochladh.

San eisimpleir seo, tha sinn a ’sealltainn mar a bheir thu seachad briosgaidean bho Selenium WebDriver gu Rest-Assured a’ cleachdadh Java.



Cuir seachad briosgaidean bho Selenium gu Rest-Assured

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);
} }