selenium php环境怎么搭建

selenium php环境搭建方法:1、下载最新线程安全版PHP zip压缩包;2、复制一份“php.ini-development”改名为“php.ini”放到安装路径下;3、设置系统变量下的Path为“D:Softwarephp-7.2.28-Win32-VC15-x64;”即可。

selenium php环境怎么搭建

本教程操作环境:windows7系统、PHP8.1版、Dell G3电脑。

selenium php环境怎么搭建?

windows环境下的PHP+selenium环境搭建

最近想要入门自动化测试,之前也写过使用codeception进行单元测试和接口测试,UI测试部分我选择了selenium框架,接下来我们来进行相关环境的搭建。

立即学习“PHP免费学习笔记(深入)”;

PHP环境的搭建

1、进入PHP下载地址 http://windows.php.net/download 下载最新线程安全版PHP zip压缩包,解压缩后放在想要安装的路径下。(此处需要注意,win7系统不能用php7.4版本,会提示丢失 VCRUNTIME140.dll)

2、进入PHP安装目录,复制一份php.ini-development 改名为 php.ini 放到安装路径下,打开找到 ;extension_dir=ext,去掉注释符,将值改为 PHP安装路径ext

3、右键计算机->属性->高级系统设置->环境变量->系统变量下的Path,点击编辑,在后面加上PHP的路径D:Softwarephp-7.2.28-Win32-VC15-x64;

至此,PHP安装完成,可打开cmd查看对应的版本,如图:

selenium php环境怎么搭建

java运行环境的搭建,这里需要说明一下selenium运行文件是一个jar包,你必须搭建好java运行的环境才能启用selenium。

进入官网,https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html,找到适配的版本,下载jdk。

selenium php环境怎么搭建

 下载selenium文件,http://selenium-release.storage.googleapis.com/index.html (selenium 下载地址)下载selenium-server-standalone-3.8.0.jar的jar包文件,版本可自行选择

下载浏览器驱动文件(这里需要注意的是:一定要下载与本机安装浏览器版本匹配的驱动文件) 。Google浏览器使用的驱动文件名为:   chromedriver,https://chromedriver.storage.googleapis.com/index.html (chrome driver 下载地址)。Firefox的驱动文件名为:geckodriver.exe,https://docs.seleniumhq.org/download/(selenium官网去下载,选择java的)

   chrom和chromedriver的版本对应可查看每个版本里面的note,chrome的版本号可通过chrome://settings/help查看

selenium php环境怎么搭建

selenium php环境怎么搭建

注意:下载完成的驱动文件要放在php的根目录下

selenium php环境怎么搭建

 下载 PHP+selenium 的demo文件,https://github.com/facebook/php-webdriver (里面有example.php以及 tests文件下的案例文档共参考)。

写好demo之后你就可以进行测试了,首先运行下载的selenium的jar包文件,在cmd命令行中进入你放置selenium文件的目录然后执行以下命令(注意:需要在第二步中配置java运行环境变量)           java -jar selenium-server-standalone-3.8.0.jar 。     如果你的命令行出现了以下提示那就是启动成功了。

 selenium php环境怎么搭建

 在执行example.php的时候,Notice: Undefined index: ELEMENT in D:estendoracebookwebdriverlibRemoteRemoteWebDriver.php on line 178,

经查,是因为较新版本的selenium的通信协议变动导致的,可在启动时加上相关的参数控制:

java -jar selenium-server-standalone-3.8.0.jar -enablePassThrough false至此,通过编写example.php文件便可实现简单的自动登录流程。

登录后复制

运行exam.php之前,需要将ekwing下vendor目录复制一份到phpDirver目录下

可修改example.php实现别的网站自动登录,example.php如下:

