0

We have a Chrome extension, and we want to test it with Selenium. The users install our extension by clicking a button on our website (after logging in or creating a signature). I created a Selenium test, but I don't know how to confirm the "Add" dialog when installing the extension. Here is my code:

import sys
sys.path.insert(0, 'libs')

import unittest
from selenium import webdriver


class SeleniumTests(unittest.TestCase):
    def setUp(self):
        caps = {}

        caps['name'] = 'Chrome Inbox Test'
        caps['build'] = '1.0'
        caps['browser_api_name'] = 'Chrome40x64'
        caps['os_api_name'] = 'Win8.1'
        caps['screen_resolution'] = '1280x1024'
        caps['record_video'] = 'true'
        caps['record_network'] = 'true'
        caps['record_snapshot'] = 'true'

        self.driver = webdriver.Remote(
            desired_capabilities=caps,
            command_executor="http://[username]:[password]@hub.crossbrowsertesting.com:80/wd/hub"
        )

        self.driver.implicitly_wait(time_to_wait=10)

    def login_to_webapp(self):
        self.driver.get(url='http://example.com/logout')
        self.driver.maximize_window()
        self.assertEqual(first="Web Editor", second=self.driver.title)
        action = webdriver.ActionChains(driver=self.driver)
        action.move_to_element(to_element=self.driver.find_element_by_xpath(xpath="//div[@id='header_floater']/div[@class='header_menu']/button[@class='btn_header signature_menu'][text()='My signature']"))
        action.perform()
        self.driver.find_element_by_xpath(xpath="//ul[@id='signature_menu_downlist'][@class='menu_downlist']/li[text()='Log In']").click()
        self.driver.find_element_by_xpath(xpath="//form[@id='atho-form']/div[@class='input']/input[@name='useremail']").send_keys("[email]")
        self.driver.find_element_by_xpath(xpath="//form[@id='atho-form']/div[@class='input']/input[@name='password']").send_keys("[password]")
        self.driver.find_element_by_xpath(xpath="//form[@id='atho-form']/button[@type='submit'][@class='atho-button signin_button'][text()='Sign in']").click()

    def install_chrome_extension(self):
        self.assertEqual(first=0, second=len(self.driver.find_elements_by_xpath(xpath="//div[@id='emails_overlay'][contains(@style,'display: block;')]/div[@id='emails_pick'][contains(@style,'display: block;')]")))
        self.driver.find_element_by_xpath(xpath="//button[@id='save']/span[@class='no-extension'][text()=\"OK, I'm Done\"]").click()
        # Add extension to Chrome.
        self.assertEqual(first=1, second=len(self.driver.find_elements_by_xpath(xpath="//div[@id='emails_overlay'][contains(@style,'display: block;')]/div[@id='emails_pick'][contains(@style,'display: block;')]"))) # Will be true only if the extension is installed.

    def test_chrome_inbox(self):
        self.login_to_webapp()
        self.install_chrome_extension()

    def tearDown(self):
        print("Done with session %s" % self.driver.session_id)
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()

After clicking "OK, I'm Done" with Selenium, I want to confirm adding the extension to Chrome (a dialog appears with "Add" or "Cancel", I want to click "Add"). How do I do it?

If that's not possible, I can install the extension directly from Chrome Web Store. But I prefer to test installing the extension from our website, if possible.

animuson
  • 53,861
  • 28
  • 137
  • 147
Uri
  • 2,992
  • 8
  • 43
  • 86
  • @Xan I saw this solution [http://stackoverflow.com/questions/26897773/how-to-accept-the-popup-presented-when-installing-extension-in-selenium], but I don't know how to implement it with our extension (where the dialog appears after clicking a button on our website). – Uri Feb 22 '15 at 12:46
  • I think that solution is outdated; this is no longer a separate dialog window but some (very well isolated) HTML dialog. – Xan Feb 22 '15 at 12:47
  • @Xan it's only from 3 months ago, are you sure it's outdated? – Uri Feb 22 '15 at 13:45

0 Answers0