找到 456 篇文章 關於軟體測試
928 次瀏覽
我們可以藉助繼承的概念在 Selenium Java 中處理可重用元件。這是一種父子關係,子類繼承父類的屬性和方法。示例:對於父類。import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Baseclass { public void login() throws IOException { Properties prop = new Properties(); // 從屬性檔案讀取值 FileInputStream ips = new FileInputStream( "C:\Users\ghs6kor\eclipse- workspace\Inheritance\config.properties"); prop.load(ips); System.setProperty("webdriver.gecko.driver", ... 閱讀更多
1K+ 次瀏覽
我們可以藉助 PROXY 類在 Java 的 Selenium 中處理代理。import java.io.IOException; import org.openqa.selenium.Proxy; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; public class ProxySelJav { public static void main(String[] args) { // TODO 自動生成的方法存根 WebDriver driver; String prox = "localhost:8080"; // 使用 Desired Capabilities 設定瀏覽器設定 Proxy p = new Proxy(); p.setHttpProxy(prox).setFtpProxy(prox).setSslProxy(prox) .setSocksProxy(prox); DesiredCapabilities c = new DesiredCapabilities(); c.setCapability(CapabilityType.PROXY, p); // 在啟動時使用功能 ... 閱讀更多
574 次瀏覽
由於以下原因,我們可能會遇到 SSL 證書問題:網站開發時,其 SSL 證書不正確。該網站可能具有自簽名證書。伺服器級別未正確配置 SSL。示例import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; public class SSLCert { public static void main(String[] args) { // TODO 自動生成的方法存根 // 通用 Chrome 配置檔案的所需功能 DesiredCapabilities c=DesiredCapabilities.chrome(); c.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true); c.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); // 本地瀏覽器的 ChromeOptions ... 閱讀更多
2K+ 次瀏覽
我們可以藉助 Properties 類(它與 .properties 檔案一起工作)在 Selenium 中宣告全域性變數。在 .properties 檔案中,資料以鍵值對的形式儲存。我們可以在 .properties 檔案中讀取和寫入值。示例import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Propert { public static void main(String[] args) throws IOException { // TODO 自動生成的方法存根 Propert t = new Propert(); t.login(); } public void login() throws IOException { Properties ... 閱讀更多
307 次瀏覽
我們可以藉助 TakesScreenshot 介面在 Selenium 中捕獲螢幕截圖。為了捕獲螢幕截圖並將其儲存在特定位置,使用 getScreenshotAs() 方法。示例import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.io.File; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; public class ScreenshotFull{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://tutorialspoint.tw/questions/index.php"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); // 使用 getScreenshotAs() 捕獲螢幕截圖並存儲在 //Screenshots 資料夾中 ... 閱讀更多
1K+ 次瀏覽
我們可以藉助 isMultiple() 方法在 Selenium 中驗證是否可以在靜態下拉列表中選擇多個選項。它返回 true 或 false 的布林值。示例import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.util.List; import org.openqa.selenium.support.ui.Select; public class OptionsMultiple{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://tutorialspoint.tw/tutor_connect/index.php"; Select s = new Select(driver.findElement(By.xpath("//select[@name=’selType’]"))); // isMultiple() 返回布林值 boolean result = s.isMultiple(); ... 閱讀更多
5K+ 次瀏覽
我們可以使用 findElements() 方法,透過 Select 類的 method 來選擇下拉列表中的特定值。示例import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.util.List; import org.openqa.selenium.support.ui.Select; public class OptionsClick{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://tutorialspoint.tw/tutor_connect/index.php"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); // 獲取具有 xpath 的元素列表 List opt = driver.findElements(By.xpath("//select[@name=’selType’]//option")); int s = opt.size(); ... 閱讀更多
10K+ 次瀏覽
Selenium 中 Select 類下選擇靜態下拉選單值的各種方法。它們列在下面:selectByVisibleText(String args)此方法最常用於下拉選單。使用此方法在下拉選單和多選框中選擇選項非常簡單。它接受一個 String 引數作為引數,並且不返回值。語法:Select s = new Select(driver.findElement(By.id(">"))); s.selectByVisibleText("Selenium");selectByIndex(String args)此方法採用下拉選單中要選擇的選項的索引。它接受一個 int 引數作為引數,並且不返回值。語法:Select s = new Select(driver.findElement(By.id(">"))); s.selectByIndex(1);selectByValue(String args)此方法採用下拉選單中要選擇的選項的值…… 閱讀更多
21K+ 次瀏覽
我們可以藉助 Select 類中的 getOptions() 方法在 Selenium 中提取下拉選單中的所有選項。此方法檢索 Select 標籤上的所有選項,並返回一個 Web 元素列表。此方法不接受任何引數。示例import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.util.List; import org.openqa.selenium.support.ui.Select; public class DropdownOptions{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = " https://tutorialspoint.tw/tutor_connect/index.php"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); ... 閱讀更多
917 次瀏覽
Selenium 中 Select 類下可用的各種方法列在下面:selectByVisibleText(String args)此方法最常用於下拉選單。使用此方法在下拉選單和多選框中選擇選項非常簡單。它接受一個 String 引數作為引數,並且不返回值。語法:Select s = new Select(driver.findElement(By.id(">"))); s.selectByVisibleText("Selenium");selectByIndex(String args)此方法採用下拉選單中要選擇的選項的索引。它接受一個 int 引數作為引數,並且不返回值。語法:Select s = new Select(driver.findElement(By.id(">"))); s.selectByIndex(1);selectByValue(String args)此方法採用下拉選單中要選擇的選項的值…… 閱讀更多
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP