未定义,当它从Selenium触发时,在Chrome通知中未定义 [英] Undefined, Undefined in Chrome notification when it's triggered from Selenium

查看:378
本文介绍了未定义,当它从Selenium触发时,在Chrome通知中未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python编写的网站自动化,并使用Angular,其中有很多确认通知。我遇到的问题是,Behat似乎不认识这些通知,更不用说允许我与他们进行交互。



我附上了通知应该显示的屏幕截图



pre> 然后我选择删除媒体计划行复选框
我删除媒体计划行
我选择是以确认删除
和我选择否以确认删除

和我的上下文:

  / ** 
* @Then / ^我选择删除媒体计划行复选框$ /
* /
public function iDeleteMediaPlanLineCheckbox()
{
/ **
* @var AddMediaPlan $ addMediaPlan
* /
$ addMediaPlan = $ this-> getPage 'AddMediaPlan');
$ addMediaPlan-> deleteMediaPlanLineCheckbox();
}

/ **
* @Given / ^我删除媒体计划行$ /
* /
public function iDeleteTheMediaPlanLine $ b {
/ **
* @var AddMediaPlan $ addMediaPlan
* /
$ addMediaPlan = $ this-> getPage('AddMediaPlan');
$ addMediaPlan-> deleteMediaPlanLines();
}

public function deleteMediaPlanLineCheckbox()
{
$ this-> getElement('deleteMediaPlanLineArea') - > click
$ this-> getSession() - > wait(2000);
$ element = $ this-> getElement('deleteMediaPlanLineCheckbox');
$ this-> scrollWindowToElement($ element);
$ element-> click();
$ this-> getSession() - > wait(4000);
}

public function deleteMediaPlanLines()
{
$ this-> getSession() - > wait(2000);
$ this-> getElement('deleteMediaPlanLines') - > click();
$ this-> getSession() - > wait(800000);
}

public function deletePopUpYes()
{
$ this-> getElement('deletePopUpYes') - > click
$ this-> getSession() - > wait(2000);
}

public function deletePopUpNo()
{
$ this-> getElement('deletePopUpNo') - > click
$ this-> getSession() - > wait(2000);
}

工作通知



是视频。

解决方案

如果我理解一切正确,你说的是通知,而不是弹出窗口。直到今天的通知仍然是实验性功能,有些浏览器不支持它们。我还假设支持它们的浏览器具有不同的API来调用它们,这些都不是的一部分



我相信你可以找到一种方法让通知显示正确的细节,但你肯定赢得了能够与它进行交互。这是另一个答案支持我的想法。



我可以看到Chrome在视频中抱怨安全性,这可能是为什么你得到未定义的值的问题,解决这个问题的方法是将此配置传递Selenium会话(这是Behat 3 config示例):

  selenium2:
browser:'chrome'
capabilities:
browser:'chrome'
extra_capabilities:
chromeOptions:
args:
- '--test-type'

很好的问题,但不应该被拒绝。


I am working on automating a website written in Python and using Angular where there are many confirmation notifications. The issue I have is that Behat doesn't seem to recognise those notifications, let alone allow me to interact with them.

I have attached screenshots of what the notification should look like and the Undefined – Undefined error message Behat produces instead.

My scenario:

Then I select the Delete the Media Plan Line Checkbox
And I delete the Media Plan Line
And I select Yes to confirm the deletion
And I select No to confirm the deletion

And my context:

/**
 * @Then /^I select the Delete the Media Plan Line Checkbox$/
 */
public function iDeleteMediaPlanLineCheckbox()
{
    /**
     * @var AddMediaPlan $addMediaPlan
     */
    $addMediaPlan= $this->getPage('AddMediaPlan');
    $addMediaPlan->deleteMediaPlanLineCheckbox();
}

/**
 * @Given /^I delete the Media Plan Line$/
 */
public function iDeleteTheMediaPlanLine()
{
    /**
     * @var AddMediaPlan $addMediaPlan
     */
    $addMediaPlan= $this->getPage('AddMediaPlan');
    $addMediaPlan->deleteMediaPlanLines();
}

public function deleteMediaPlanLineCheckbox ()
{
    $this->getElement('deleteMediaPlanLineArea')->click();
    $this->getSession()->wait(2000);
    $element = $this->getElement('deleteMediaPlanLineCheckbox');
    $this->scrollWindowToElement($element);
    $element->click();
    $this->getSession()->wait(4000);
}

public function deleteMediaPlanLines ()
{
    $this->getSession()->wait(2000);
    $this->getElement('deleteMediaPlanLines')->click();
    $this->getSession()->wait(800000);
}

public function deletePopUpYes ()
{
    $this->getElement('deletePopUpYes')->click();
    $this->getSession()->wait(2000);
}

public function deletePopUpNo ()
{
    $this->getElement('deletePopUpNo')->click();
    $this->getSession()->wait(2000);
}

Working notification

http://i58.tinypic.com/1z3qpsw.png

Broken notification

And here is the video.

解决方案

If I understand everything correctly, you are talking about notifications, not popups. Notifications up to this day remain pretty much experimental features and some browsers don't support them. I also assume that the browsers that do support them have different APIs for invoking them, none of which are part of the Webdriver API, which is used by Behat.

I'm sure you can find a way to make the notification display proper details, but you definitely won't be able to interact with it. Here's another answer supporting my thoughts.

I can see that Chrome in the video complains about the security, this might be the problem why you get undefined values, the way to solve this is to pass this config to the selenium session (this is Behat 3 config example):

selenium2:
    browser: 'chrome'
    capabilities:
        browser: 'chrome'
        extra_capabilities:
            chromeOptions:
                args:
                    - '--test-type'

Nice question though, it shouldn't be downvoted.

这篇关于未定义,当它从Selenium触发时,在Chrome通知中未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