selenium导出php代码,seleniumIDE安装和录制导出测试脚本的步骤

1、  先安装火狐浏览器Firefox

2、  在火狐浏览器Firefox输入栏,

54d778f69f6c8435a412f42d984fda0d.png

3、  点击按钮【Add to Firefox】,弹出下图

399eed4f82373ef9e36c822e58a6bb9d.png

4、  点击按钮【安装】,安装结束后,重启浏览器,就可以在开发者菜单看到Selenium IDE选项,如下图:

0b87fc0d7d298415ca8052cfa7117b4a.png

5、 打开Selenium IDE,界面如下图:

b6049c0610a489aa808c39d7208f8d41.png

6、打开火狐浏览器,输入测试访问地址http://192.168.199.110/chadmin/backend/web/index.php,登录操作

b07041a8dbdd2908d0e2554146242637.png

7、点击文件,选择Export Test Case As,选择Java/TestNG/WebDriver,导出脚本。

ea17c3027adaf945bfdcb59ff9de929f.png

8、 导出脚本如下:

package com.example.tests;

import java.util.regex.Pattern;

import java.util.concurrent.TimeUnit;

import org.testng.annotations.*;

import static org.testng.Assert.*;

import org.openqa.selenium.*;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.support.ui.Select;

public class Login {

private WebDriver driver;

private String baseUrl;

private boolean acceptNextAlert = true;

private StringBuffer verificationErrors = new StringBuffer();

@BeforeClass(alwaysRun = true)

public void setUp() throws Exception {

driver = new FirefoxDriver();

baseUrl = "http://192.168.199.110/chadmin/backend/web/index.php";

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

}

public void testLogin() throws Exception {

driver.get(baseUrl + "/chadmin/backend/web/index.php");

driver.findElement(By.id("username")).clear();

driver.findElement(By.id("username")).sendKeys("admin");

driver.findElement(By.id("password")).clear();

driver.findElement(By.id("password")).sendKeys("123456");

driver.findElement(By.id("login_btn")).click();

}

@AfterClass(alwaysRun = true)

public void tearDown() throws Exception {

driver.quit();

String verificationErrorString = verificationErrors.toString();

if (!"".equals(verificationErrorString)) {

fail(verificationErrorString);

}

}

private boolean isElementPresent(By by) {

try {

driver.findElement(by);

return true;

} catch (NoSuchElementException e) {

return false;

}

}

private boolean isAlertPresent() {

try {

driver.switchTo().alert();

return true;

} catch (NoAlertPresentException e) {

return false;

}

}

private String closeAlertAndGetItsText() {

try {

Alert alert = driver.switchTo().alert();

String alertText = alert.getText();

if (acceptNextAlert) {

alert.accept();

} else {

alert.dismiss();

}

return alertText;

} finally {

acceptNextAlert = true;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值