var webdriver = require(‘selenium-webdriver’),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser(‘chrome’)
.build();
driver.get(‘https://www.baidu.com’);
driver.findElement(By.id(‘kw’)).sendKeys(‘webdriver’);
driver.findElement(By.id(‘su’)).click();
driver.wait(until.titleIs(‘webdriver_百度搜索’), 1000);
driver.quit();
執(zhí)行姿勢,打開cmd執(zhí)行。
node baidu.js
chrome mobile emulation
有時候,需要模擬移動端瀏覽器測試。例子如下:
var webdriver = require(‘selenium-webdriver’),
By = webdriver.By,
until = webdriver.until,
chrome = require(‘selenium-webdriver/chrome’);
var driver = new webdriver.Builder()
.forBrowser(‘chrome’)
.setChromeOptions(new chrome.Options()
.setMobileEmulation({deviceName: ‘Google Nexus 5’}))
.build();
driver.get(‘https://m.baidu.com’);
driver.findElement(By.name(‘word’)).sendKeys(‘webdriver’);
driver.findElement(By.name(‘word’)).submit();
driver.wait(until.titleIs(‘webdriver - 百度’), 2000);
driver.quit();
Using the Builder API
The Builder class is your one-stop shop for configuring new WebDriver instances. Rather than clutter your code with branches for the various browsers, the builder lets you set all options in one flow. When you call Builder#build(), all options irrelevant to the selected browser are dropped:
var webdriver = require(‘selenium-webdriver’),
chrome = require(‘selenium-webdriver/chrome’),
firefox = require(‘selenium-webdriver/firefox’);
var driver = new webdriver.Builder()
.forBrowser(‘firefox’)
.setChromeOptions(/* … */)
.setFirefoxOptions(/* … */)
.build();
Why would you want to configure options irrelevant to the target browser? The Builder’s API defines your defaultconfiguration. You can change the target browser at runtime through the SELENIUM_BROWSER environment variable. For example, the example/google_search.js script is configured to run against Firefox. You can run the example against other browsers just by changing the runtime environment
cd node_modules/selenium-webdriver
node example/google_search
SELENIUM_BROWSER=chrome node example/google_search
SELENIUM_BROWSER=safari node example/google_search
The Standalone Selenium Server
The standalone Selenium Server acts as a proxy between your script and the browser-specific drivers. The server may be used when running locally, but it’s not recommend as it introduces an extra hop for each request and will slow things down. The server is required, however, to use a browser on a remote host (most browser drivers, like the IEDriverServer, do not accept remote connections).
To use the Selenium Server, you will need to install the JDK and download the latest server from Selenium. Once downloaded, run the server with
java -jar selenium-server-standalone-2.45.0.jar
You may configure your tests to run against a remote server through the Builder API:
var webdriver = require(‘selenium-webdriver’),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser(‘chrome’)
.usingServer(‘http://localhost:4444/wd/hub’) //注意這里
.build();
driver.get(‘https://www.baidu.com’);
driver.findElement(By.id(‘kw’)).sendKeys(‘webdriver’);
driver.findElement(By.id(‘su’)).click();
driver.wait(until.titleIs(‘webdriver_百度搜索’), 1000);
driver.quit();
Or change the Builder’s configuration at runtime with the?SELENIUM_REMOTE_URL?environment variable:
最后感謝每一個認(rèn)真閱讀我文章的人,禮尚往來總是要有的,這些資料,對于【軟件測試】的朋友來說應(yīng)該是最全面最完整的備戰(zhàn)倉庫,雖然不是什么很值錢的東西,如果你用得到的話可以直接拿走:
這些資料,對于【軟件測試】的朋友來說應(yīng)該是最全面最完整的備戰(zhàn)倉庫,這個倉庫也陪伴上萬個測試工程師們走過最艱難的路程,希望也能幫助到你!
自我介紹一下,小編13年上海交大畢業(yè),曾經(jīng)在小公司待過,也去過華為、OPPO等大廠,18年進入阿里一直到現(xiàn)在。
深知大多數(shù)軟件測試工程師,想要提升技能,往往是自己摸索成長或者是報班學(xué)習(xí),但對于培訓(xùn)機構(gòu)動則幾千的學(xué)費,著實壓力不小。自己不成體系的自學(xué)效果低效又漫長,而且極易碰到天花板技術(shù)停滯不前!
因此收集整理了一份《2024年軟件測試全套學(xué)習(xí)資料》,初衷也很簡單,就是希望能夠幫助到想自學(xué)提升又不知道該從何學(xué)起的朋友,同時減輕大家的負(fù)擔(dān)。
既有適合小白學(xué)習(xí)的零基礎(chǔ)資料,也有適合3年以上經(jīng)驗的小伙伴深入學(xué)習(xí)提升的進階課程,基本涵蓋了95%以上軟件測試開發(fā)知識點,真正體系化!
由于文件比較大,這里只是將部分目錄大綱截圖出來,每個節(jié)點里面都包含大廠面經(jīng)、學(xué)習(xí)筆記、源碼講義、實戰(zhàn)項目、講解視頻,并且后續(xù)會持續(xù)更新
如果你覺得這些內(nèi)容對你有幫助,可以添加V獲取:vip1024b (備注軟件測試)
一個人可以走的很快,但一群人才能走的更遠。不論你是正從事IT行業(yè)的老鳥或是對IT行業(yè)感興趣的新人,都?xì)g迎掃碼加入我們的的圈子(技術(shù)交流、學(xué)習(xí)資源、職場吐槽、大廠內(nèi)推、面試輔導(dǎo)),讓我們一起學(xué)習(xí)成長!文章來源地址http://www.zghlxwxcb.cn/news/detail-857730.html
件測試)**
[外鏈圖片轉(zhuǎn)存中…(img-v5lhJfTq-1712878245460)]文章來源:http://www.zghlxwxcb.cn/news/detail-857730.html
一個人可以走的很快,但一群人才能走的更遠。不論你是正從事IT行業(yè)的老鳥或是對IT行業(yè)感興趣的新人,都?xì)g迎掃碼加入我們的的圈子(技術(shù)交流、學(xué)習(xí)資源、職場吐槽、大廠內(nèi)推、面試輔導(dǎo)),讓我們一起學(xué)習(xí)成長!
到了這里,關(guān)于JavaScript+Selenium自動化測試_selenium和js能一起做自動化測試的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!