តើធ្វើដូចម្តេចដើម្បីផ្លាស់ប្តូរទំហំបង្អួចកម្មវិធីរុករកជាមួយសេលេញ៉ូម WebDriver? នៅទីនេះយើងពិនិត្យមើលវិធីបីយ៉ាងផ្សេងគ្នាដែលយើងអាចប្តូរទំហំផ្ទាំងវិនដូអ៊ីនធឺរណែតនៅក្នុង WebDriver ។
នៅពេលណាដែល WebDriver ចាប់ផ្តើមកម្មវិធីរុករកវាចាប់ផ្តើមវាដោយការកំណត់លំនាំដើម។ ពេលខ្លះវាត្រូវបានគេតម្រូវឱ្យផ្លាស់ប្តូរទំហំផ្ទាំងវិនដូកម្មវិធីរុករកជាពិសេសនៅពេលដែលយើងកំពុងធ្វើតេស្តរកគេហទំព័រដែលឆ្លើយតបពីព្រោះយើងត្រូវពិនិត្យមើលថាតើធាតុខុសគ្នានៅលើទំព័របង្ហាញយ៉ាងដូចម្តេចនៅពេលយើងផ្លាស់ប្តូរទំហំផ្ទាំងវិនដូរុករក។
Webdriver មានវិធីសាស្រ្តងាយស្រួលនិងវិធីផ្សេងៗគ្នាដែលអាចអោយយើងផ្លាស់ប្តូរទំហំ browser browser ។
ចាវ៉ា ដោយប្រើវិមាត្រ
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.Dimension; public class BrowserOperations {
WebDriver driver;
//this will open browser with default size
public void launchBrowser() {
driver = new FirefoxDriver();
}
public void resizeBrowser() {
Dimension d = new Dimension(800,480);
//Resize current window to the set dimension
driver.manage().window().setSize(d);
} }
ចាវ៉ា ប្រើជំរើស Chrome
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.DesiredCapabilities; public class BrowserOperations {
public static void main(String[] args) {
System.setProperty('webdriver.chrome.driver';,
'/path/to/chromedriver');
ChromeOptions options = new ChromeOptions();
options.addArguments('window-size=800,480');
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
//this will open chrome with set size
WebDriver driver = new ChromeDriver(capabilities);
driver.get('https://www.testingexcellence.com/');
} }
ប្រសិនបើអ្នកចង់ពង្រីកផ្ទាំងវិនដូអ៊ីនធឺណេតដល់ទទឹងនិងកំពស់អតិបរមារបស់អេក្រង់អ្នកគ្រាន់តែអាចហៅវិធីពង្រីកអតិបរិមា () ។
Webdriver driver = new FirefoxDriver(); driver.manage().window().maximize();
អំណានបន្ថែម៖