赛普拉斯:contains()。click()带有或语句
问题在于,从柏树中的Docker映像将浏览器语言设置为英语,并且页面上的某些元素被翻译成英语。看来这是柏树中的错误,因为Docker映像中的浏览器,无论设定语言如何,都将某些文本转换为英语。即使设置浏览器语言不同。
我本地的浏览器语言与Docker映像中的语言不同,因此某些文本对我而言与Dockerimage(英语)中的文本不同。现在,我必须建立解决方法,直到柏树设法修复该错误为止。
我希望柏树选择一个由逻辑或(||
)选择的元素。但是,它行不通,因为cypress.contains()
不支持此。 对于更好的说明,这里是我的意思的简单示例。您有一个想法如何实施吗?
const value1 = data.text_local_language
const value2 = data.text_english
cy.get("element")
.contains(value1 || value2)
.click();
the problem is that the Docker image from Cypress sets the browser language to english and some elements on the page are translated to english. It looks like it's a bug in Cypress because the browser in the Docker image, regardless of the set language, translates certain texts into English. even if the set browser language is different.
my local browser language is different than the one in the docker image so some texts are different for me locally than in the dockerimage (english). now i have to build a workaround until cypress manages to fix the bug.
i want cypress to select an element which is selected by a logical or ( ||
). However it doesn't work because cypress.contains()
doesn't support this.
For a better illustration here is a simple example of what I mean. Do you have an idea how to implement this?
const value1 = data.text_local_language
const value2 = data.text_english
cy.get("element")
.contains(value1 || value2)
.click();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
continains() /a>
正则表达式(在斜线内)
value1 | value2
匹配value1
或value2
(或或 is用管道符号|
表示。You can use a regular expression in
contains()
The regular expression (inside the slashes)
value1|value2
matches eithervalue1
orvalue2
(or is denoted by the pipe-symbol|
).有
oneof 如果确切的匹配是可以接受。
There is the
oneOf
assertion if an exact match is is acceptable.您可以查看文本包含
中的文本。
You can check the text contains either text inside a
.then()
command and assert it.要断言元素包含替代零件您可以在
contains()
中使用正则表达式(REGEXP)。surstert
包含
regexp,从变量中构建正则模式,使用constructor
使用字符串表达式使用新的Regexp
。另请参见文本内容:
配置浏览器语言,以您的容器化柏树
如果要配置用于测试的语言,则可以:
lang
环境变量在您的Docker容器中,浏览器可以将其选为System/System/default LocaleAccept-Language
请求标头中使用在柏树中设置浏览器语言
To assert that an element contains alternative parts you can use a regular expression (RegExp) inside
contains()
.Assert
Contains
RegExpTo build a regex pattern from variables use the constructor
new RegExp
with a string expression.See also the Cypress Assertions guide on Text Content:
Configure browser language in your containerized Cypress
If you want to configure the language used for testing, you could:
LANG
environment variable in your docker container, which can then be picked by the browser as system/default localeaccept-language
request headerSee Setting the browser language in Cypress