189 8069 5689

如何将Cookie从SeleniumWebDriver传递到休息保证-创新互联

如何将Cookie从Selenium WebDriver传递给Rest-Assured?当您在API和UI层进行自动化测试时,可能会出现这样的情况:您需要将API测试中的属性传递给UI测试,反之亦然。

成都创新互联服务项目包括沧源网站建设、沧源网站制作、沧源网页制作以及沧源网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,沧源网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到沧源省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

在此示例中,我们将展示如何使用Java将Selenium WebDriver中的Cookie传递给Rest-Assured。
将Cookie从Selenium传递给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);
}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前名称:如何将Cookie从SeleniumWebDriver传递到休息保证-创新互联
本文路径:http://cdxtjz.cn/article/dcsgoj.html

其他资讯