Skip to content

Commit

Permalink
Fix screenshot test with better logging and handle NL page open (#2838)
Browse files Browse the repository at this point in the history
  • Loading branch information
shifucun authored Jun 22, 2023
1 parent a95083f commit 797b080
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[pytest]
log_cli=true
log_level=INFO
log_level=ERROR
log_file=pytest_log.txt
2 changes: 1 addition & 1 deletion server/webdriver/screenshot/local/page.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"async": true
},
{
"url": "/tools/map#%26sv%3DMaxTemp_Daily_GaussianMixture_5PctProb_Greater_Atleast1DayADecade_CMIP6_Ensemble_SSP245%26pc%3D0%26denom%3DCount_Person%26pd%3Dcountry%2FUSA%26ept%3DCounty",
"url": "/tools/map#%26sv%3DDifferenceRelativeToBaseDate2006_Max_Temperature_RCP45%26pc%3D0%26denom%3DCount_Person%26pd%3Dcountry%2FUSA%26ept%3DCounty",
"height": 1200,
"async": true
},
Expand Down
2 changes: 2 additions & 0 deletions server/webdriver/screenshot/remote/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
type=str,
required=True)

logging.getLogger().setLevel(logging.ERROR)

if __name__ == "__main__":
args = parser.parse_args()
logging.info(args.domain)
Expand Down
10 changes: 9 additions & 1 deletion server/webdriver/screenshot/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
# limitations under the License.

import json
import logging
import os
import shutil
import time
import urllib.parse

from PIL import Image
from PIL import PngImagePlugin
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import UnexpectedAlertPresentException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
Expand All @@ -41,6 +44,7 @@ def run(driver, base_url, page_config_dir):
config = json.load(f)
for page in config:
# Set the window size. Testing different sizes.
driver.switch_to.new_window('window')
driver.set_window_size(width=WIDTH,
height=page['height'],
windowHandle='current')
Expand All @@ -49,7 +53,11 @@ def run(driver, base_url, page_config_dir):
# asyncronously. The web driver wait depends on it.
if page['async']:
shared.wait_for_loading(driver)
WebDriverWait(driver, shared.TIMEOUT).until(shared.charts_rendered)
try:
WebDriverWait(driver, shared.TIMEOUT).until(shared.charts_rendered)
except (TimeoutException, UnexpectedAlertPresentException) as e:
logging.error("Exception for url: %s\n%s", page['url'], e)
continue
else:
element_present = EC.presence_of_element_located((By.TAG_NAME, 'main'))
WebDriverWait(driver, shared.TIMEOUT).until(element_present)
Expand Down
3 changes: 0 additions & 3 deletions server/webdriver/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# limitations under the License.
"""Common library for functions used by multiple webdriver tests"""

import logging

from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Expand Down Expand Up @@ -67,6 +65,5 @@ def charts_rendered(driver):
try:
c.find_element(By.CLASS_NAME, ASYNC_ELEMENT_CLASS)
except NoSuchElementException:
logging.info(c.text)
return False
return True

0 comments on commit 797b080

Please sign in to comment.