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.