//package jj.tech.paolu.utils.playwright;
//
//import java.util.HashMap;
//
//import org.apache.commons.codec.binary.Base64;
//
//import com.fasterxml.jackson.databind.JsonNode;
//import com.microsoft.playwright.APIRequestContext;
//import com.microsoft.playwright.APIResponse;
//import com.microsoft.playwright.Browser;
//import com.microsoft.playwright.BrowserContext;
//import com.microsoft.playwright.BrowserType;
//import com.microsoft.playwright.FrameLocator;
//import com.microsoft.playwright.Page;
//import com.microsoft.playwright.Playwright;
//import com.microsoft.playwright.Response;
//import com.microsoft.playwright.options.RequestOptions;
//
//import jj.tech.paolu.utils.YMHttp;
//
//
//public class Hgt8 {
//
//	public static Playwright playwright;
//	public static Browser browser;
//	public static HashMap<String, Hgt8> instances = new HashMap<String, Hgt8>();
//	
//	public static void start() {
//		playwright = Playwright.create();
//		playwright.selectors().setTestIdAttribute("id");
//		//设置有是否UI,每个操作减慢执行200毫秒
//		browser = playwright.chromium().launch(
//	    		new BrowserType.LaunchOptions()
//	    		.setHeadless(false)
//	    		.setSlowMo(200)
//	    );	
//	}
//	
//	public BrowserContext browserContext;
//	public APIRequestContext aPIRequestContext;
//	public Page page;
//	//用户是否登录
//	public Boolean isOnLine = false;
//	public Long defaultTimeout = 6000L;
//	
//	
//	
//	public static void closePlaywright() {
//		browser.close();
//		playwright.close();
//	}
//
//	public static Hgt8 addInstance(String name) {
//		Hgt8 instance = instances.get(name);
//		if(instance == null) {
//			Hgt8 inst = new Hgt8();
//			instances.put(name, inst);
//			return inst;
//		}else {
//			return instance;
//		}
//	}
//	public static Hgt8 getInstance(String name) {
//		return instances.get(name);
//	}
//	
//	public static void deleteInstance(String name) {
//		instances.get(name).close();
//		instances.remove(name);
//	}
//	
//	public static void updateInstance(String name) {
//		if(instances.get(name) != null) {
//			instances.get(name).close();
//			instances.remove(name);
//			instances.put(name, new Hgt8());
//		}
//	}
//	
//	
//	
//
//	
//	
//	private Hgt8() {
//		 this.browserContext = browser.newContext();
//		 this.browserContext.setDefaultNavigationTimeout(this.defaultTimeout);
//		 this.aPIRequestContext = browserContext.request();
//	     this.page = browserContext.newPage();
//	     this.page.setDefaultTimeout(this.defaultTimeout);
//	}
//	
//	public void close() {
//		this.page.close();
//		this.browserContext.close();
//	}
//	
//	
//	public Boolean login(String url, String manageName, String user, String passworld) {
//		try {
//			if(this.isOnLine == false) {
//				this.page.navigate(url+ "/search.aspx");
//				FrameLocator ifr_main = this.page.frameLocator("#ifr_main");
//				
//				//管理员账号
//				ifr_main.getByTestId("lineCode")
//					.fill(manageName);
//				ifr_main.locator("xpath=//input[@class='btn']")
//				.click();
//				
//				//login
//				Response response = this.page.waitForResponse("**/captcha_image/2*", () -> {
//				});
//				byte[] image_bytes = response.body();
//				JsonNode root = 
//				YMHttp.customApi(Base64.encodeBase64String(image_bytes));
//				JsonNode code_num = root.get("data").get("data");
//				ifr_main.getByTestId("userName").fill(user);
//				ifr_main.getByTestId("password").fill(passworld);
//				ifr_main.getByTestId("code").fill(code_num.asText());
//				this.page.waitForTimeout(2_500);
//				System.out.println("wait 2500");
//				ifr_main.getByTestId("btnSubmit").click();
//				
//				
//				//同意
//				this.page.frameLocator("#ifr_main")
//				.locator("xpath=//input[@class='protocol-btn-y']")
//				.click();
//				
//				
//				String storageState = 
//				aPIRequestContext.storageState();
//				System.err.println(storageState);
//				
//				
//				
//				
//				//关闭弹窗
//				//ifr_main.getByTestId("tc_Close")
//				//.click();
//				
//				this.isOnLine = true;
//			}
//			return true;
//		}catch (Exception e) {
//			e.printStackTrace();
//			return false;
//		}
//		
//	}
//	
//	public void G_24_His(String url, String page, String issuet) {
//		
//		HashMap<String, String> pram = new HashMap<String, String>();
//		pram.put("gameID", "G_24");
//		pram.put("currtentPage","1");
//		pram.put("asDate","2024-09-23");
//		pram.put("issuet", "");
//		
//		RequestOptions  requestOptions  =
//		RequestOptions.create().setHeader("Content-Type", "application/json")
//        .setData(pram);
//		
//		APIResponse addNewPet =
//		this.aPIRequestContext.post(url+"/wb2/jg0001/s001s", requestOptions);
//		
//		System.err.println(addNewPet.text());
//		
//	}
//	
//	
////	public static void main(String[] args) {
////		Hgt8.addInstance("a");
////		Hgt8.addInstance("b");
////		Hgt8.deleteInstance("a");
////		
////	}
//	
//    
//	
////	public static void main(String[] args) {
////        try {
////        	Playwright playwright = Playwright.create();
////            Browser browser = playwright.chromium().launch(
////            		new BrowserType.LaunchOptions().setHeadless(false)
////            		);
////            Page page = browser.newPage();
//////            page.navigate("https://sse8.idc9998.com");
////            page.navigate("https://sol8.idc9998.com");
////            
////
////            // Expect a title "to contain" a substring.
////            
////
////            // create a locator
////            Locator getStarted = page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Get Started"));
////
////            // Expect an attribute "to be strictly equal" to the value.
//////            assertThat(getStarted).hasAttribute("href", "/docs/intro");
////
////            // Click the get started link.
//////            getStarted.click();
////            
//////            assertThat(browser.close()).hasAttribute("href", "/docs/intro");
////            
//////            page.pause();
////
////            // Expects page to have a heading with the name of Installation.
//////            assertThat(page.getByRole(AriaRole.HEADING,
//////               new Page.GetByRoleOptions().setName("Installation"))).isVisible();
////            page.close();
////            browser.close();
////            playwright.close();
////            
////            
////        }catch (Exception e) {
////			// TODO: handle exception
////		}
////    }
//
//}