manage()->window()->maximize();// navigate to Selenium page on Wikipedia$driver->get('http://www.baidu.com/Login/s?name=lzxx');// write 'PHP' in the search box$driver->findElement(WebDriverBy::id('name')) // find search input element->sendKeys('xxxx'); // fill the search box$driver->findElement(WebDriverBy::id('xxxx'))    ->sendKeys('88888888');//$driver->submit(); // submit the whole form// wait until 'PHP' is shown in the page heading element//$driver->wait()->until(//    WebDriverExpectedCondition::elementTextContains(WebDriverBy::id('firstHeading'), 'PHP')//);// print title of the current page to outputecho "The title is '" . $driver->getTitle() . "'";// print URL of current page to outputecho "The current URL is '" . $driver->getCurrentURL() . "'";// find element of 'History' item in menu//$historyButton = $driver->findElement(//    WebDriverBy::cssSelector('#jsLoginBtn')//);$historyButton = $driver->findElement(    WebDriverBy::id('jsLoginBtn'));// read text of the element and print it to outputecho "About to click to button with text: '" . $historyButton->getText() . "'";// click the element to navigate to revision history page$historyButton->click();// wait until the target page is loaded$driver->wait()->until(    WebDriverExpectedCondition::titleContains('教师首页'));// print the title of the current pageecho "The title is '" . $driver->getTitle() . "'";// print the URI of the current pageecho "The current URI is '" . $driver->getCurrentURL() . "'";// delete all cookies//$driver->manage()->deleteAllCookies();// add new cookie$cookie = new Cookie('cookie_set_by_selenium', 'cookie_value');$driver->manage()->addCookie($cookie);// dump current cookies to output$cookies = $driver->manage()->getCookies();print_r($cookies);$driver->get('http://www.ekwing.com/exam/teacher/selflist');// close the browser//$driver->quit();

登录后复制

题外话:因为selenium没有支持PHP语言的集成框架,因此我们要使用selenium在项目中进行功能测试的话,需要自己将各个脚本组合,差不多就是写个框架了。

推荐学习:《PHP视频教程》

以上就是selenium php环境怎么搭建的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2076312.html

(0)
上一篇 2025年2月24日 08:47:21
下一篇 2025年2月19日 15:13:18

AD推荐 黄金广告位招租... 更多推荐

相关推荐

  • php怎么实现定位功能

    php实现定位功能的方法:1、注册成为百度用户,成为地图开放平台开发者;2、获取服务密钥;3、通过百度地图API接口获取经纬度;4、通过API接口定位到具体位置即可。 本教程操作环境:windows7系统、PHP8.1版、Dell G3电脑…

    2025年2月24日
    200
  • idea怎么搭建php

    idea搭建php的方法:1、下载wampserver并安装;2、设置系统php的path环境变量;3、下载对应wamp版本的“phpunit.phar”;4、idea安装php插件即可。 本教程操作环境:windows7系统、PHP8.1…

    2025年2月24日 编程技术
    200
  • php怎么实现短信验证

    php实现短信验证的方法:1、注册账号并下载接口;2、配置参数变量;3、调用接口测试短信;4、通过代码“if(strtolower($_SESSION[“captcha”]) == strtolower($captc…

    2025年2月24日
    200
  • php证书授权失效怎么办

    php证书授权失效的解决办法:1、进入服务器终端,执行“wget –no-check-certificate https://curl.haxx.se/ca/cacert.pem”命令下载根证书;2、修改配置文件;3、重启PHP…

    2025年2月24日
    200
  • 断电后php文件乱码怎么办

    断电后php文件乱码的解决办法:1、重启电脑;2、用phpstorm打开相应的php文件;3、在phpstorm界面中右击;4、找到“local history”,查看历史记录并恢复即可。 本教程操作环境:windows7系统、PHP8.1…

    2025年2月24日
    200
  • php function 报错怎么办

    php function报错的解决办法:1、运行相应的php文件,检查报错信息;2、找到“$name = $_GET(“name”);”代码;3、修改“$_GET(“”)”为“$_GET[&#…

    2025年2月24日
    200
  • php6为什么没有

    没有php6的原因:1、开发小组认为,如果不能完全解决Unicode就不能称之为php6;2、当初提出开发php6的草案有点操之过急,需要解决的问题超出当时想像;3、开发成员并未对php6展现出100%的热情,从另一个方面来说,解决Unic…

    2025年2月24日
    200
  • php passthru 乱码怎么办

    php passthru乱码的解决办法:1、运行相应的php文件;2、检查输出“echo passthru(“ipconfig”);”;3、在原文件的开头处添加“header(“content-type:…

    2025年2月24日
    200
  • mac升级php后不能用了怎么办

    mac升级php后不能用了的解决办法:1、设置php.ini的时区;2、找到“;date.timezone =”改为“date.timezone = Asia/Shanghai”;3、启动myql服务;4、配置rewrite即可。 本教程操…

    2025年2月24日
    200
  • php无法使用postgresql怎么办

    php无法使用postgresql的解决办法:1、检查php连接pgsql时提示的错误信息;2、找到并打开php配置文件“php.ini”;3、去掉“extension=php_pdo_pgsql.dll”和“extension=php_p…

    2025年2月24日
    200

发表回复

登录后才能评论