我在硒化物中编写了自动化测试代码,但奇怪的时间出现了。
浏览器窗口无法与 http://localhost:2757/devtools/browser/uuid 建立 websocket 连接
> [ERROR] Tests run: 97, Failures: 1, Errors: 0, Skipped: 96, Time
> elapsed: 3.945 s <<< FAILURE! - in
> com.rev.testManager.GenericTestManager [ERROR]
> com.rev.testManager.GenericTestManager.openPage Time elapsed: 3.727 s
> <<< FAILURE!
> org.openqa.selenium.remote.http.ConnectionFailedException: Unable to
> establish websocket connection to
> http://localhost:2757/devtools/browser/d5f72b05-f030-41ee-88b2-5823e7d0f35c
> Build info: version: '4.4.0', revision: 'e5c75ed026a' System info:
> host: 'localhost', ip: '127.0.0.1', os.name: 'Linux', os.arch:
> 'amd64', os.version: '5.14.0-283.el9.x86_64', java.version: '18.0.2'
> Driver info: driver.version: SelenideDriver selenide.url:
> https://www.buletintv3.my/ …Run Code Online (Sandbox Code Playgroud) 我在Firefox 46版本中运行Selenide测试时遇到问题.当测试单独运行时,一切正常.但是当我在课堂上运行所有测试方法时,它会挂起以下步骤:
addons.productaddons INFO sending request to: https://aus5.mozilla.org/update/3/GMP/46.0/20160421124000/WINNT_x86_64-msvc-x64/en-US/release/Windows_NT%206.1.1.0%20(x64)/default/default/update.xml
addons.productaddons INFO Completed downloading document
addons.productaddons INFO Downloading from https://cdmdownload.adobe.com/firefox/win/x64/primetime_gmp_win_x64_gmc_40673.zip to C:\Users\hunar_letsko\AppData\Local\Temp\tmpaddon
addons.productaddons INFO Downloading from http://ciscobinary.openh264.org/openh264-win64-0410d336bb748149a4f560eb6108090f078254b1.zip to C:\Users\hunar_letsko\AppData\Local\Temp\tmpaddon
addons.manager INFO Skipping background update check
DeferredSave.extensions.json DEBUG Save changes
DeferredSave.extensions.json DEBUG Starting timer
DeferredSave.extensions.json DEBUG Starting write
DeferredSave.extensions.json DEBUG Write succeeded
Run Code Online (Sandbox Code Playgroud)
还有一点需要注意:当测试方法运行超过3小时时,连接超时会失败:
org.openqa.selenium.WebDriverException: java.net.SocketTimeoutException: Read timed out
Build info: version: '3.0.0', revision: '350cf60', time: '2016-10-13 10:48:57 -0700'
System info: host: 'EPBYMINW2815', ip: '10.6.9.56', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_92' …Run Code Online (Sandbox Code Playgroud) 以前我使用 Maven+Selenide+JUnit4 进行我的测试,它很好,并行运行效果很好。例子:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin}</version>
<configuration>
<parallel>all</parallel>
<perCoreThreadCount>true</perCoreThreadCount>
<threadCount>4</threadCount>
<perCoreThreadCount>false</perCoreThreadCount>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
在 Jenkins 的工作中,我能够运行测试(下面的示例)
mvn -Dtest=TestClassName test
Run Code Online (Sandbox Code Playgroud)
我的测试在 4 个浏览器中运行。
在我切换到JUnit5之前,因为我想使用标签运行测试,例如
@Test
@Tag("smoke")
public void test1() {}
Run Code Online (Sandbox Code Playgroud)
并通过下一个命令运行所有标记为“smoke”的测试:
mvn -Dtag=smoke test
Run Code Online (Sandbox Code Playgroud)
但是我遇到了下一个问题:并行执行不起作用,我仍然没有找到解决方案。我发现了这个错误https://github.com/junit-team/junit5/issues/1424
如何与 JUnit5 并行运行测试?
我曾尝试在pom.xml 中使用
<forkCount>2</forkCount>
<reuseForks>true</reuseForks>
<parallel>all</parallel>
Run Code Online (Sandbox Code Playgroud)
它没有帮助,我创建了一个文件junit-platform.properties并在那里插入
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.config.strategy = fixed
Run Code Online (Sandbox Code Playgroud)
但无论如何我无法解决这个问题。
I\xe2\x80\x99m 试图捕获 NoSuchElementException。这是我的代码:
\n\npublic void checkActiveApps() {\n try {\n $(BUTTON).click();\n } catch (org.openqa.selenium.NoSuchElementException e) {\n System.out.println(e);\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n但仍然抛出异常。怎样才能抓住它呢?
\n\n这是日志:
\n\nElement not found {button[role='checkbox']}\nExpected: visible\nScreenshot: file:/Users/user/source/project/build/reports/tests/1537866631954.0.png\nPage source: file:/Users/user/source/project/build/reports/tests/1537866631954.0.html\nTimeout: 4 s.\nCaused by: NoSuchElementException: Unable to locate element: button[role='checkbox']\n at com.codeborne.selenide.impl.WebElementSource.createElementNotFoundError(WebElementSource.java:31)\n at com.codeborne.selenide.impl.ElementFinder.createElementNotFoundError(ElementFinder.java:82)\n at com.codeborne.selenide.impl.WebElementSource.checkCondition(WebElementSource.java:59)\n at com.codeborne.selenide.impl.WebElementSource.findAndAssertElementIsVisible(WebElementSource.java:72)\n at com.codeborne.selenide.commands.Click.execute(Click.java:16)\n at com.codeborne.selenide.commands.Click.execute(Click.java:12)\n at com.codeborne.selenide.commands.Commands.execute(Commands.java:144)\n at com.codeborne.selenide.impl.SelenideElementProxy.dispatchAndRetry(SelenideElementProxy.java:90)\n at com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java:65)\nRun Code Online (Sandbox Code Playgroud)\n\n我使用selenide版本4.12.3
\n我Error: no display specified在FreeBSD服务器的Jenkins中运行play框架测试时遇到错误.所以每次我都面临超时
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox
詹金斯有:
1)安装Xvfb插件
2)安装了Play Framework
使用硒化物库和硒化物模块为游戏框架编写测试.
在作业配置中配置并启用Xvfb.
作业控制台输出是:
Checking out Revision 3f485bd2e3dbcfa058fc19f89ab18020e36707d8 (origin/trunk)
...
Xvfb starting$ /usr/local/bin//Xvfb :1 -screen 0 -fbdir /usr/local/jenkins/xvfb-9-786185694297443042.fbdir
...
Command detected: clean
Command detected: deps --sync
Command detected: precompile
Command detected: auto-test
[YalsTests] $ /srv/java/play/play clean
...
~ using java version "1.8.0_72"
[YalsTests] $ /srv/java/play/play auto-test
~ 14 tests to run:
~
~ selenium/front/CorrectInput... org.openqa.selenium.firefox.NotConnectedException: Unable to …Run Code Online (Sandbox Code Playgroud) 我想检查使用 Selenide download() 方法下载文件,但捕获 FileNotFoundException 和错误“拦截 1 个响应”,尽管文件已下载。
我有按钮,点击它会下载一个 zip 文件。元素没有 href 属性。
我使用 Selenide 5.0.0,chromdriver.exe 2.43
我有以下设置
Configuration.proxyEnabled = true;
Configuration.fileDownload = FileDownloadMode.PROXY;
Run Code Online (Sandbox Code Playgroud)
以下代码调用错误
public static SelenideElement actionButton() {return $(By.xpath("//div[@class='task-list_container_scroll-view']/div[1]/div[@class='ng-star-inserted'][1]//common-task-view//span[@role='button']"));}
File file = actionButton().download(10000);
Run Code Online (Sandbox Code Playgroud)
java.io.FileNotFoundException: 无法下载文件 {By.xpath: //div[@class='task-list_container_scroll-view']/div[1]/div[@class='ng-star-inserted'][ 1]//common-task-view//span[@role='button']} 在 10000 毫秒内。拦截了 1 个响应。200"" {Server=nginx/1.13.12, Cache-Control=private, Access-Control-Allow-Origin=*, Access-Control-Allow-Methods=POST, GET, OPTIONS, DELETE, PUT, Connection=keep-活着,到期=星期四,1970 年 1 月 1 日 00:00:00 GMT,Access-Control-Max-Age=3600,X-Application-Context="frontend":staging:80,Content-Length=1271853,Date=Wed, 2018 年 10 月 31 日 12:41:32 GMT,Access-Control-Allow-Headers=Content-Type,x-requested-with,X-Custom-Header,accept,authorization} application/octet-stream(1202830 字节)在 com。 codeborne.selenide.impl.DownloadFileWithProxyServer。
操作系统:窗口 10
浏览器:Chrome webDriver
浏览器版本:Chrome 63.0.3239.10(64bit)
- 硒版本 2.44
添加以下依赖项:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.44.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
预期行为 -
我想检查驱动程序是否被用户直接关闭,如果没有浏览器,则重新启动webdriver。
在Driver webdriver = new ChromeDriver()代码之前,webdriver 为空状态,
但是Driver webdriver = new ChromeDriver()代码完成后,即使用户关闭浏览器,webdriver 也不会被破坏。
因此,在用户关闭浏览器后,所有与 webdriver 相关的代码都会出现错误:“无法访问的异常”。
如果浏览器被用户关闭,我想重新启动 webdriver,但我无法检测到这种情况。
driver!=null 代码不起作用,因为用户关闭浏览器后驱动程序仍然存在 if((driver.getWindowHandle().equals("")) 无法正常工作,因为 Chrome 无法访问异常,因为浏览器已被用户关闭我想要做的是检查浏览器是否因为用户而消失了?
如何使用shouldHave断言检查 Selenide 中的页面标题?
在“Selenium”中,它将是下一个代码:
Assert.assertEquals(title(), "Your page title");
Run Code Online (Sandbox Code Playgroud) 我在 Maven 项目中使用 Java。当我尝试在测试中使用 Selenide 函数时,出现此错误:
Error:(39, 26) java: cannot access org.openqa.selenium.WrapsDriver
class file for org.openqa.selenium.WrapsDriver not found
同时,我的测试在没有 Selenide 代码的情况下运行良好。
这是我的 POM xml:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.13.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud) 我试图在网站上找到一个元素并获取所有元素。为此,我使用硒化物/硒。我正在寻找的元素无法由一个类定位,因此我尝试定位具有两个类(父类和子类)的元素。仅使用 Selenide,我就可以使用以下方法轻松定位元素:
SelenideElement basketIcon = $(By.className("buttons")).$(byClassName("btn-cart"))
这肯定会给我一个元素。但是我怎样才能找到一个元素数组呢?
List<SelenideElement> productName1 = WebDriverRunner.getWebDriver().findElements(By.className(""));但它不起作用,我也尝试过:List<WebElement> productName = WebDriverRunner.getWebDriver().findElements(By.className("buttons"));但是这里如何添加另一个类来定位元素?$(byClassName("btn-cart"))?或者还有其他方法可以做到这一点吗?
我也尝试过使用ElementsCollection elements = WebDriverRunner.getWebDriver().findElements(By.className(""));但它不起作用......
编辑: 我有一个名为“DriverFactory”的类,用于打开浏览器:
public static void openBrowser(String browserName, String url) throws Exception {
WebDriverManager.chromedriver().browserVersion(chromeversion).setup();
Configuration.browser = "Chrome";
Configuration.startMaximized = true;
driver.get(url);
}
Run Code Online (Sandbox Code Playgroud)
另一个类,我在其中定义定位器:
public class EE_MonitorCategoryElements extends DriverFactory {
protected static List<WebElement> productName = getWebDriver().findElements(By.id("asddsa"));
}
Run Code Online (Sandbox Code Playgroud)
和一个测试类:
@Test
public void ads() throws Exception {
DriverFactory.openBrowser("Chrome", "https://google.ge");
}
Run Code Online (Sandbox Code Playgroud)
当我使用“getWebDriver()”添加最后一个元素定位器并且我尝试运行测试时,它给了我一个错误:没有绑定测试,并且在我删除/注释 getWebDriver 行的地方,它正在工作