def __call__(self): # The cache of cookies for each worker thread will be reset at # the start of each run. result = request1.GET("http://localhost:7001/console/?request1") # If the first response set any cookies for the domain, # they willl be sent back with this request. result2 = request1.GET("http://localhost:7001/console/?request2") # Now let's add a new cookie. threadContext = HTTPPluginControl.getThreadHTTPClientContext() expiryDate = Date() expiryDate.year += 10 cookie = Cookie("key", "value", "localhost", "/", expiryDate, 0) CookieModule.addCookie(cookie, threadContext) result = request1.GET("http://localhost:7001/console/?request3") # Get all cookies for the current thread and write them to the log cookies = CookieModule.listAllCookies(threadContext) for c in cookies: log("retrieved cookie: %s" % c) # Remove any cookie that isn't ours. for c in cookies: if c != cookie: CookieModule.removeCookie(c, threadContext) result = request1.GET("http://localhost:7001/console/?request4")
def __call__(self): # The cache of cookies for each worker thread will be reset at # the start of each run. result = request1.GET("http://localhost:7001/console/?request1") # If the first response set any cookies for the domain, # they willl be sent back with this request. result2 = request1.GET("http://localhost:7001/console/?request2") # Now let's add a new cookie. threadContext = HTTPPluginControl.getThreadHTTPClientContext() expiryDate = Date() expiryDate.year += 10 cookie = Cookie("key", "value","localhost", "/", expiryDate, 0) CookieModule.addCookie(cookie, threadContext) result = request1.GET("http://localhost:7001/console/?request3") # Get all cookies for the current thread and write them to the log cookies = CookieModule.listAllCookies(threadContext) for c in cookies: log("retrieved cookie: %s" % c) # Remove any cookie that isn't ours. for c in cookies: if c != cookie: CookieModule.removeCookie(c, threadContext) result = request1.GET("http://localhost:7001/console/?request4")
def __call__(self): sumStatusCode = [0L, 0L, 0L, 0L] for c in self.login_cookies: CookieModule.addCookie(c, self.threadContext) PTS.sumHttpCode(tenant(), sumStatusCode) if sum(sumStatusCode[1:4]) > 0: grinder.statistics.forLastTest.success = 0 grinder.logger.error(u'事务请求中http 返回状态大于300,请检查请求是否正确!') else: grinder.statistics.forLastTest.success = 1
def doit(self): if linkdrop_static_per_send: for i in range(0,linkdrop_static_per_send): getStatic(linkdrop_static_url) if self.csrf is None or \ (sends_per_oauth and grinder.getRunNumber() % sends_per_oauth==0): self.csrf, self.linkdrop_cookie = getCSRF() self.userid = authService(self.csrf) # cookies are reset by the grinder each test run - re-inject the # linkdrop session cookie. threadContext = HTTPPluginControl.getThreadHTTPClientContext() CookieModule.addCookie(self.linkdrop_cookie, threadContext) send(self.userid, self.csrf)
def __call__(self): grinder.statistics.delayReports = 1 ##### Set to the cookies for login ##### threadContext = HTTPPluginControl.getThreadHTTPClientContext() for c in self.cookies: CookieModule.addCookie(c,threadContext) ##### Request with login ##### result = request1.GET("/mypage") if result.text.count("only my content data") < 0: grinder.statistics.forLastTest.success = 0 else : grinder.statistics.forLastTest.success = 1
def __call__(self): grinder.statistics.delayReports = 1 ##### Set to the cookies for login ##### threadContext = HTTPPluginControl.getThreadHTTPClientContext() for c in self.cookies: CookieModule.addCookie(c,threadContext) ##### Request with login ##### result = request1.GET("/mypage") if result.text.count("only my content data") < 0: grinder.statistics.forLastTest.success = 0 else : grinder.statistics.forLastTest.success = 1
def setStubbornAuthToken(): threadContext = HTTPPluginControl.getThreadHTTPClientContext() cookies = CookieModule.listAllCookies(threadContext) for cookie in cookies: if cookie.getName() == 'sso.auth_token': CookieModule.removeCookie(cookie, threadContext) expiryDate = Date() expiryDate.year += 10 stubbornAuthToken = StubbornCookie('sso.auth_token', cookie.getValue(), '.wgenhq.net', '/', expiryDate, False) CookieModule.addCookie(stubbornAuthToken, threadContext) grinder.logger.output("Replaced sso.auth_token with a stubborn version of itself")
def doit(self): if linkdrop_static_per_send: for i in range(0,linkdrop_static_per_send): getStatic(linkdrop_static_url) if (sends_per_oauth and grinder.getRunNumber() % sends_per_oauth==0): self.linkdrop_cookie = None self.userid = None if self.userid is None: self.userid, self.linkdrop_cookie = authService() # cookies are reset by the grinder each test run - re-inject the # linkdrop session cookie. threadContext = HTTPPluginControl.getThreadHTTPClientContext() CookieModule.addCookie(self.linkdrop_cookie, threadContext) send(self.userid)
def __call__(self): sumStatusCode = [0L, 0L, 0L, 0L] #因为每次执行测试cookie会被清空,所以这里需要每次重新设置cookie for c in self.login_cookies: CookieModule.addCookie(c, self.threadContext) PTS.sumHttpCode(tenant(), sumStatusCode) # if you want to print out log.. Don't use print keyword. Instead, use following. #grinder.logger.info(str(sumStatusCode)) # statusCode[0]代表http code < 300 个数, statusCode[1] 代表 300<=http code<400 个数 # statusCode[2]代表400<=http code<500个数, statusCode[3] 代表 http code >=500个数 # 如果http code 300 到 400 之间是正常的 # 那么判断事务失败,请将statusCode[1:4] 改为 statusCode[2:4] 即可 if sum(sumStatusCode[1:4]) > 0: grinder.statistics.forLastTest.success = 0 grinder.logger.error(u'事务请求中http 返回状态大于300,请检查请求是否正确!') else: grinder.statistics.forLastTest.success = 1
def __call__(self): PTS.Data.delayReports = 1 for c in self.init_cookies: CookieModule.addCookie(c, self.threadContext) # DealUser注册 result = self.registerDealUser() PTS.Framework.setExtraData(result["statusCode"]) dealUserId = result["dealUserId"] accessToken = result["accessToken"] # 开始访问网站 result = self.startAccessSite(dealUserId, accessToken) PTS.Framework.setExtraData(result["statusCode"]) logId = result["logId"] # 循环控制器 for i in range(1, 5): pageNum = str(i) # 开始访问页面 result = self.startViewPage(dealUserId, logId, pageNum, accessToken) PTS.Framework.setExtraData(result["statusCode"]) viewLogId = result["viewLogId"] for j in range(5): # 线程睡眠1秒 PTS.Thread.sleep(5000) # 定时更新页面访问结束时间 statusCode = self.updateViewPageEndTime( dealUserId, logId, pageNum, viewLogId, accessToken) PTS.Framework.setExtraData(statusCode) # 提交关键行为 statusCode = self.submitKeyBehaviour(dealUserId, logId, pageNum, viewLogId, accessToken) PTS.Framework.setExtraData(statusCode) PTS.Data.report() PTS.Data.delayReports = 0
def __del__(self): for c in self.init_cookies: CookieModule.addCookie(c, self.threadContext)
def before(self): request1.setHeaders(headers) for c in cookies: CookieModule.addCookie( c, HTTPPluginControl.getThreadHTTPClientContext())