selenium面试题总结——测试经验分享

selenium面试题总结——测试经验分享selenium上传文件操作,需要被操作对象的type属性是什么?

大家好,又见面了,我是你们的朋友全栈君。

今天有同学问到seleinum面试的时候会问到的问题,随便想了想,暂时纪录一下。欢迎大家在评论中提供更多问题。

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默认会去点这个元素的中心点,不占空间的元素算不出来中心点;

被点击的元素不能被其他元素遮挡;

被点击的元素不能在viewport之外,也就是说如果元素必须是可见的或者通过滚动条操作使得元素可见;

使用element.is_enabled()(python代码)判断元素是否是可以被点击的,如果返回false证明元素可能灰化了,这时候就不能点;

4.如何提高selenium脚本的执行速度?

使用效率更高的语言,比如java执行速度就快过python

不要盲目的加sleep,尽量使用显示等待

对于firefox,考虑使用测试专用的profile,因为每次启动浏览器的时候firefox会创建1个新的profile,对于这个新的profile,所有的静态资源都是从服务器直接下载,而不是从缓存里加载,这就导致网络不好的时候用例运行速度特别慢的问题

chrome浏览器和safari浏览器的执行速度看上去是最快的

可以考虑分布式执行或者使用selenium grid

5.用例在运行过程中经常会出现不稳定的情况,也就是说这次可以通过,下次就没办法通过了,如何去提升用例的稳定性?

测试专属profile,尽量让静态资源缓存

尽量使用显示等待

尽量使用测试专用环境,避免其他类型的测试同时进行,对数据造成干扰

6.你的自动化用例的执行策略是什么?

每日执行:比如每天晚上在主干执行一次

周期执行:每隔2小时在开发分之执行一次

动态执行:每次代码有提交就执行

7.什么是持续集成?

可以自行百度,学习能力自我提升很重要(1079636098)软件测试技术交流群推荐。

8.自动化测试的时候是不是需要连接数据库做数据校验?

一般不需要,因为这是单元测试层做的事情,在自动化测试层尽量不要为单元测试层没做的工作还债。

9.id,name,clas,x path, css selector这些属性,你最偏爱哪一种,为什么?

xpath和css最为灵活,所以其他的答案都不够完美。

10如何去定位页面上动态加载的元素?

显示等待

11.如何去定位属性动态变化的元素?

找出属性动态变化的规律,然后根据上下文生成动态属性。

12.点击链接以后,selenium是否会自动等待该页面加载完毕?

java binding在点击链接后会自动等待页面加载完毕。

13.webdriver client的原理是什么?

selenium的原理涉及到3个部分,分别是

浏览器

driver: 一般我们都会下载driver

client: 也就是我们写的代码

client其实并不知道浏览器是怎么工作的,但是driver知道,在selenium启动以后,driver其实充当了服务器的角色,跟client和浏览器通信,client根据webdriver协议发送请求给driver,driver解析请求,并在浏览器上执行相应的操作,并把执行结果返回给client。这就是selenium工作的大致原理。

14.webdriver的协议是什么?

client与driver之间的约定,无论client是使用java实现还是c#实现,只要通过这个约定,client就可以准确的告诉drier它要做什么以及怎么做。

webdriver协议本身是http协议,数据传输使用json。

这里有webdriver协议的所有endpoint,稍微看一眼就知道这些endpoints涵盖了selenium的所有功能。

15.启动浏览器的时候用到的是哪个webdriver协议?

New Session,如果创建成功,返回sessionId和capabilities。

16.什么是page object设计模式?

简单来说就是用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设计模式?

实际上是官方给出的java page object的工厂模式实现。

18.怎样去选择一个下拉框中的value=xx的option?

使用select类,具体可以加群了解

19.如何在定位元素后高亮元素(以调试为目的)?

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

20.什么是断言?

可以简单理解为检查点,就是预期和实际的比较

如果预期等于实际,断言通过,测试报告上记录pass

如果预期不等于实际,断言失败,测试报告上记录fail

21.如果你进行自动化测试方案的选型,你会选择哪种语言,java,js,python还是ruby?

哪个熟悉用哪个

如果都不会,团队用哪种语言就用那种

22.page object设置模式中,是否需要在page里定位的方法中加上断言?

一般不要,除非是要判断页面是否正确加载。

Generally don’t make assertions

23.page object设计模式中,如何实现页面的跳转?

