溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

selenium面試題有哪些

發(fā)布時間:2021-12-18 10:58:35 來源:億速云 閱讀:125 作者:小新 欄目:大數(shù)據(jù)

小編給大家分享一下selenium面試題有哪些,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

1.selenium中如何判斷元素是否存在?

selenium中沒有提供原生的方法判斷元素是否存在,一般我們可以通過定位元素+異常捕獲的方式判斷。

```

# 判斷元素是否存在try:

    dr.find_element_by_id('none')except NoSuchElementException:

    print 'element does not exist'

```

2.selenium中hidden或者是display = none的元素是否可以定位到?

不可以,selenium不能定位不可見的元素。display=none的元素實際上是不可見元素。

3.selenium中如何保證操作元素的成功率?也就是說如何保證我點擊的元素一定是可以點擊的?

被點擊的元素一定要占一定的空間,因為selenium默認(rèn)會去點這個元素的中心點,不占空間的元素算不出來中心點;

被點擊的元素不能被其他元素遮擋;

被點擊的元素不能在viewport之外,也就是說如果元素必須是可見的或者通過滾動條操作使得元素可見;

使用element.is_enabled()(python代碼)判斷元素是否是可以被點擊的,如果返回false證明元素可能灰化了,這時候就不能點;

4.如何提高selenium腳本的執(zhí)行速度?

使用效率更高的語言,比如java執(zhí)行速度就快過python

不要盲目的加sleep,盡量使用顯示等待

對于firefox,考慮使用測試專用的profile,因為每次啟動瀏覽器的時候firefox會創(chuàng)建1個新的profile,對于這個新的profile,所有的靜態(tài)資源都是從服務(wù)器直接下載,而不是從緩存里加載,這就導(dǎo)致網(wǎng)絡(luò)不好的時候用例運行速度特別慢的問題

chrome瀏覽器和safari瀏覽器的執(zhí)行速度看上去是最快的

可以考慮分布式執(zhí)行或者使用selenium grid

5.用例在運行過程中經(jīng)常會出現(xiàn)不穩(wěn)定的情況,也就是說這次可以通過,下次就沒辦法通過了,如何去提升用例的穩(wěn)定性?

測試專屬profile,盡量讓靜態(tài)資源緩存

盡量使用顯示等待

盡量使用測試專用環(huán)境,避免其他類型的測試同時進(jìn)行,對數(shù)據(jù)造成干擾

 

6.你的自動化用例的執(zhí)行策略是什么?

每日執(zhí)行:比如每天晚上在主干執(zhí)行一次

周期執(zhí)行:每隔2小時在開發(fā)分之執(zhí)行一次

動態(tài)執(zhí)行:每次代碼有提交就執(zhí)行

7.什么是持續(xù)集成?

可以自行百度,學(xué)習(xí)能力自我提升很重要(1079636098)軟件測試技術(shù)交流群推薦。

8.自動化測試的時候是不是需要連接數(shù)據(jù)庫做數(shù)據(jù)校驗?

一般不需要,因為這是單元測試層做的事情,在自動化測試層盡量不要為單元測試層沒做的工作還債。

9.id,name,clas,x path, css selector這些屬性,你最偏愛哪一種,為什么?

xpath和css最為靈活,所以其他的答案都不夠完美。

10如何去定位頁面上動態(tài)加載的元素?

顯示等待

11.如何去定位屬性動態(tài)變化的元素?

找出屬性動態(tài)變化的規(guī)律,然后根據(jù)上下文生成動態(tài)屬性。

12.點擊鏈接以后,selenium是否會自動等待該頁面加載完畢?

java binding在點擊鏈接后會自動等待頁面加載完畢。

13.webdriver client的原理是什么?

selenium的原理涉及到3個部分,分別是

瀏覽器

driver: 一般我們都會下載driver

client: 也就是我們寫的代碼

client其實并不知道瀏覽器是怎么工作的,但是driver知道,在selenium啟動以后,driver其實充當(dāng)了服務(wù)器的角色,跟client和瀏覽器通信,client根據(jù)webdriver協(xié)議發(fā)送請求給driver,driver解析請求,并在瀏覽器上執(zhí)行相應(yīng)的操作,并把執(zhí)行結(jié)果返回給client。這就是selenium工作的大致原理。

14.webdriver的協(xié)議是什么?

client與driver之間的約定,無論client是使用java實現(xiàn)還是c#實現(xiàn),只要通過這個約定,client就可以準(zhǔn)確的告訴drier它要做什么以及怎么做。

webdriver協(xié)議本身是http協(xié)議,數(shù)據(jù)傳輸使用json。

這里有webdriver協(xié)議的所有endpoint,稍微看一眼就知道這些endpoints涵蓋了selenium的所有功能。

15.啟動瀏覽器的時候用到的是哪個webdriver協(xié)議?

New Session,如果創(chuàng)建成功,返回sessionId和capabilities。

16.什么是page object設(shè)計模式?

簡單來說就是用class去表示被測頁面。在class中定義頁面上的元素和一些該頁面上專屬的方法。

例子

