Scalatest PlusPlay Selenium 无法调整窗口大小 [英] Scalatest PlusPlay Selenium not able to resize a window
问题描述
我已经研究了一段时间,我似乎找不到使用 scalatest plus 调整窗口大小的方法.
Been digging at this for a while, and I can't seem to find a way to resize a window using scalatest plus.
我在网上找到的唯一方法或http://doc.scalatest.org/2.1.5/index.html#org.scalatest.selenium.WebBrowser
The only method I've found searching online or the documentation at http://doc.scalatest.org/2.1.5/index.html#org.scalatest.selenium.WebBrowser
是executeScript("window.resizeTo(700,700);")
is executeScript("window.resizeTo(700,700);")
但这对我没有反应(没有错误,没有什么).有没有一种方法可以涵盖我缺少的这一点?我的代码的简短示例:
but that has been unresponsive to me (no errors, no nothing). Is there a method that covers this that I am missing? A brief sample of my code:
import java.util.concurrent.TimeUnit
import org.scalatestplus.play._
import org.openqa.selenium._
import com.sun.xml.internal.bind.v2.TODO
import scala.collection.JavaConverters._
import controllers.Application
import models.{Item, ItemPriorityBucket}
import play.api.test._
import org.scalatest.time._
class WebSpec extends PlaySpec with OneServerPerSuite with AllBrowsersPerTest {
implicit override val patienceConfig =
PatienceConfig(timeout = scaled(Span(5, Seconds)), interval = scaled(Span(20, Millis)))
override lazy val browsers = Vector(
// FirefoxInfo(firefoxProfile),
ChromeInfo
// SafariInfo
)
implicit override lazy val app: FakeApplication =
FakeApplication(additionalConfiguration = TestUtil.inMemoryDatabase("default", Map()))
val base: String = "http://localhost:" + port
def sharedTests(browser: BrowserInfo) = {
"Home page" should {
"render an item" + browser.name in {
executeScript("window.resizeTo(700,700);")
Item.deleteAll()
delete all cookies
val itemId = TestUtil.createRandomItem(Some(ItemPriorityBucket.Low), Some(Application.ENGLISH))
val item = Item.find(itemId).get
go to (base + "/")
eventually { assert(cssSelector(Selectors.all_items).webElement.isDisplayed) }
}
}
}
我的一个测试会根据窗口大小看到不同的元素,所以这是我需要控制的东西,但我真的找不到在 Scala 中执行此操作的任何帮助.
One of my tests will see different elements based on the window size, so this is something I need to control, but I can't really find any help out there for doing this in Scala.
感谢您的帮助,
我还应该提到使用执行脚本运行的其他脚本按预期运行,而不是调整大小窗口脚本
I should also mention that other scripts run using execute script are functioning as expected, just not the resize window script
推荐答案
通过添加以下代码行,我能够解决此问题:
I was able to resolve this issue by adding the following line of code:
webDriver.manage.window.setSize(new org.openqa.selenium.Dimension(1000, 600))
这不是很直观,因为我们必须显式访问隐式网络驱动程序,但它可以工作.
it's not very intuitive, since we have to explicitly access the implicit webdriver, but it works.
这篇关于Scalatest PlusPlay Selenium 无法调整窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!