macOS 10.14.3
铬72.0.3626.96
铬驱动器2.46
在尝试执行以下代码时,我收到一个错误:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.util.concurrent.TimeUnit;
public class RobotTest {
public WebDriver driver;
public WebDriverWait wait;
private static String filePath = System.getProperty("user.dir") + "\\images\\sw-test-academy.png";
@BeforeMethod
public void setup () {
driver = new ChromeDriver();
driver.navigate().to("https://blueimp.github.io/jQuery-File-Upload/");
driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
wait = new WebDriverWait(driver,10);
driver.manage().window().maximize();
}
@Test
public void robotTest () throws InterruptedException {
//Click Image Upload
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".btn.btn-success.fileinput-button")));
driver.findElement(By.cssSelector(".btn.btn-success.fileinput-button")).click();
uploadFileWithRobot(filePath);
Assert.assertTrue(wait.until(ExpectedConditions.visibilityOfElementLocated
(By.cssSelector(".name"))).getText().equals("sw-test-academy.png"));
//I added sleep to see the result with my eyes. If you want you can remove below line.
Thread.sleep(2000);
}
@AfterMethod
public void teardown () {
driver.quit();
}
//File upload by Robot Class
public void uploadFileWithRobot (String imagePath) {
StringSelection stringSelection = new StringSelection(imagePath);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
Robot robot = null;
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
robot.delay(250);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.delay(150);
robot.keyRelease(KeyEvent.VK_ENTER);
}
}2019-02-12 :08:49.264 java21517:2034626 pid(21517)/euid(502)在非主线程环境中调用TIS/TSM,错误:这是不允许的。请在主线程调用TIS/TSM!
发布于 2019-05-13 15:15:07
这似乎是Mac的chrome驱动程序实现的一个问题。围绕High (10.13.0),苹果似乎为他们的文本服务管理器(TSM)引入了更高的日志记录。
从围绕同一问题(其他库)的讨论来看,我不认为它会有任何功能问题(但非常烦人)。https://github.com/processing/processing/issues/5462
这里的另一个开发人员已经详细介绍了如何在自己的代码中调试这个问题。https://indiestack.com/2018/08/let-it-rip/
尽管出现了错误,我的测试仍在运行。我认为我们所能做的就是等待ChromeDriver对导致错误记录的任何代码使用主线程。
https://sqa.stackexchange.com/questions/37745
复制相似问题