返回另一个页面的实例可以代表页面跳转。


// 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.自动化测试用例从哪里来?

手工用例的子集,尽量

简单而且需要反复回归

稳定,也就是不要经常变来变去

核心,优先覆盖核心功能

25.你觉得自动化测试最大的缺陷是什么?

实现成本高

运行速度较慢

需要一定的代码能力才能及时维护

26.什么是分层测试?

画给他/她看。

27.webdriver可以用来做接口测试吗?

不用纠结,不可以。

28.selenium 是否可以调用js来对dom对象进行操作?

Could selenium call js for implementation dom object directly?

29.selenium 是否可以向页面发送鼠标滚轮操作?

Could selenium send the action of mouse scroll wheel?

不能

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

Does selenium support drag and drop action?

可以

31.selenium 对下拉列表的中的选项进行选择操作时,需要被操作对象的标签是什么?

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

最后:
欢迎关注公众号:程序员阿沐,领取一份216页pdf文档的Python自动化测试工程师核心知识点总结!

这些资料的内容都是面试时面试官必问的知识点,篇章包括了很多知识点,其中包括了有基础知识、Linux必备、Shell、互联网程序原理、Mysql数据库、抓包工具专题、接口测试工具、测试进阶-Python编程、Web自动化测试、APP自动化测试、接口自动化测试、测试高级持续集成、测试架构开发测试框架、性能测试、安全测试等。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/151452.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 久坐提醒电脑软件_久坐提醒app哪个好

    久坐提醒电脑软件_久坐提醒app哪个好下载废话不多说,先直接给出下载地址介绍久坐的危害不必多言,但工作起来很多时候总是不知不觉一坐几个小时不动地方。去年毕业前闲来无事写了个桌面端的久坐提醒小工具,放到github就没再管过,前些天发现这个仓库有了20个star了,虽然很少,但也蛮有成就感的。于是又有了更新的动力,根据issues里使用者提的建议,做了些小修改,提高了一些使用体验。截图展示…

    2022年10月1日
    4
  • 面试题的基本总结回顾(以以往面试过的问题做基本总结)[通俗易懂]

    Java基础问题整理:1.HashMap1.7与HashMap1.8的区别,从数据结构上、Hash值的计算上、链表数据的插入方法、内部Entry类的实现上分析?2.Hash1.7是基于数组和链表实现的,为什么不用双链表?HashMap1.8中引入红黑树的原因是?为什么要用红黑树而不是平衡二叉树?3.HashMap、HashTable、ConcurrentHashMap的原理与区别?…

    2022年4月6日
    45
  • 创建servlet的4个步骤_映射不能一对多还是多对一

    创建servlet的4个步骤_映射不能一对多还是多对一Servlet接口的实现类,路径配置映射,ServletConfig对象,ServletContext对象及web工程中文件的读取…

    2022年4月20日
    55
  • if python用法_for循环语句

    if python用法_for循环语句今天,我们将学习Python中if语句的基本使用。if在Python中用作某个条件或值的判断,格式为:if条件: 执行语句1else: 执行语句2else是当条件不成立时运行的代码。我们先来看个例子,程序判断天气情况并输出是否要带伞:weather=input(“今日天气是:”)ifweather==”雨天” print(“今天出门需要带伞”)else: print(“今天出门不需要带伞”)运行代码,输入雨天会提示要带伞。if语句中用的两个“=”是什么呢

    2022年9月26日
    4
  • python实现交叉验证_kfold显示不可迭代

    python实现交叉验证_kfold显示不可迭代KFold模块fromsklearn.model_selectionimportKFold为什么要使用交叉验证?交叉验证的介绍交叉验证是在机器学习建立模型和验证模型参数时常用的办法。交叉验证,顾名思义,就是重复的使用数据,把得到的样本数据进行切分,组合为不同的训练集和测试集,用训练集来训练模型,用测试集来评估模型预测的好坏。在此基础上可以得到多组不同的训练集和测试集,某次训练集中的某样本在…

    2022年9月20日
    3
  • TOR架构_中国有多少大数据中心

    TOR架构_中国有多少大数据中心1、前言最近在看《云数据中心网络技术》,学习了企业数据中心网络建设过程,看到有ToR和EoR两种布线方式,之前没有接触过,今天总结一下。2、布线方式ToR:(TopofRack)接入方式就是

    2022年8月6日
    5

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号