我正在阅读SeleniumHQ文档并遇到以下声明.
"警告:不要混合隐式和显式等待.这样做可能会导致不可预测的等待时间.例如,设置10秒的隐式等待和15秒的显式等待可能会导致20秒后发生超时."
出于某种原因,我无法理解这一点.总超时20秒是我的主要困惑点.任何人都可以解释我是否遗漏了什么?
编辑
我的问题不是关于混合这些等待的实施/后果.它完全是关于doc上的语句和超时计算.
第二次编辑
根据下面的测试,看起来文档是正确的.我仍然需要解释.
using System;
using System.Diagnostics;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace Test
{
[TestFixture]
public class Test
{
private IWebDriver _webDriver;
[Test]
public void ExplicitVsImplicitWaitTest()
{
_webDriver = new ChromeDriver();
_webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
_webDriver.Navigate().GoToUrl("https://www.google.com/");
_webDriver.Manage().Window.Maximize();
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
try
{
//new WebDriverWait(_webDriver, TimeSpan.FromSeconds(15)).Until(
//ExpectedConditions.ElementExists(By.CssSelector("Should Fail")));
_webDriver.FindElement(By.CssSelector("Should Fail"));
}
catch ( NoSuchElementException exception)
//catch ( OpenQA.Selenium.WebDriverTimeoutException)
{
stopwatch.Stop();
Console.WriteLine(stopwatch.Elapsed);
}
_webDriver.Quit();
}
}
}
Run Code Online (Sandbox Code Playgroud)
时间秒:00:00:10.0167290
using System; …
Run Code Online (Sandbox Code Playgroud) 在我正在测试的页面中,可能会显示两个按钮:BASIC或ADVANCED.
我希望能够判断ADVANCED按钮是否显示 - 如果是,请单击它.
如果显示BASIC按钮,我想什么都不做,继续我的测试.
我试验过的所有Nightwatchjs选项都会生成失败消息.例如,如果我"waitforpresent"或"waitforvisible"并且该按钮不存在,则会生成错误/失败.我只是想知道哪个按钮存在,所以我可以在我的代码中做出决定.
这是我尝试过的:
try {
browser.isVisible('#advanced-search', function(result) {console.log(result.state); })
} catch (myError)
{
console.log(myError);
}
Run Code Online (Sandbox Code Playgroud)
思考?
我有一个HTML href
链接
<a href="/docs/configuration">App Configuration</a>
Run Code Online (Sandbox Code Playgroud)
使用Selenium我需要点击链接.目前,我使用下面的代码 -
Driver.findElement(By.xpath("//a[text()='App Configuration']")).click();
Run Code Online (Sandbox Code Playgroud)
但它没有重定向到页面.我也试过下面的代码 -
Driver.findElement(By.xpath(//a[@href ='/docs/configuration']")).click();
Run Code Online (Sandbox Code Playgroud)
但这是抛出异常 -
org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与命令持续时间或超时交互:13毫秒
链接可见,页面已完全加载.我不知道我的代码有什么问题.
我最近几天一直在寻找答案而无法找到答案.我能找到的最接近的答案是,这并不完全回答我的问题.
顺便说一下,我有一个基于Gradle的Selenium测试项目.我们在Jenkins上构建项目,在20个并发线程中运行测试.我拥有的唯一测试类总数是87.所以,我希望gradle能够执行至少5个批次测试项目是使用Cucumber JVM构建的,构建并触发Jenkins对Selenium Hub的测试.我试图通过尽可能多地利用网格来增加测试的并行性.但是,当测试数量开始增长时,问题就开始了.
当我从Jenkins开始测试时,我在第一次观察时观察到测试执行了所有20个测试过程,我看到第二批也开始使用相同数量的过程.在第二批之后,流程回到单一模式,整个工作需要14个小时才能完成,这违背了并行测试执行的目的.
Gradle属性:
jvmArgs '-Xms128m', '-Xmx1024m', '-XX:MaxPermSize=128m'
Runtime.runtime.availableProcessors().toString()) as int
maxParallelForks = PropertyUtils.getProperty('test.parallel', '15') as int
forkEvery = PropertyUtils.getProperty('test.forkEvery', '0') as int
Run Code Online (Sandbox Code Playgroud)
CLI:
gradle clean test -Dtest.single=*TestRun --info
Run Code Online (Sandbox Code Playgroud)
我已经阅读了所有可能找到但未能得到答案的文件.如果有人可以帮我解决这些问题,将不胜感激
1. Gradle如何在内部批量测试运行器?例如,如果20个执行程序启动并且测试1,2,3完成执行速度比其他执行程序快,那么三个执行程序是否会获得另外三个测试类或等待整个批处理完成执行?
2. forkEvery可以影响并行测试期间执行的工作方式吗?
詹金斯登录
成功启动了"Gradle Test Executor 6"流程
成功启动了"Gradle Test Executor 13"流程
成功启动了"Gradle Test Executor 14"流程
成功启动了"Gradle Test Executor 5"流程
成功启动了"Gradle Test Executor 16"流程
成功启动了"Gradle Test Executor 8"流程
成功启动了"Gradle Test Executor 19"流程
成功启动了"Gradle Test Executor 4"流程
成功启动了"Gradle Test Executor 2"流程
成功启动了"Gradle Test Executor 11"流程
成功启动了"Gradle …
我们在我们的网站上添加了一个异步的javascript调用.我正试图让Selenium Webdriver等待来电的响应.
听众看起来像这样:
$(document).on("application:subapp:rendered", function(){console.log("foo");});
Run Code Online (Sandbox Code Playgroud)
我的webdriver代码(python):
driver.set_script_timeout(30)
response = driver.execute_async_script("$(document).on(\"application:subapp:rendered\", function(){return \"foo\";});"
Run Code Online (Sandbox Code Playgroud)
接下来我执行页面应该让"foo"返回
不过这是我的回答......
TimeoutException:消息:异步脚本超时:结果未在30秒内接收(会话信息:chrome = 41.0.2272.118)(驱动程序信息:chromedriver = 2.11.298604(75ea2fdb5c87f133a8e1b8da16f6091fb7d532 1e),platform = Windows NT 6.1 SP1 x86_64)
我正在使用 Selenium 和 Java 在 android 上运行脚本(通过 Appium 服务器)。我看到使用 selenium 来定位吐司是不可能的
driver.findElement(By.LinkText("User not logged in")
Run Code Online (Sandbox Code Playgroud)
在 Appium
但是可以在 Selendroid 中用于捕获 toast 消息。
有没有办法在同一个脚本中同时使用 Selendroid 和 Appium?
我正在尝试使用PHP webdriver和PhantomJS更改输入的值.当我运行一个简单的
$driver->executeScript("document.getElementById('changeme').value='".$newvalue."' ;", array());
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
拒绝将字符串评估为JavaScript,因为unsafe-eval不是以下内容安全策略指令中允许的脚本源
我已经设置了以下命令行选项
--ignore-ssl-errors=true --web-security=false --ssl-protocol=any
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我正在使用Selenium webdriver
但它不会退出chrome
并且chrome
正确驱动。一些过程沉闷的赛跑者。
退出 chrome 的代码:
driver.quit();
Run Code Online (Sandbox Code Playgroud)
启动 chrome 的代码:
System.setProperty("webdriver.chrome.driver","/<path to chrome driver>/chromedriver");
ChromeOptions options = new ChromeOptions();
options.setBinary(new File("/<path to chrome >/google-chrome"));
driver = new ChromeDriver(options);
Run Code Online (Sandbox Code Playgroud)
Chrome 驱动程序版本:2.9.248304 Chromium 版本:40.0.2214.115 Selenium 版本:2.32 操作系统:Linux java.version:1.7.0_71
提前致谢,奈拉
我看到其他几个线程处理类似的问题,但不一样。我正在使用直接连接到浏览器,ChromeDriver
有时无法启动并显示以下错误。看起来我可以在配置文件中设置一些浏览器超时,只是无法弄清楚。的conf.js
模样
'use strict';
exports.config = {
/* seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
** enables to connect to the browsers directly.
** http://stackoverflow.com/questions/27889488/cannot-run-protractor-on-internet-explorer-11
*/
directConnect: true,
specs: ['giftengHomePageTests.js'],
multiCapabilities: [{
'browserName': 'chrome'
}, {
'browserName': 'firefox'
},
/**
* {
* 'browserName': 'internet explorer'
* }
* */
],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose: true
},
onPrepare: function () {
browser.driver.manage().window().maximize();
}
}
Run Code Online (Sandbox Code Playgroud)
[chrome#1]直接使用ChromeDriver ...
[chrome#1]错误-无法启动WebDriver会话。
[chrome#1]错误:收听EACCES
错误更新
我已经多次运行这些相同的测试,但是现在在Firefox驱动程序上失败了。很不规律
“ D:\ Program Files(x86)\ JetBrains \ WebStorm 9.0.3 \ …
我正在尝试为UI测试自动化执行以下操作:
[SetUp]
public void TestSetUp()
{
_scope = new TransactionScope();
}
[TearDown]
public void TearDown()
{
_scope.Dispose();
}
[Test]
public void SomeTest()
{
Utilities.SomeDeleteTransaction(companyCode);
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试执行一个Update查询并在[Test]中执行一些操作,并在测试后运行的[TearDown]中执行UI和回滚事务.我不确定我做得对.但是,我正在尝试(可能提交)该事务,以便我可以看到它对UI的影响和回滚相同的事务,所以我的数据库保持不变.我可以使用TransactionScope或其他类来实现吗?
编辑
这个问题主要是处理数据库已知的硒测试状态.由于我的数据库每月从生产中删除,我希望能够在测试之前执行一些insert/update/delete sql脚本来修改db,然后使用Selenium进行一些UI测试,然后在Teardown中回滚(测试是使用NUnit编写的) )确保db对测试没有任何影响,并在测试后保持相同.
selenium ×8
java ×3
webdriver ×3
angularjs ×1
appium ×1
asynchronous ×1
build.gradle ×1
c# ×1
ghostdriver ×1
gradle ×1
groovy ×1
javascript ×1
phantomjs ×1
php ×1
protractor ×1
python ×1
selendroid ×1
sql ×1
sql-server ×1
xpath ×1