標籤:amp text img 控制指令 class bool smi cat port
==========================================================================================================
寫在前面:
Selenium IDE是FireFox的整合外掛程式,目前而言,只能通過FireFox來錄製指令碼。
但是實際工作中,我們可能需要測試IE或者Chrome等其他瀏覽器,那麼,可以通過其他途徑來實現這個願望。詳細看下文。
==========================================================================================================
8. Selenium IDE- 不同的瀏覽器
Selenium IDE指令碼只能對Firefox的工具Firefox外掛程式運行測試。
使用Selenium-IDE開發的測試可以對其他瀏覽器所儲存為Selenium網路磁碟機或硒的遠端控制指令碼執行。
指令碼只能對Firefox的工具Firefox外掛程式運行測試。
使用Selenium-IDE開發的測試可以對其他瀏覽器所儲存為Selenium網路磁碟機或硒的遠端控制指令碼執行。
更多關於Selenium的webdriver和Selenium的遠端控制,在後面的章節有詳細講解。
第1步:開啟Selenium IDE任何已儲存的測試
第2步:定位到“File”菜單,並選擇“Export Test Suite As”,而選擇將被列出。
第3步:現在讓我們匯出指令碼“WebDriver”,並將其儲存為同樣的名稱。
第4步:如所示,顯示儲存webdriver檔案。
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 BaiduSearch1 { 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 = "https://www.baidu.com/"; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } @Test public void testBaiduSearch1() throws Exception { driver.get(baseUrl + "/"); // ERROR: Caught exception [unknown command []] driver.findElement(By.id("kw")).clear(); driver.findElement(By.id("kw")).sendKeys("selenium"); driver.findElement(By.id("su")).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; } }}
以上為IDE匯出的Java代碼,可以通過其他途徑來執行測試案例,運行到Chrome等瀏覽器上。
==========================================================================================================
學習小結:
1. 關於Selenium IDE的內容學習就告一段落了。
Selenium IDE執行的局限性和錄製指令碼/回放指令碼等,包括自己去面試的時候提到的錄製指令碼,被別人嘲笑,所以決定學習更多的關於Selenium
方面的內容。
那麼接下來,將學習Selenium/WebDriver的實際開發,相信會是另外一番學習體驗。
==========================================================================================================
【Selenium-WebDriver自學】Selenium-IDE不同的瀏覽器(八)