Skip to content

Commit

Permalink
QE-13684 Fix injecting cucu fuzzy find library (#372)
Browse files Browse the repository at this point in the history
In cases where a webpage redirects to another webpage, the context of
the browser is cleared and the loaded javascript is lost. This causes
`jQuery` or `jqCucu` not defined error.

We don't need to load the needed javascript code at the beginning of the
new browser since it's loaded at each `fuzzy.find` call.

In this PR, the injection of the all the needed JS code is combined into
one browser execution. This reduces the chance of half loaded code
  • Loading branch information
ddl-xin authored Oct 13, 2023
1 parent 86c5d12 commit e36ad16
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project closely adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.167.0
- Fix - fuzzy JS code injection in web page redirection

## 0.166.0
- Add - functions and steps for clicking a row in a table

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cucu"
version = "0.166.0"
version = "0.167.0"
license = "MIT"
description = "Easy BDD web testing"
authors = ["Domino Data Lab <[email protected]>"]
Expand Down
1 change: 0 additions & 1 deletion src/cucu/browser/selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ def open(
raise Exception(f"unknown browser {browser}")

self.driver.set_window_size(width, height)
self.wait_for_page_to_load()

def get_log(self):
if config.CONFIG["CUCU_BROWSER"] == "firefox":
Expand Down
21 changes: 10 additions & 11 deletions src/cucu/fuzzy/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pkgutil
from enum import Enum

from cucu import logger
from cucu.browser.frames import search_in_all_frames


Expand All @@ -27,17 +28,15 @@ def init(browser):
parameters:
browser - ...
"""
browser.execute(load_jquery_lib())

# to prevent interference with the jQuery used on the web page
browser.execute("window.jqCucu = jQuery.noConflict(true);")
script = "return window.jqCucu && jqCucu.fn.jquery;"
jquery_version = browser.execute(script)

while jquery_version is None or not jquery_version.startswith("3.5.1"):
jquery_version = browser.execute(script)

browser.execute(load_fuzzy_lib())
script = "return typeof cucu !== 'undefined' && typeof cucu.fuzzy_find === 'function';"
cucu_injected = browser.execute(script)
if cucu_injected:
# cucu fuzzy find already exists
return

logger.debug("inject cucu fuzzy find library to the browser")
jqCucu_script = "window.jqCucu = jQuery.noConflict(true);"
browser.execute(load_jquery_lib() + jqCucu_script + load_fuzzy_lib())


class Direction(Enum):
Expand Down
4 changes: 1 addition & 3 deletions src/cucu/steps/browser_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from selenium.webdriver.common.keys import Keys

from cucu import config, fuzzy, logger, retry, run_steps, step
from cucu import config, logger, retry, run_steps, step
from cucu.browser.selenium import Selenium


Expand Down Expand Up @@ -37,7 +37,6 @@ def open_a_browser(ctx, url):

logger.debug(f"navigating to url #{url}")
ctx.browser.navigate(url)
fuzzy.init(ctx.browser)


@step('I open a new browser at the url "{url}"')
Expand All @@ -46,7 +45,6 @@ def open_a_new_browser(ctx, url):
ctx.browsers.append(ctx.browser)
logger.debug(f"navigating to url #{url}")
ctx.browser.navigate(url)
fuzzy.init(ctx.browser)


@step("I execute in the current browser the following javascript")
Expand Down

0 comments on commit e36ad16

Please sign in to comment.