1# Copyright 2019 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5
6import os
7import time
8
9from absl import app, flags
10from selenium import webdriver
11from pywinauto.application import Application
12from pywinauto.findwindows import ElementNotFoundError
13
14import test_util
15
16# A URL that is in a different language than our Chrome language.
17URL = "https://zh.wikipedia.org/wiki/Chromium"
18
19FLAGS = flags.FLAGS
20
21flags.DEFINE_bool('incognito', False,
22                  'Set flag to open Chrome in incognito mode.')
23
24
25def main(argv):
26  os.system('start chrome --remote-debugging-port=9222')
27  options = webdriver.ChromeOptions()
28  # Add option for connecting chromedriver with Chrome
29  options.add_experimental_option("debuggerAddress", "localhost:9222")
30  driver = test_util.create_chrome_webdriver(
31      chrome_options=options, incognito=FLAGS.incognito)
32  driver.get(URL)
33  time.sleep(10)
34  translatePopupVisible = None
35
36  try:
37    app = Application(backend="uia")
38    app.connect(title_re='.*Chrome|.*Chromium')
39    app.top_window() \
40       .child_window(title="Translate this page?", control_type="Pane") \
41       .print_control_identifiers()
42    translatePopupVisible = True
43  except ElementNotFoundError as error:
44    translatePopupVisible = False
45  finally:
46    driver.quit()
47    os.system('taskkill /f /im chrome.exe')
48
49  if translatePopupVisible:
50    print("TRUE")
51  else:
52    print("FALSE")
53
54
55if __name__ == '__main__':
56  app.run(main)
57