cancel
Showing results for 
Search instead for 
Did you mean: 

Testing a chrome extension with TestComplete

Highlighted
Contributor

Testing a chrome extension with TestComplete

Hello,

 

I'm trying to use TestComplete to test a Chrome extension that is currently in development. When I click on the icon it will display a popup like so:

 

2020-03-19_17h53_11.png

As far as I know there is no way to reliably target and click the icon. Please let me know if there is.

Since the popup is actually another webpage (this is just how chrome extensions work) I tried to work around this by opening it by itself. You can do this by opening a url like chrome-extension://<extention-unique-id>/popup.html

 

So now I have a web page like this:

 

2020-03-19_17h59_05.png

 

But for some reason, I cannot find the 'Take Screenshot' button in TestComplete.

It finds the page but it does not have any children

 

2020-03-19_18h06_02.png

 

Here is the HTML for the page:

<html>
  <head>
        <style>
            button {
                white-space: nowrap;
                outline: none;
            }
        </style>
    </head>
    <body>
    <button id="takeScreenshot">Take Screenshot</button>
        <script src="popup.js"></script>
    </body>
</html>

 

Does anyone have any ideas/experiance testing chrome extensions? I came up with this method from this selenium post so I know it's possible

 

Thanks!

8 REPLIES 8
Highlighted
Community Hero

Re: Testing a chrome extension with TestComplete

This is one of the few cases where I'd suggest using FindChildByXPath.  My guess is that the button is not recognized by TestComplete's engine as a UI component because it doesn't match some sort of pattern.  So, an XPath search may find the button and allow you to interact with it.

 

https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/web-objects/findchild...


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Contributor

Re: Testing a chrome extension with TestComplete

@tristaanogre 

 

I tried FindChildByXPath but no luck...

I'm noticed that the SmartBear extension doesn't inject the hidden nodes that it normally does in other pages.

When I right click on the extension while my chrome extension page is open I see:

2020-03-20_09h15_19.png

I think this is a chrome limitation. It doesn't allow us to inject into it's internal pages. 

 

For security considerations Chrome refuses all extensions to inject code into its internal pages (about:*chrome:*). Because of that, internal pages, like the new tab page, the extension manager, the download manager, the history page and so on, are not accessible to TestComplete.

 

Source: https://support.smartbear.com/testcomplete/docs/app-testing/web/general/considerations.html

 

I may need to switch to selenium for this one... It doesn't have this limitation.

Highlighted
Community Hero

Re: Testing a chrome extension with TestComplete

@thePantz :

Hi,

 

I am afraid that you are referencing help topic that describes exactly the reason of the problem.

One quick idea meanwhile:

-- If TestComplete Object Browser can access internals of the .contentDocument property, you may try to search for and work with web elements via native DOM functions like it is described in the https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/page/contentdocument-... and https://support.smartbear.com/testcomplete/docs/app-testing/web/general/common-tasks/javascript.html help topics.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Moderator

Re: Testing a chrome extension with TestComplete

Hi @thePantz,

 

Because of the Chrome specifics, TestComplete can only get access to the viewport of the browser - the actual pages you visit. That's why currently there is no way to recognize elements in extension popups. As far as I know, the same goes for Selenium - it only allows you to work with the popup if you open it in Chrome as an individual HTML page, but TestComplete has no issues with this scenario as well.

 

As a workaround, I can suggest using the image-based approach - finding elements by their images. You can also use Optical Character Recognition to obtain elements by their text (please note that it requires a separate license for the TC IQ add-on).

 

Julia Bernikova
SmartBear Customer Care Product Lead - TestComplete
Highlighted
Contributor

Re: Testing a chrome extension with TestComplete

@AlexKaras I'm afraid the .contentDocument I get is null in this case. However it is visible if I change my my Web Object Model from a Tree View Model to a DOM Model

Highlighted
Moderator

Re: Testing a chrome extension with TestComplete

@thePantz,

 

The DOM model is a deprecated web testing mode which might cause issues with performance, so
I suggest you stick with the Tree model.

 

Julia Bernikova
SmartBear Customer Care Product Lead - TestComplete
Highlighted
Contributor

Re: Testing a chrome extension with TestComplete

@JuliaBernikova As I explained in my original post, TestComplete cannot locate the elements when you open the popup on an indivudual page. I did not have difficulties when using Selenium so I have gone that route. I will not pay for an Image Recognition module when I can get more reliable results from Selenium.

Highlighted
Moderator

Re: Testing a chrome extension with TestComplete

@thePantz,

 

I should have put it differently: by an individual HTML page, I meant opening HTML locally as a file, not via chrome-extension://. It's good to know that Selenium supports this mode though - the next TestComplete version will introduce a cross-platform web testing feature that allows running tests using Selenium Grid. So, our product team will check if we can make TestComplete work with chrome-extension:// pages too.

 

Julia Bernikova
SmartBear Customer Care Product Lead - TestComplete
New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
A new challenge is here!

Create a function to drag one element to another for the TechCorner tag!

Will you dare to take the challenge?


Scripts created in July:
- Passing custom command-line arguments as a test parameter
Top Kudoed Authors