Selenium Webdriver API -role hub表示启动运行hub; https://192.168.43.58:4444/ Nodes should register to https://192.168.43.58:4444/grid/register/ -role node:表示启动的是node节点文章目录
Selenium Grid 测试
专门用于在不同的浏览器、操作系统和机器上并行运行多个测试(兼容性测试)。
参考
https://wangxiwei.gitbooks.io/webdriver-python/content/
配置环境
下载https://selenium-release.storage.googleapis.com/index.html
启动Hub
-port是设置端口号,hub的默认端口是4444
-maxSession为最大会话请求,这个参数主要要用并发执行测试用例,默认是1java -jar c:/third/selenium-server-standalone-3.5.3.jar -role hub -maxSession 10 -port 4444
验证Hub控制台
启动节点1
-port 5555:指定node节点端口
-hub https://localhost:4444/grid/register:表示hub机地址
-maxSession 5:node节点最大会话请求
-browser browserName=firefox,seleniumProtocol=WebDriver,maxInstances=5,platform=WINDOWS 设置浏览器的参数
maxInstances表示最大实例,最多可运行的浏览器数,不能大于前面maxSession的值java -jar c:/third/selenium-server-standalone-3.5.3.jar -role node -port 5555 -hub https://localhost:4444/grid/register -maxSession 5 -browser browserName=firefox,seleniumProtocol=WebDriver,maxInstances=5
主节点显示
控制台
节点2
java -jar c:/third/selenium-server-standalone-3.5.3.jar -role node -port 6666 -hub https://localhost:4444/grid/register -maxSession 5 -browser browserName=chrome,seleniumProtocol=WebDriver,maxInstances=5
Remote测试(Java)
Remote测试(python)
DesiredCapabilities
pytest代码分析
脚本录制
// Generated by Selenium IDE import org.junit.Test; import org.junit.Before; import org.junit.After; import static org.junit.Assert.*; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.core.IsNot.not; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.Dimension; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.Alert; import org.openqa.selenium.Keys; import java.util.*; import java.net.MalformedURLException; import java.net.URL; public class T1Test { private WebDriver driver; private Map<String, Object> vars; JavascriptExecutor js; @Before public void setUp() { driver = new FirefoxDriver(); js = (JavascriptExecutor) driver; vars = new HashMap<String, Object>(); } @After public void tearDown() { driver.quit(); } public String waitForWindow(int timeout) { try { Thread.sleep(timeout); } catch (InterruptedException e) { e.printStackTrace(); } Set<String> whNow = driver.getWindowHandles(); Set<String> whThen = (Set<String>) vars.get("window_handles"); if (whNow.size() > whThen.size()) { whNow.removeAll(whThen); } return whNow.iterator().next(); } @Test public void t1() { driver.get("https://www.baidu.com/"); driver.manage().window().setSize(new Dimension(881, 694)); driver.findElement(By.id("kw")).sendKeys("hadoop"); driver.findElement(By.id("kw")).sendKeys(Keys.ENTER); vars.put("window_handles", driver.getWindowHandles()); driver.findElement(By.linkText("Hadoop_百度百科")).click(); vars.put("win3844", waitForWindow(2000)); driver.switchTo().window(vars.get("win3844").toString()); { WebElement element = driver.findElement(By.cssSelector(".summary-pic img")); Actions builder = new Actions(driver); builder.moveToElement(element).perform(); } { WebElement element = driver.findElement(By.tagName("body")); Actions builder = new Actions(driver); builder.moveToElement(element, 0, 0).perform(); } } }
Java脚本
import org.eclipse.jetty.util.thread.ThreadClassLoaderScope; import org.openqa.selenium.*; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import java.net.MalformedURLException; import java.net.URL; public class Test { public static void main(String[] args) { testBaidu("firefox"); // testBaidu("chrome"); } public static void testBaidu(String browserName){ DesiredCapabilities capability = new DesiredCapabilities(); capability.setBrowserName(browserName); capability.setPlatform(Platform.WINDOWS); try { //List list =new ArrayList<>() WebDriver driver = new RemoteWebDriver(new URL("https://localhost:4444/wd/hub"), capability); driver.get("https://www.baidu.com"); //输入 hadoop查询 driver.findElement(By.cssSelector("#kw")).sendKeys("hadoop" + Keys.ENTER); //获得当前窗口url String curUrl = driver.getCurrentUrl(); System.out.println(" browser:"+browserName+" url:"+curUrl); //使用close()方法关闭浏览器后,并不会清除临时文件中的webdriver临时文件 //driver.close(); //使用quit()关闭浏览器后,会自动删除临时文件夹 //driver.quit(); } catch ( MalformedURLException e) { e.printStackTrace(); } } }
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算