我有一个Selenium测试.DLL被加载使用NUnit.
我运行所需的硒Java服务器悄悄藏在一个进程中运行测试时.
不过,我目前启动服务器当测试开始和Kill()它的当测试停止.
这导致每个测试启动/停止 selenium服务器.
我想要的是Selenium Server进程:
Kill()编上DLL死亡或垃圾收集
我读到C#不支持捕获DLL初始化和调用代码.(我错了吗?)
我的想法是将Selenium服务器托管在单例类中,并在第一次测试运行时对其进行初始化.然后我将它留给垃圾收集器通过解构器调用Dispose方法.我目前有以下代码来托管selenium服务器:
namespace Tests.Server
{
using System;
using System.Diagnostics;
using System.IO;
using System.Security;
using System.Windows.Forms;
using Microsoft.Win32;
/// <summary>
/// A singleton class to host and control the selenium server.
/// </summary>
public class SeleniumServer : IDisposable
{
#region Fields
/// <summary>
/// …Run Code Online (Sandbox Code Playgroud) 我知道Selenium有一个内置方法getTable("tableName.row.column")可以方便地返回一个单元格.但是,如何返回整列?
我直接尝试了getText(),但只返回了第一个单元格,
getText("//tbody[@id='recordsTable']/tr[contains(@class, 'someclass')]")
Run Code Online (Sandbox Code Playgroud)
但是具有相同Xpath表达式的getXpathCount()显示有多个元素匹配.
getXpathCount("//tbody[@id='recordsTable']/tr[contains(@class, 'someclass')]") // result is 15
Run Code Online (Sandbox Code Playgroud)
请多多帮助,非常感谢!
我正在尝试使用Selenium RC(在Python中)获取页面中的第一个href属性:
sel.get_text("xpath=//@href")
Run Code Online (Sandbox Code Playgroud)
这会返回一个空字符串.
但是,Firefox内同一页面上的相同xpath(使用"View XPath"扩展名)会产生正确的值.
我试过摆弄它,但其他属性也是如此(例如@class) - 硒有什么问题吗?或者我忽略了一些微不足道的事情吗?
我有一套Selenium测试,我在Selenium IDE中创建并移植到Java.在几个测试中,我使用verifyTextPresent命令的Java等价物来确认页面上的一些文本(verifyTrue(selenium.isTextPresent())).
从IDE运行测试时,我在页面上的文本中发现了拼写错误,但是在通过Selenium RC/TestNG运行测试时未捕获到错误.这是我的代码示例和导致问题的文本(拼写错误以粗体显示):
文本:
请更正下面指出的错误.
您需要添加一个至少一个约束.
IDE:
verifyTextPresent | Please correct the errors indicated below.
verifyTextPresent | You need to add at least one restriction.
Run Code Online (Sandbox Code Playgroud)
Java的:
verifyTrue(selenium.isTextPresent("Please correct the errors indicated below."));
verifyTrue(selenium.isTextPresent("You need to add at least one restriction."));
Run Code Online (Sandbox Code Playgroud)
由于测试的两个版本都有正确的文本,为什么Selenium RC版本没有捕获错误?有没有其他人有这个问题?
我想用Selenium IDE在IFrame中输入内容,但我不知道如何做到这一点.
非常感谢!
<table id="ext-comp-1389" class="x-btn x-btn-text-icon " cellspacing="0" style="width: auto;">
<tbody class="x-btn-small x-btn-icon-small-left">
<tr>
<tr>
<td class="x-btn-ml">
<td class="x-btn-mc">
<em class="x-btn-split" unselectable="on">
<button id="ext-gen128" class="x-btn-text create" type="button">New</button>
</em>
</td>
<td class="x-btn-mr">
<i> </i>
</td>
</tr>
<tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
以上是HTML元素的嵌入方式..!HTML元素是一个"新"按钮,旁边有一个"+"符号...如果,我只点击'+',我可以得到菜单选项,类似于'D','P ','T'和'U'.如果我单击"新建"按钮(在代码中,正是这部分, 新建 ,没有任何内容显示为点击操作,发生在中心...下面是按钮的图像...
这是代码,我试过......在过去的几个小时里,
package com.hr.testpack;
import static org.junit.Assert.fail;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import com.thoughtworks.selenium.*;
public class Classtest2 {
static Selenium selenium;
static final …Run Code Online (Sandbox Code Playgroud) 我是硒的新手,运行硒RC时遇到了问题.
实际上,我已经记录了一个脚本selenium IDE并将其保存为,test.html并且我能够通过脚本运行脚本,selenium IDE但是当我尝试通过selenium RC它运行脚本时,它会卡在某个位置并在控制台"检查资源别名"中显示以下消息
通过命令提示符运行脚本的命令:
java -jar selenium-server.jar -htmlSuite "*firefox" "www.google.com" "test.html" -port 4445
让我知道发生这种情况的确切原因?
附上图片了解更多详情请关注::![我想在文字区域输入文字:照片中提到] [1] [1]:http://i.stack.imgur.com/sai92.png我想要将文本输入文本区域,但是发现找不到元素的错误.我试过X路径,名称和ID,但无法执行此代码,并希望与页面上出现的其他元素一起玩,但测试目的却没有!我不知道它可以用java-executor或switch窗口处理(弹出).下面提到的是java代码.如何处理这种情况请帮助详细说明.
Java代码:
@Test
public void CreteLead() throws InterruptedException
{
WebElement _loginName =
driver.findElement(By.xpath(OR.getProperty("username")));
_loginName.sendKeys(OR.getProperty("loginId"));
WebElement _password =
driver.findElement(By.xpath(OR.getProperty("password")));
_password.sendKeys(OR.getProperty("loginPassword"));
WebElement _login =
driver.findElement(By.xpath(OR.getProperty("login")));
_login.click();
Thread.sleep(5000);
WebElement _New =
driver.findElement(By.xpath(OR.getProperty("New")));
_New.click();
Thread.sleep(10000);
driver.findElement(By.id("btnCreateCustomer")).click();
Run Code Online (Sandbox Code Playgroud)
HTML代码:
<table class="tbl_top_align" width="100%" cellspacing="3" cellpadding="0">
<tbody>
<tr>
<tr>
<tr>
<tr id="trBranch">
<tr id="trAssign">
<td> Assign To*: </td>
<td>
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="font-weight: normal !important;">
<div
id="ctl00_CPHPageContents_ctl00_CPHPageContents_ddlAssignedToPanel"
class="RadAjaxPanel" style="display: block;"
>
<span id="RequiredFieldValidator1"
class="error_message" style="display:none;"
>* missing</span>
</td>
<td …Run Code Online (Sandbox Code Playgroud) 我正在开发selenium自动化的框架,我一直坚持使用下拉列表来获取下拉选项的值.我有下拉选项,但现在我想要相同下拉列表的值.是否有可能在硒中获得它.
例如:
这是Html标签:
<select id="periodId" name="period" style="display: none;">
<option value="week1">1</option>
<option value="week2">2</option>
<option value="week3">3</option>
<option value="week4">4</option>
<option value="week5">5</option>
<option value="week16">6</option>
</select>
Run Code Online (Sandbox Code Playgroud)
现在在我开发的框架中,我将传递下拉选项'5',现在我想要下拉选项'5'的值.使用硒可以获得下拉选项'5'的'week5'值吗?
我是jUnit和Selenium的新手.目前,我们正在我们的项目中进行POC评估工具的适用性.
我们的一个关键要求是在断言失败的情况下使用友好消息并验证失败.目标是通过手动测试人员对这些用户进行直观分析.
我正在尝试使用SLF4J来记录用户友好消息的INFO消息.
我面临的挑战是 - 当断言失败时,如何传递自定义消息而不是jUnit默认消息?
例如,我想摆脱以下默认断言失败消息
预期"健康AZ"匹配glob"Health A-ZZ"(已将glob变为regexp"Health A-ZZ")
并将其框定为
菜单项的标题与预期值"Health A-ZZ"不匹配.看到的实际价值是"健康AZ"
问题1 - 有没有办法用我想要的方式覆盖默认消息?问题2 - 我可以将变量参数传递给消息并使其成为动态消息吗?
示例代码:
try {
assertEquals("Health A-ZZ", selenium.getText("//div[@id='topnav']/ul/li[2]/a"));
logger.info("SUCCESS: Menu Item {} title verification Passed. EXPECTED : A-Z and Actual: {}",mainCounter, selenium.getText("//div[@id='topnav']/ul/li[2]/a"));
}
catch (AssertionError e) {
logger.error("FAILURE: Menu Item {} title verification Failed. EXPECTED : A-ZZ and Actual: {}",mainCounter, selenium.getText("//div[@id='topnav']/ul/li[2]/a"));
}
Run Code Online (Sandbox Code Playgroud)
我得到两次打印的assertFailure消息..一个在上面的catch块中有错误消息,另一个是默认的junit assertfailre消息,就像我上面提到的那个我想要摆脱的消息.
提前致谢.
此致,普拉卡什