```

public class LoginPage { private final WebDriver driver; public LoginPage(WebDriver driver) { this.driver = driver; // Check that we're on the right page. if (!"Login".equals(driver.getTitle())) { // Alternatively, we could navigate to the login page, perhaps logging out first throw new IllegalStateException("This is not the login page"); } } // The login page contains several HTML elements that will be represented as WebElements. // The locators for these elements should only be defined once. By usernameLocator = By.id("username"); By passwordLocator = By.id("passwd"); By loginButtonLocator = By.id("login"); // The login page allows the user to type their username into the username field public LoginPage typeUsername(String username) { // This is the only place that "knows" how to enter a username driver.findElement(usernameLocator).sendKeys(username); // Return the current page object as this action doesn't navigate to a page represented by another PageObject return this; } // The login page allows the user to type their password into the password field public LoginPage typePassword(String password) { // This is the only place that "knows" how to enter a password driver.findElement(passwordLocator).sendKeys(password); // Return the current page object as this action doesn't navigate to a page represented by another PageObject return this; } // The login page allows the user to submit the login form public HomePage submitLogin() { // This is the only place that submits the login form and expects the destination to be the home page. // A seperate method should be created for the instance of clicking login whilst expecting a login failure. driver.findElement(loginButtonLocator).submit(); // Return a new page object representing the destination. Should the login page ever // go somewhere else (for example, a legal disclaimer) then changing the method signature // for this method will mean that all tests that rely on this behaviour won't compile. return new HomePage(driver); } // The login page allows the user to submit the login form knowing that an invalid username and / or password were entered public LoginPage submitLoginExpectingFailure() { // This is the only place that submits the login form and expects the destination to be the login page due to login failure. driver.findElement(loginButtonLocator).submit(); // Return a new page object representing the destination. Should the user ever be navigated to the home page after submiting a login with credentials // expected to fail login, the script will fail when it attempts to instantiate the LoginPage PageObject. return new LoginPage(driver); } // Conceptually, the login page offers the user the service of being able to "log into" // the application using a user name and password. public HomePage loginAs(String username, String password) { // The PageObject methods that enter username, password & submit login have already defined and should not be repeated here. typeUsername(username); typePassword(password); return submitLogin(); } }

```

17.什么是page factory設(shè)計模式?

實際上是官方給出的java page object的工廠模式實現(xiàn)。

18.怎樣去選擇一個下拉框中的value=xx的option?

使用select類,具體可以加群了解

19.如何在定位元素后高亮元素(以調(diào)試為目的)?

使用javascript將元素的border或者背景改成黃色就可以了。

20.什么是斷言?

可以簡單理解為檢查點,就是預(yù)期和實際的比較

如果預(yù)期等于實際,斷言通過,測試報告上記錄pass

如果預(yù)期不等于實際,斷言失敗,測試報告上記錄fail

21.如果你進(jìn)行自動化測試方案的選型,你會選擇哪種語言,java,js,python還是ruby?

哪個熟悉用哪個

如果都不會,團(tuán)隊用哪種語言就用那種

22.page object設(shè)置模式中,是否需要在page里定位的方法中加上斷言?

一般不要,除非是要判斷頁面是否正確加載。

Generally don't make assertions

23.page object設(shè)計模式中,如何實現(xiàn)頁面的跳轉(zhuǎn)?

返回另一個頁面的實例可以代表頁面跳轉(zhuǎn)。

```

// The login page allows the user to submit the login form public HomePage submitLogin() { // This is the only place that submits the login form and expects the destination to be the home page. // A seperate method should be created for the instance of clicking login whilst expecting a login failure. driver.findElement(loginButtonLocator).submit(); // Return a new page object representing the destination. Should the login page ever // go somewhere else (for example, a legal disclaimer) then changing the method signature // for this method will mean that all tests that rely on this behaviour won't compile. return new HomePage(driver); }

```

24.自動化測試用例從哪里來?

手工用例的子集,盡量

簡單而且需要反復(fù)回歸

穩(wěn)定,也就是不要經(jīng)常變來變?nèi)?/p>

核心,優(yōu)先覆蓋核心功能

25.你覺得自動化測試最大的缺陷是什么?

實現(xiàn)成本高

運行速度較慢

需要一定的代碼能力才能及時維護(hù)

26.什么是分層測試?

畫給他/她看。

27.webdriver可以用來做接口測試嗎?

不用糾結(jié),不可以。

28.selenium 是否可以調(diào)用js來對dom對象進(jìn)行操作?

Could selenium call js for implementation dom object directly?

29.selenium 是否可以向頁面發(fā)送鼠標(biāo)滾輪操作?

Could selenium send the action of mouse scroll wheel?

不能

30selenium 是否可以模擬拖拽操作?

Does selenium support drag and drop action?

可以

31.selenium 對下拉列表的中的選項進(jìn)行選擇操作時,需要被操作對象的標(biāo)簽是什么?

When Selenium selects the option in selenium, What tag the DOM object should be?

select

32.selenium 上傳文件操作,需要被操作對象的type屬性是什么?

When Selenium upload a file, what value of type of the DOM object should be?

file


以上是“selenium面試題有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI