简体   繁体   English

在Selenium Webdriver中通过Java获取$ _SESSION参数

[英]Get $_SESSION parameters via Java in Selenium Webdriver

I am new with Selenium Webdriver and trying to create my first test cases for application that is constructed mostly with PHP . 我是Selenium Webdriver的新手,并试图为主要由PHP构建的应用程序创建我的第一个测试用例。 I am creating test cases with Java. 我正在用Java创建测试用例。

My first test case is testing login into the system. 我的第一个测试用例是测试登录到系统。 When I run my test, browser instance is started, login information is set into login form fields and login form is submitted. 当我运行测试时,将启动浏览器实例,将登录信息设置到登录表单字段中,然后提交登录表单。 After that browser dericets to used users start page as it should. 之后,浏览器就会按原样向使用过的用户启动页面。 So the test works as it should. 因此测试可以正常进行。

The problem is, I would like to check if the login was successful and save it in a testing report without a need for me to see the process trough in person. 问题是,我想检查登录是否成功,然后将其保存在测试报告中,而无需亲自查看过程。 I figured most valid way to ensure login success is to see if PHP code have created variable $_SESSION['logged_in'] = true as it does when login process is successful. 我认为确保登录成功的最有效方法是查看PHP代码是否已创建变量$_SESSION['logged_in'] = true就像登录过程成功时一样。 Is there any way for me to seek through $_SESSION variables with Java in my Selenium Webdriver test class? 我有什么办法可以在Selenium Webdriver测试类中使用Java搜索$_SESSION变量吗?

Honestly, don't know php, but in js eg any js variable can be recieved using next code 老实说,不了解php,但是在js中,例如,可以使用下一个代码接收任何js变量

driver.executeScript("return someGlobalVar");

Why you need to verify exactly value of $_SESSION variable?! 为什么需要验证$ _SESSION变量的值? I think successfull login verification can be done using other ways eg: a. 我认为可以使用其他方式来完成登录验证,例如: Verify that page contains some valid information related to currently logged user (eg name, other fields on the page) b. 确认该页面包含一些与当前登录用户有关的有效信息(例如,名称,页面上的其他字段)b。 Verify url c. 验证网址c。 By getting response from server (or smth like this) etc. Hope this will help. 通过从服务器(或类似的东西)等获得响应。希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM