Selenium教程

WebDriver IE上运行测试

在本节中,您将学习如何在IE浏览器上运行Selenium测试脚本。
Internet Explorer使用Internet Explorer驱动程序服务器实现WebDriver协议。 Internet Explorer驱动程序服务器是Selenium中的测试和Internet Explorer浏览器之间的链接。
让我们考虑一个测试用例,在该用例中,我们将尝试在IE浏览器中自动执行以下方案。
启动IE浏览器。 打开URL: www.google.com 最大化浏览器。 输入值" lidihuo教程" 单击"搜索"按钮。
我们将在同一测试套件(Demo_Test)中创建第四个测试用例。
Step1、右键单击" src"文件夹,然后从"新建">"类"创建一个新的类文件。将您的班级名称命名为"第四",然后单击"完成"按钮。

在IE浏览器上运行的SeleniumWebDriver运行测试
运行SeleniumWebDriver在IE浏览器上进行测试
Step2、打开网址: http://selenium-release。在浏览器中进入storage.googleapis.com/index.html?path=2.48/。
Step3、选择最新版本并根据您当前正在使用的操作系统下载。
对于Windows 64位,请单击"IEDriverServer x64 2.48.0 zip"下载。

Selenium WebDriver在IE浏览器上运行测试
下载的文件为压缩格式。将内容解压缩到一个方便的目录中。在IE浏览器上"

Step4、将系统属性" webdriver.ie.driver"设置为IEDriverServer.exe文件的路径,并实例化IEDriver类。
以下是执行此操作的示例代码。
// System Property for IEDriver 
System.setProperty("webdriver.ie.driver", "D:\\IE Driver Server\\IEDriverServer.exe");
        
     // Instantiate a IEDriver class.   
WebDriver driver=new InternetExplorerDriver();
Step5、现在该进行编码了。我们在每个代码块中都嵌入了注释,以清楚地说明这些步骤。
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Fourth {
    public static void main(String[] args) {
    
            // System Property for IEDriver 
        System.setProperty("webdriver.ie.driver", "D:\\IE Driver Server\\IEDriverServer.exe");
        
           // Instantiate a IEDriver class.     
        WebDriver driver=new InternetExplorerDriver();
        
           // Launch Website
        driver.navigate().to("http://www.google.com/");
        
           //Maximize the browser
          driver.manage().window().maximize();
          
           // Click on the search text box and send value
        driver.findElement(By.id("lst-ib")).sendKeys("lidihuo tutorials");
            
           // Click on the search button
        driver.findElement(By.name("btnK")).click();
          
    }
}
Eclipse代码窗口将如下所示:

 Selenium WebDriver在IE浏览器上运行测试
Step6、右键单击Eclipse代码,然后选择运行方式

Selenium WebDriver在IE浏览器上运行测试
Step7、以上测试脚本的输出将显示在Internet Explorer浏览器中。

Selenium WebDriver在IE浏览器上运行测试
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4