# Practical Phase Retrieval Using Double Deep Image Priors

###### Abstract

Phase retrieval (PR) concerns the recovery of complex phases from complex
magnitudes. We identify the connection between the difficulty level and the
number and variety of symmetries in PR problems. We focus on the most
difficult far-field PR (FFPR), and propose a novel method using double deep
image priors. In realistic evaluation, our method outperforms all competing
methods by large margins. As a single-instance method, our method requires no
training data and minimal hyperparameter tuning, and hence enjoys good
practicality.

Index Terms—  Phase Retrieval, Deep Image Prior, Inverse Problems, (Bragg)
Coherent Diffraction Imaging

##  1 Introduction

In scientific imaging, observable physical quantities about the object of
interest are often complex-valued, e.g., when diffraction happens [1].
However, practical detectors can only record complex magnitudes, but not
phases, resulting in phaseless observations. Phase retrieval (PR), broadly
defined, is the nonlinear inverse problem (NIP) of estimating the object of
interest from the phaseless observations. PR is central to coherent
diffraction imaging ((B)CDI) [2, 3], image-based wavefront sensing [4], radar
and sonar sensing [5]; see the recent survey [6].

Which phase retrieval (PR)? Without loss of generality, consider a 2D object
of interest $\mathbf{X}\in\mathbb{C}^{m\times n}$, and a physical observation
model $\mathcal{A}$ that leads to an ideal complex-valued observation
$\mathcal{A}(\mathbf{X})\in\mathbb{C}^{m^{\prime}\times n^{\prime}}$1113D
phase retrieval problems can be formalized similarly. . However, the detector
can only record $\mathbf{Y}=\left|\mathcal{A}(\mathbf{X})\right|^{2}$, where
$\left|\cdot\right|^{2}$ denotes the elementwise squared magnitudes—which
correspond to the photon flux the detector is able to capture. In far-field
(Fraunhofer) PR (FFPR) that stems from far-field propagation and is also the
focus of this paper, $\mathcal{A}$ is the oversampled 2D Fourier transform
$\mathcal{F}$ with $m^{\prime}\geq 2m-1$ and $n^{\prime}\geq 2n-1$ to ensure
recoverability. For notational simplicity, we assume $m,n$ are odd numbers,
and $\mathbf{X}$ is centered at $(0,0)$ so that index ranges are
$[-(m-1)/2,(m-1)/2]$ and $[-(n-1)/2,(n-1)/2]$, respectively. Numerous other
$\mathcal{A}$’s have been studied in the literature, notable ones including:

  * •

Generalized PR (GPR):
$\mathcal{A}(\mathbf{X})=\left\\{\left\langle\mathbf{A}_{i},\mathbf{X}\right\rangle\right\\}_{i=1}^{k}$
where $\mathbf{A}_{i}$’s are iid Gaussian or randomly-masked Fourier basis
matrices [7, 8]. These elegant mathematical models do not correspond to
physically feasible imaging systems so far;

  * •

Near-Field (Fresnel) PR (NFPR):
$\mathcal{A}(\mathbf{X})=\mathcal{F}(\mathbf{X}\odot[e^{i\pi\beta\left(i^{2}+j^{2}\right)}]_{i,j})$
[9, 10], where the constant $\beta>0$ depends on the sampling intervals,
wavelength, and imaging distance [11], comes from near field propagation. Note
that FFPR corresponds to $\beta\to 0$, and PR problems solved in image-based
wavefront sensing for astronomical applications correspond to multi-plane
near-field propagation with sequential optical aberrations [12];

  * •

Holographical PR (HPR):
$\mathcal{A}(\mathbf{X})=\mathcal{F}\left([\mathbf{X},\mathbf{R}]\right)$,
where $\mathbf{R}$ is a known reference that is put side-by-side with the
object of interest $\mathbf{X}$ [13]; depending on the propagation distance,
near-field versions are also possible [1, Chapter 11];

  * •

Ptychography (PTY): $\mathbf{X}$ is raster scanned by a sharp illumination
pattern $\mathbf{W}$ that is focused over a local patch of $\mathbf{X}$ each
time. Now $\mathbf{Y}$ is the set of magnitude measurements
$\mathbf{Y}_{i}=\left|\mathcal{F}\left(\mathbf{W}\odot\mathbf{X}(\mathbf{p}_{i})\right)\right|^{2}$,
where $\mathbf{p}_{i}$ indexes the raster grid [14, 15].

Fig. 1: Illustration of the three intrinsic symmetries in FFPR on simulated complex-valued crystal data (see Section 4 for details). Any composition of 2D conjugate flipping, translation, and global phase, when applied to $\mathbf{X}$, leads to the same set of magnitudes $\mathbf{Y}$.  Table 1: Comparison of GPR, NFPR, and FFPR in terms of their symmetries and numerical solvability with the least-squares formulation in Eq. 1.1 combined with gradient descent. PR model |  GPR |  NFPR |  FFPR
---|---|---|---
Symmetry |  global phase |  global phase |  global phase, translation, 2D conjugate flipping
Final loss of solving LS in Eq. 1.1 using gradient descent from $100$ random initializations |  |  |

Symmetry matters Identifiability in PR is often up to intrinsic symmetries.
For example, any global phase factor $e^{i\theta}$ added to $\mathbf{X}$
leaves $\mathbf{Y}$ unchanged for FFPR, NFPR, GPR, and PTY, i.e., global phase
symmetry. While this is the only symmetry for NFPR, GPR, and PTY, FFPR has two
other symmetries: translation and 2D conjugate flipping, as demonstrated in
Fig. 1 [16]. A crucial empirical observation is that the difficulty level of a
PR problem is proportional to the number of its symmetries. To see the point,
consider a natural least-squares (LS) formulation of PR222We consider this
inner-unsquared version as it has better noise stability than the inner-
squared one in practice [17].

$\displaystyle\min_{\mathbf{X}\in\mathbb{C}^{m\times
n}}\;\frac{1}{m^{\prime}n^{\prime}}\|\sqrt{\mathbf{Y}}-\left|\mathcal{A}(\mathbf{X})\right|\|_{F}^{2},$
(1.1)

with the groundtruth complex-valued 2D crystal sample in Fig. 1 as the target
$\mathbf{X}$. On GPR with Gaussian, NFPR, and FFPR, we run gradient descent
with $100$ random starts respectively and record their final convergent
losses. As evident from Table 1, while we can consistently find numerically
satisfactory solutions for GPR and NFPR, we always find bad local solutions
for FFPR—which has three symmetries. Similarly, for FFPR,

Fig. 2: HIO to solve FFPR with vs without precise support. We plot the final
least-squares losses defined in Eq. 1.1 over $100$ random starts. $\mathbf{X}$
is the groundtruth in Fig. 1.

the gold-standard hybrid input-output (HIO) algorithm can typically solve the
problem when provided with tight support specification333Specifically, we mean
that the tightest rectangular bounding box of the support is provided.
—translation symmetry is killed, but HIO fails when the support is
loose—translation symmetry remains; see Fig. 2. Moreover, our prior works [18,
19, 20, 21] also show the learning difficulties caused by these symmetries
when one develops data-driven methods for solving FFPR. See Section 2 for
details of HIO and related algorithms.

Our focus on practical FFPR methods We have stressed that symmetries largely
determine the difficulty level of PR. However, in previous research, there are
often simplifications to FFPR, including (1) randomized the model
$\mathcal{A}$ that only keeps the global phase symmetry, (2) evaluation on
natural images that removes the translation symmetry and simplifies the global
phase symmetry into sign symmetry [8, 22, 23]. These simplifications
invariably lead to FFPR methods that do not work on practical data. The goal
of this paper is to develop practical methods for FFPR that involve all three
symmetries. In particular, we propose a novel FFPR method based on double deep
image priors (see Section 3), and validate its superiority over state-of-the-
art (SOTA) on realistic datasets (see Section 4).

##  2 FFPR: Formulation and Prior Arts

FFPR model The object of interest is $\mathbf{X}\in\mathbb{C}^{m\times n}$,
and
$\mathbf{Y}=\left|\mathcal{F}(\mathbf{X})\right|^{2}\in\mathbb{R}_{+}^{m^{\prime}\times
n^{\prime}}$. Here, $\mathcal{F}$ is the oversampled 2D Fourier transform:

$\displaystyle\mathcal{F}(\mathbf{X})=\mathbf{F}_{m^{\prime}}\begin{bmatrix}\mathbf{X}&\mathbf{0}\\\
\mathbf{0}&\mathbf{0}\end{bmatrix}\mathbf{F}_{n^{\prime}}^{\intercal},$ (2.1)

where $\mathbf{F}_{m^{\prime}}$ and $\mathbf{F}_{n^{\prime}}$ are normalized
discrete Fourier matrices. We always assume that $m^{\prime}\geq 2m-1$ and
$n^{\prime}\geq 2n-1$, which is necessary to ensure recoverability.

Prior arts on FFPR Since we focus on practical FFPR, here we only discuss
methods that have been tested on FFPR with at least partial success.

  * •

Classical iterative methods: Due to the failure of the LS in Eq. 1.1, most (if
not all) classical methods tackle the over-parameterized feasibility
reformulation:

$\displaystyle\text{find}\;\mathbf{Z}\in\mathbb{C}^{m^{\prime}\times
n^{\prime}}\;\operatorname{s.t.}\;\left|\mathcal{F}(\mathbf{Z})\right|^{2}=\mathbf{Y},\mathcal{L}(\mathbf{Z})=\mathbf{0},$
(2.2)

where $\mathcal{L}$ restricts $\mathbf{Z}$ to the zero-padding locations
defined by the oversampling in Eq. 2.1. More refined support information can
be naturally incorporated into the support constraint
$\mathcal{L}(\mathbf{Z})=\mathbf{0}$. These classical methods are all based on
generalized alternating projection for solving Eq. 2.2, represented by error-
reduction (ER), hybrid input-output (HIO) [24], reflection average alternating
reflectors (RAAR) [25], difference map (DM) [26], and oversampling smoothness
(OSS) [27]. They are empirically observed to find good solutions for FFPR,
provided that the support specification for $\mathbf{Z}$ is tight and
hyperparameters are properly tuned. Alternative formulations solved by second-
order methods [28, 29] are less sensitive to hyperparameters. However, all
these methods require tight support specification to avoid the translation
symmetry—failing so leads to spurious solutions that look like the
superposition of translated copies; see Fig. 3.

Fig. 3: Two failure examples when solving FFPR using classical iterative
methods without precise support specification and without shrinkwrap.

This is addressed by the popular shrinkwrap trick [30] in practice, which
refines the support by smoothing-and-thresholding over iterations.

  * •

Data-driven methods: The first line represents the inverse mapping from
$\mathbf{Y}$ to $\mathbf{X}$ by a deep neural network (DNN)
$g_{\mathbf{\theta}}$, which is trained either over an extensive training set
$\left\\{(\mathbf{Y}_{i},\mathbf{X}_{i})\right\\}_{i}$, or unpaired
$\left\\{\mathbf{Y}_{i}\right\\}_{i}$ and
$\left\\{\mathbf{X}_{i}\right\\}_{i}$ only by observing the cycle consistency
constraint:
$\left|\mathcal{F}(g_{\mathbf{\theta}}(\mathbf{Y}))\right|^{2}\approx\mathbf{Y}$
[31, 32, 33, 34, 35, 36, 18, 19, 20, 21, 37, 38]. But, as discussed in our
prior works [18, 19, 20, 21], symmetries in the problem cause substantial
learning difficulties, as any $\mathbf{Y}$ maps to a family of equivalent
$\mathbf{X}$’s. The second line [39, 40, 41] is tied to specific iterative
methods for solving FFPR and replaces certain components of these methods with
trainable DNNs. A common limitation of this line is the reliance on good
initialization that is obtained from classical iterative methods. Therefore,
this family can be viewed as a final refinement of the results from classical
methods and does not address the essential difficulty of solving FFPR. Both
lines suffer in generalization when the training data are not sufficiently
representative.

Our method overcomes the limitations of both classical and data-driven
methods. (1) No training set: it works with a single problem instance each
time, with zero extra training data; (2) No shrinkwrap: we can specify the
size of $\mathbf{X}$ directly as $\lfloor m^{\prime}/2\rfloor\times\lfloor
n\rfloor$, i.e., the information-theoretic recovery limit, without worrying
about the translation symmetry; (3) Minimal tuning: mostly we only need to
tune $2$ learning rates as hyperparameters, vs. the $5$ or $6$ hyperparameters
used in HIO+ER+Shrinkwrap (HES) for practical coherent diffraction imaging
(CDI) [42].

##  3 Our method: FFPR using double DIPs

Deep image prior (DIP) for visual inverse problems DIP and variants [43]
parameterize visual objects as outputs of DNNs—typically structured
convolutional networks to favor spatially smooth structures, i.e.,
$\mathbf{x}=G_{\mathbf{\theta}}(\mathbf{z})$, where $\mathbf{z}$ is normally a
random but fixed seed, and $G_{\mathbf{\theta}}$ is a trainable DNN
paramaterized by $\mathbf{\theta}$. For a visual inverse problem of the form
$\mathbf{y}\approx f(\mathbf{x})$ where $\mathbf{y}$ is the observation and
$f$ is the observation model, the classical regularized data-fitting
formulation

$\displaystyle\min_{\mathbf{x}}\;\ell\left(\mathbf{y},f(\mathbf{x})\right)+\lambda\Omega(\mathbf{x})$
(3.1)

can now be empowered by DIP and turned into

$\displaystyle\min_{\mathbf{\theta}}\;\ell\left(\mathbf{y},f\circ
G_{\mathbf{\theta}}(\mathbf{z})\right)+\lambda\Omega\circ
G_{\mathbf{\theta}}(\mathbf{z}).$ (3.2)

This simple idea has recently claimed numerous successes in computer vision
and computational imaging; see, e.g., the recent survey [44], and our recent
work addressing practicality issues around DIP [45, 46, 47]. A salient feature
of DIP is the strong structured prior it imposes through DNNs, with zero extra
data! Although the theoretical understanding of DIP is still far from
complete, current theories attribute its success to two aspects: (1)
structured priors imposed by convolutional and upsampling operations, and (2)
global optimization due to significant overparameterization and first-order
methods [48, 49].

Applying DIP to FFPR As shown in Table 1, solving the LS formulation in Eq.
1.1 using gradient descent always gets trapped in bad local minimizers. It is
then tempting to try DIP, as (1) the objects we try to recover in scientific
imaging are visual objects and probably can be blessed by the structured
priors enforced by DIP, and (2) more importantly, the issue we encounter in
solving the LS is exactly about global optimization, which could be eliminated
by overparameterization in DIP444Interestingly, the feasibility reformulation
in Eq. 2.2 solved by classical methods can also be understood as performing
overparameterization.. In fact, we have tried the single-DIP version in our
preliminary work [50]:

$\displaystyle\min_{\mathbf{\theta}}\;\|\sqrt{\mathbf{Y}}-\left|\mathcal{F}\circ
G_{\mathbf{\theta}}(\mathbf{z})\right|\|^{2}_{F},\quad
G_{\mathbf{\theta}}(\mathbf{z})\in\mathbb{C}^{m\times n}.$ (3.3)

Systematic evaluation in Figs. 4 and 5 shows that it is already competitive
compared to the gold-standard HES, although it struggles to reconstruct
complicated complex phases.

Double DIPs boost the performance For FFPR applications such as CDI,
$\mathbf{X}$ as a complex-valued object can often be naturally split into two
parts with disparate complexity levels. For example, in Bragg CDI on crystals,
the magnitude part on the support is known to have uniform values, but the
phase part can have complex spatial patterns due to strains [51, 52, 53]; in
CDI on live cells, the nonnegative real part contains useful information, and
the imaginary part acts like small-magnitude noise [54]. In these cases, due
to the apparent asymmetry in complexity, it makes sense to parameterize
$\mathbf{X}$ as two separate DIPs [55, 47] instead of one:

$\displaystyle\mathbf{X}=G^{1}_{\mathbf{\theta}_{1}}\left(\mathbf{z}_{1}\right)e^{iG^{2}_{\mathbf{\theta}_{2}}\left(\mathbf{z}_{2}\right)},\;\text{or}\;\mathbf{X}=G^{1}_{\mathbf{\theta}_{1}}\left(\mathbf{z}_{1}\right)+iG^{2}_{\mathbf{\theta}_{2}}\left(\mathbf{z}_{2}\right).$
(3.4)

This can be justified as balancing the learning paces: with a single DIP,
“simple” part is learned much faster than the “complex” part; with double
DIPs, we can balance the learning paces by making the learning rate for the
“simple” part relatively small compared to that for the “complex” part. We
observe a substantial performance boost in Figs. 4 and 5 due to the double-DIP
parametrization.

Fig. 4: Visual comparison of reconstruction results by different methods on 2D
simulated crystal data Fig. 5: Quantitative comparison of reconstruction
results by different methods on 2D simulated crystal data by symmetry-adjusted
MSE Fig. 6: Visual comparison of reconstruction results by HIO+ER+Shrinkwrap
and our method on a 3D simulated crystal instance

##  4 Experiments Results

Evaluation on 2D simulated Bragg CDI crystal data We first compare our Double-
DIP method with multiple SOTA methods for FFPR, including Naive [37], CGAN
[56], Passive [33], prDeep [39], HIO+ER, HIO+ER+Shrinkwrap (HES), and
(single-)DIP on simulated 2D data for Bragg CDI on crystals. The final form of
our learning objective for this task is:

$\min_{\mathbf{\theta}_{1},\mathbf{\theta}_{2}}\;\|\sqrt{\mathbf{Y}}-|\mathcal{F}\circ
G^{1}_{\mathbf{\theta}_{1}}\left(\mathbf{z}_{1}\right)e^{iG^{2}_{\mathbf{\theta}_{2}}\left(\mathbf{z}_{2}\right)}|\|^{2}_{F},\\\
G^{1}_{\mathbf{\theta}_{1}}\left(\mathbf{z}_{1}\right)\in\mathbb{C}^{m\times
n},\;G^{2}_{\mathbf{\theta}_{2}}\left(\mathbf{z}_{2}\right)\in\mathbb{C}^{m\times
n}.$ (4.1)

To ensure that the evaluation data reflect real-world complexity, we simulate
2D complex-valued crystal data in Bragg CDI applications [3]. The dataset is
generated by first creating 2D convex and nonconvex shapes based on random
scattering points in a $110\times 110$ grid on a $128\times 128$ background.
The complex magnitudes are uniformly $1$, and the complex phases are
determined by projecting the simulated 2D displacement fields (due to crystal
defects) onto the corresponding momentum transfer vectors. To maximize the
diversity, the dataset contains diverse shapes and different numbers and
densities of crystal defects that directly determine the complexity of the
phases. Although our double-DIP method is a single-instance method that
requires no training data, the dataset is large enough to support data-driven
methods, such as Passive and prDeep. For methods that require a training set,
we provide $8000$ samples. All methods are tested on $50$ samples.

From both visual (Fig. 4) and quantitative (Fig. 5) results, it is evident
that: (1) all data-driven methods, including Naive, CGAN, Passive, prDeep,
perform poorly. We believe that this is due to either the learning difficulty
caused by the three symmetries [18, 19, 20, 21] or the bad initialization
given by HIO (i.e., for prDeep); (2) HES, DIP, and our double-DIP are the top
three methods. HES deals with translation symmetry by explicitly iterative
refining the support, whereas DIP and ours do not need tight support
estimation at all, substantially reducing parameter tuning; (3) Our method
wins HES and DIP by a large margin. Although the latter two perform reasonably
well in magnitude estimation, their phase estimations are typically off for
complicated instances.

Evaluation on 3D simulated Bragg CDI crystal data We will not continue
considering data-driven methods, due to their clear performance deficiency on
2D data and the considerable cost to obtain sufficiently representative
training sets for 3D. We only compare HES, which is the gold-standard used in
Bragg CDI practice, with our double-DIP method. Since both methods can work
with single instances and need no training data, here we quickly compare their
performance qualitatively on a single 3D simulated crystal instance (the
simulation process is similar to the 2D case), as shown in Fig. 6. It is
obvious that even with Shrinkwrap iteratively refining support, HES still
struggles to get the support right. By contrast, our double-DIP method obtains
sharp support recovery and good phase estimation.

## References

  * [1] Joseph W. Goodman,  Introduction to Fourier Optics,  Freeman & Company, W. H., 4th edition, 2017.
  * [2] Jianwei Miao, Pambos Charalambous, Janos Kirz, and David Sayre,  “Extending the methodology of x-ray crystallography to allow imaging of micrometre-sized non-crystalline specimens,”  Nature, vol. 400, no. 6742, pp. 342–344, 1999.
  * [3] I. K. Robinson, I. A. Vartanyants, G. J. Williams, M. A. Pfeifer, and J. A. Pitney,  “Reconstruction of the shapes of gold nanocrystals using coherent x-ray diffraction,”  Physical Review Letters, vol. 87, no. 19, pp. 195505, oct 2001.
  * [4] D. Russell Luke, James V. Burke, and Richard G. Lyon,  “Optical wavefront reconstruction: Theory and numerical methods,”  SIAM Review, vol. 44, no. 2, pp. 169–224, jan 2002.
  * [5] Philippe Jaming,  “Phase retrieval techniques for radar ambiguity problems,”  The Journal of Fourier Analysis and Applications, vol. 5, no. 4, pp. 309–329, jul 1999.
  * [6] Yoav Shechtman, Yonina C. Eldar, Oren Cohen, Henry Nicholas Chapman, Jianwei Miao, and Mordechai Segev,  “Phase retrieval with application to optical imaging: A contemporary overview,”  IEEE Signal Processing Magazine, vol. 32, no. 3, pp. 87–109, may 2015.
  * [7] Emmanuel J Candes, Yonina C Eldar, Thomas Strohmer, and Vladislav Voroninski,  “Phase retrieval via matrix completion,”  SIAM review, vol. 57, no. 2, pp. 225–251, 2015.
  * [8] Albert Fannjiang and Thomas Strohmer,  “The numerics of phase retrieval,”  Acta Numerica, vol. 29, pp. 125–228, may 2020.
  * [9] Fei Wang, Yaoming Bian, Haichao Wang, Meng Lyu, Giancarlo Pedrini, Wolfgang Osten, George Barbastathis, and Guohai Situ,  “Phase imaging with an untrained neural network,”  Light: Science & Applications, vol. 9, no. 1, may 2020.
  * [10] Yuhe Zhang, Mike Andreas Noack, Patrik Vagovic, Kamel Fezzaa, Francisco Garcia-Moreno, Tobias Ritschel, and Pablo Villanueva-Perez,  “PhaseGAN: a deep-learning phase-retrieval approach for unpaired datasets,”  Optics Express, vol. 29, no. 13, pp. 19593, jun 2021.
  * [11] Tomoyoshi Shimobaba and Tomoyoshi Ito,  Computer Holography Acceleration Algorithms and Hardware Implementations,  Taylor & Francis Group, 2019.
  * [12] J. R. Fienup,  “Phase-retrieval algorithms for a complicated optical system,”  Applied Optics, vol. 32, no. 10, pp. 1737, apr 1993.
  * [13] David A. Barmherzig and Ju Sun,  “Towards practical holographic coherent diffraction imaging via maximum likelihood estimation,”  Optics Express, vol. 30, no. 5, pp. 6886, feb 2022.
  * [14] Pierre Thibault, Martin Dierolf, Andreas Menzel, Oliver Bunk, Christian David, and Franz Pfeiffer,  “High-resolution scanning x-ray diffraction microscopy,”  Science, vol. 321, no. 5887, pp. 379–382, jul 2008.
  * [15] Stefano Marchesini, Andre Schirotzek, Chao Yang, Hau tieng Wu, and Filipe Maia,  “Augmented projections for ptychographic imaging,”  Inverse Problems, vol. 29, no. 11, pp. 115009, oct 2013.
  * [16] Tamir Bendory, Robert Beinert, and Yonina C. Eldar,  “Fourier phase retrieval: Uniqueness and algorithms,”  in Compressed Sensing and its Applications, pp. 55–91. Springer International Publishing, 2017.
  * [17] Li-Hao Yeh, Jonathan Dong, Jingshan Zhong, Lei Tian, Michael Chen, Gongguo Tang, Mahdi Soltanolkotabi, and Laura Waller,  “Experimental robustness of fourier ptychography phase retrieval algorithms,”  Optics express, vol. 23, no. 26, pp. 33214–33240, 2015.
  * [18] Kshitij Tayal, Chieh-Hsin Lai, Vipin Kumar, and Ju Sun,  “Inverse problems, deep learning, and symmetry breaking,”  arXiv:2003.09077, Mar. 2020.
  * [19] Raunak Manekar, Kshitij Tayal, Zhong Zhuang, Chieh-Hsin Lai, Vipin Kumar, and Ju Sun,  “Breaking symmetries in data-driven phase retrieval,”  in OSA Imaging and Applied Optics Congress 2021 (3D, COSI, DH, ISA, pcAOP). 2021, Optica Publishing Group.
  * [20] Kshitij Tayal, Chieh-Hsin Lai, Raunak Manekar, Zhong Zhuang, Vipin Kumar, and Ju Sun,  “Unlocking inverse problems using deep learning: Breaking symmetries in phase retrieval,”  in NeurIPS 2020 Workshop on Deep Learning and Inverse Problems, 2020\.
  * [21] Raunak Manekar, Zhong Zhuang, Kshitij Tayal, Vipin Kumar, and Ju Sun,  “Deep learning initialized phase retrieval,”  in NeurIPS 2020 Workshop on Deep Learning and Inverse Problems, 2020\.
  * [22] D. Russell Luke, Shoham Sabach, and Marc Teboulle,  “Optimization on spheres: Models and proximal algorithms with computational performance comparisons,”  SIAM Journal on Mathematics of Data Science, vol. 1, no. 3, pp. 408–445, jan 2019.
  * [23] S. Marchesini,  “Invited article: A unified evaluation of iterative projection algorithms for phase retrieval,”  Review of Scientific Instruments, vol. 78, no. 1, pp. 011301, jan 2007.
  * [24] James R Fienup,  “Phase retrieval algorithms: a comparison,”  Applied optics, vol. 21, no. 15, pp. 2758–2769, 1982.
  * [25] D Russell Luke,  “Relaxed averaged alternating reflections for diffraction imaging,”  Inverse problems, vol. 21, no. 1, pp. 37, 2004.
  * [26] Veit Elser,  “Phase retrieval by iterated projections,”  JOSA A, vol. 20, no. 1, pp. 40–55, 2003.
  * [27] Jose A Rodriguez, Rui Xu, C-C Chen, Yunfei Zou, and Jianwei Miao,  “Oversampling smoothness: an effective algorithm for phase retrieval of noisy diffraction intensities,”  Journal of applied crystallography, vol. 46, no. 2, pp. 312–318, 2013.
  * [28] Stefano Marchesini,  “Phase retrieval and saddle-point optimization,”  JOSA A, vol. 24, no. 10, pp. 3289–3296, 2007.
  * [29] Zhong Zhuang, Gang Wang, Yash Travadi, and Ju Sun,  “Phase retrieval via second-order nonsmooth optimization,”  in ICML Workshop on Beyond First-Order Methods for Machine Learning, 2020.
  * [30] S. Marchesini, H. He, H. N. Chapman, S. P. Hau-Riege, A. Noy, M. R. Howells, U. Weierstall, and J. C. H. Spence,  “X-ray image reconstruction from a diffraction pattern alone,”  Physical Review B, vol. 68, no. 14, pp. 140101, oct 2003.
  * [31] Ayan Sinha, Justin Lee, Shuai Li, and George Barbastathis,  “Lensless computational imaging through deep learning,”  Optica, vol. 4, no. 9, pp. 1117–1125, 2017.
  * [32] Alexander Scheinker and Reeju Pokharel,  “Adaptive 3d convolutional neural network-based reconstruction method for 3d coherent diffraction imaging,”  Journal of Applied Physics, vol. 128, no. 18, pp. 184901, 2020.
  * [33] Henry Chan, Youssef SG Nashed, Saugat Kandel, Stephan O Hruszkewycz, Subramanian KRS Sankaranarayanan, Ross J Harder, and Mathew J Cherukara,  “Rapid 3d nanoscale coherent imaging via physics-aware deep learning,”  Applied Physics Reviews, vol. 8, no. 2, pp. 021407, 2021.
  * [34] Ross Harder,  “Deep neural networks in real-time coherent diffraction imaging,”  IUCrJ, vol. 8, no. Pt 1, pp. 1, 2021.
  * [35] Longlong Wu, Shinjae Yoo, Ana F Suzana, Tadesse A Assefa, Jiecheng Diao, Ross J Harder, Wonsuk Cha, and Ian K Robinson,  “Three-dimensional coherent x-ray diffraction imaging via deep convolutional neural networks,”  npj Computational Materials, vol. 7, no. 1, pp. 1–8, 2021.
  * [36] Yudong Yao, Henry Chan, Subramanian Sankaranarayanan, Prasanna Balaprakash, Ross J Harder, and Mathew J Cherukara,  “Autophasenn: unsupervised physics-aware deep learning of 3d nanoscale bragg coherent diffraction imaging,”  npj Computational Materials, vol. 8, no. 1, pp. 1–8, 2022.
  * [37] Mathew J Cherukara, Youssef SG Nashed, and Ross J Harder,  “Real-time coherent diffraction inversion using deep generative networks,”  Scientific reports, vol. 8, no. 1, pp. 1–8, 2018.
  * [38] Yuhe Zhang, Mike Andreas Noack, Patrik Vagovic, Kamel Fezzaa, Francisco Garcia-Moreno, Tobias Ritschel, and Pablo Villanueva-Perez,  “Phasegan: a deep-learning phase-retrieval approach for unpaired datasets,”  Optics express, vol. 29, no. 13, pp. 19593–19604, 2021.
  * [39] Christopher Metzler, Phillip Schniter, Ashok Veeraraghavan, et al.,  “prdeep: Robust phase retrieval with a flexible deep network,”  in International Conference on Machine Learning. PMLR, 2018, pp. 3501–3510.
  * [40] Çağatay Işıl, Figen S Oktem, and Aykut Koç,  “Deep iterative reconstruction for phase retrieval,”  Applied optics, vol. 58, no. 20, pp. 5422–5431, 2019.
  * [41] Yaotian Wang, Xiaohang Sun, and Jason Fleischer,  “When deep denoising meets iterative phase retrieval,”  in International Conference on Machine Learning. PMLR, 2020, pp. 10007–10017.
  * [42] Marcus C. Newton, Steven J. Leake, Ross Harder, and Ian K. Robinson,  “Three-dimensional imaging of strain in a single ZnO nanorod,”  Nature Materials, vol. 9, no. 2, pp. 120–124, dec 2009.
  * [43] Dmitry Ulyanov, Andrea Vedaldi, and Victor Lempitsky,  “Deep image prior,”  International Journal of Computer Vision, vol. 128, no. 7, pp. 1867–1888, 2020.
  * [44] Adnan Qayyum, Inaam Ilahi, Fahad Shamshad, Farid Boussaid, Mohammed Bennamoun, and Junaid Qadir,  “Untrained neural network priors for inverse imaging problems: A survey,”  IEEE Transactions on Pattern Analysis and Machine Intelligence, 2022\.
  * [45] Taihui Li, Zhong Zhuang, Hengyue Liang, Le Peng, Hengkang Wang, and Ju Sun,  “Self-validation: Early stopping for single-instance deep generative priors,”  arXiv preprint arXiv:2110.12271, 2021.
  * [46] Hengkang Wang, Taihui Li, Zhong Zhuang, Tiancong Chen, Hengyue Liang, and Ju Sun,  “Early stopping for deep image prior,”  arXiv preprint arXiv:2112.06074, 2021.
  * [47] Zhong Zhuang, Taihui Li, Hengkang Wang, and Ju Sun,  “Blind image deblurring with unknown kernel size and substantial noise,”  arXiv preprint arXiv:2208.09483, 2022.
  * [48] Reinhard Heckel and Mahdi Soltanolkotabi,  “Denoising and regularization via exploiting the structural bias of convolutional generators,”  arXiv preprint arXiv:1910.14634, 2019.
  * [49] Reinhard Heckel and Mahdi Soltanolkotabi,  “Compressive sensing with un-trained neural networks: Gradient descent finds a smooth approximation,”  in International Conference on Machine Learning. PMLR, 2020, pp. 4149–4158.
  * [50] Kshitij Tayal, Raunak Manekar, Zhong Zhuang, David Yang, Vipin Kumar, Felix Hofmann, and Ju Sun,  “Phase retrieval using single-instance deep generative prior,”  in OSA Optical Sensors and Sensing Congress 2021 (AIS, FTS, HISE, SENSORS, ES). 2021, Optica Publishing Group.
  * [51] JN Clark, X Huang, R Harder, and IK Robinson,  “High-resolution three-dimensional partially coherent diffraction imaging,”  Nature communications, vol. 3, no. 1, pp. 1–6, 2012.
  * [52] Felix Hofmann, Edmund Tarleton, Ross J Harder, Nicholas W Phillips, Pui-Wai Ma, Jesse N Clark, Ian K Robinson, Brian Abbey, Wenjun Liu, and Christian E Beck,  “3d lattice distortions and defect structures in ion-implanted nano-crystals,”  Scientific reports, vol. 7, no. 1, pp. 1–10, 2017.
  * [53] David Yang, Mark T Lapington, Guanze He, Kay Song, Minyi Zhang, Clara Barker, Ross J Harder, Wonsuk Cha, Wenjun Liu, Nicholas W Phillips, et al.,  “Refinements for bragg coherent x-ray diffraction imaging: Electron backscatter diffraction alignment and strain field computation,”  arXiv preprint arXiv:2203.17015, 2022.
  * [54] Gijs Van Der Schot, Martin Svenda, Filipe RNC Maia, Max Hantke, Daniel P DePonte, M Marvin Seibert, Andrew Aquila, Joachim Schulz, Richard Kirian, Mengning Liang, et al.,  “Imaging single cells in a beam of live cyanobacteria with an x-ray laser,”  Nature communications, vol. 6, no. 1, pp. 1–9, 2015.
  * [55] Yosef Gandelsman, Assaf Shocher, and Michal Irani,  ““double-DIP”: Unsupervised image decomposition via coupled deep-image-priors,”  in 2019 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR). jun 2019, IEEE.
  * [56] Tobias Uelwer, Alexander Oberstraß, and Stefan Harmeling,  “Phase retrieval using conditional generative adversarial networks,”  in 2020 25th International Conference on Pattern Recognition (ICPR). IEEE, 2021, pp. 731–738.
  * [57] Tomoyoshi Shimobaba and Tomoyoshi Ito,  Computer Holography Acceleration Algorithms and Hardware Implementations,  Taylor & Francis Group, 2019.

##  Appendix A Fresnel and Fraunhofer approximations to the diffraction
formula

Fig. 7: A schematic diffraction imaging system with parallel aperture and
imaging planes (plot adapted from
https://commons.wikimedia.org/wiki/File:Diffraction_geometry.svg under the
Creative Commons Attribution-Share Alike 3.0 Unported license.)

In this section, we clarify the difference between the near-field and far-
field models for phase retrieval, following [1, 57]. Consider the propagation
of a monochromatic wave (with wavelength $\lambda$) from an aperture plane
$z=0$ to a parallel imaging plane $z=z_{0}$ with $z_{0}\gg\lambda$; see Fig.
7. Let $U(x,y,z)$ denote the wave field. The celebrated Rayleigh-Sommerfeld
diffraction formula dictates that

$\displaystyle\boxed{U(x,y,z_{0})=\frac{1}{2\pi}\iint
U(\xi,\eta,0)\left(\frac{1}{r\left(\xi,\eta\right)}-ik\right)\frac{z_{0}}{r^{2}\left(\xi,\eta\right)}e^{ikr\left(\xi,\eta\right)}\;d\xi
d\eta},$ (A.1)

where $r\left(\xi,\eta\right)\doteq\sqrt{z_{0}^{2}+(x-\xi)^{2}+(y-\eta)^{2}}$,
$k\doteq\frac{2\pi}{\lambda}$ is the wavenumber, and the effective domain of
the double integral is the aperture $\Omega$. Moreover, write the domain of
the image plane as $\Sigma\subset\mathbb{R}^{2}$. Eq. A.1 has an equivalent
form:

$\displaystyle\boxed{U(x,y,z_{0})=\iint\widehat{U}\left(f_{X},f_{Y},0\right)e^{ikz_{0}\sqrt{1-\left(\lambda
f_{X}\right)^{2}-\left(\lambda
f_{Y}\right)^{2}}}e^{i2\pi\left(f_{X}x+f_{Y}y\right)}\;df_{X}df_{Y}},$ (A.2)

where $\widehat{U}\left(f_{X},f_{Y},0\right)=\iint
U(x,y,0)e^{-i2\pi\left(f_{X}x+f_{Y}y\right)}\;df_{X}df_{Y}$ is the 2D Fourier
transform of the planar field $U(x,y,0)$. The equivalence is due to the
convolution theorem: write
$r^{\circ}\left(x,y\right)\doteq\sqrt{z_{0}^{2}+x^{2}+y^{2}}$ and
$h(x,y,z_{0})\doteq\frac{1}{2\pi}(\frac{1}{r^{\circ}(x,y)}-ik)\frac{z_{0}}{[r^{\circ}(x,y)]^{2}}e^{ikr^{\circ}(x,y)}$.
Then Eq. A.1 can be written as $U(x,y,z_{0})=U(x,y,0)\ast h(x,y,z_{0})$. The
equivalence is clear once we recognize that
$\widehat{r^{\circ}}\left(f_{X},f_{Y},z_{0}\right)\doteq\iint
h(x,y,z_{0})e^{-i2\pi\left(f_{X}x+f_{Y}y\right)}\;df_{X}df_{Y}=e^{ikz_{0}\sqrt{1-(\lambda
f_{X})^{2}-\left(\lambda f_{Y}\right)^{2}}}$.

For Eq. A.1,
$\frac{1}{r\left(\xi,\eta\right)}-ik=\frac{1}{r\left(\xi,\eta\right)}-\frac{i2\pi}{\lambda}\approx\frac{2\pi}{i\lambda}$
as $r\left(\xi,\eta\right)\gg\lambda$ in practice. Hence we have the
simplified form called the Huygens-Fresnel principle:

$\displaystyle\boxed{U(x,y,z_{0})=\frac{z_{0}}{i\lambda}\iint
U(\xi,\eta,0)\frac{1}{r^{2}\left(\xi,\eta\right)}e^{ikr\left(\xi,\eta\right)}\;d\xi
d\eta}.$ (A.3)

We can derive two approximations to Eq. A.3, i.e., the Fresnel (i.e., near-
field) and Fraunhofer (i.e., far-field) approximations. Noting that
$\sqrt{1+\varepsilon}=1+\varepsilon/2-\varepsilon^{2}/8+O(\varepsilon^{3})$
for $\left|\varepsilon\right|\ll 1$, we can approximate

$\displaystyle
r\left(\xi,\eta\right)\doteq\sqrt{z_{0}^{2}+(x-\xi)^{2}+(y-\eta)^{2}}=z_{0}\sqrt{1+\left(\frac{x-\xi}{z_{0}}\right)^{2}+\left(\frac{y-\eta}{z_{0}}\right)^{2}}$
(A.4)

by its low-order Taylor expansions, provided that
$\left(x-\xi\right)^{2}+\left(y-\eta\right)^{2}\ll z_{0}^{2}$ for all
$\left(\xi,\eta\right)\in\Omega$. First, we have
$r^{2}\left(\xi,\eta\right)\approx z_{0}^{2}$ using only the $0$-th order
expansion. For the exponential term, since $k$ is normally large, we use the
$1$-st order expansion:

$\displaystyle\exp\left(ikr\left(\xi,\eta\right)\right)$
$\displaystyle\approx\exp\left[ik\left(z_{0}+\frac{(x-\xi)^{2}}{2z_{0}}+\frac{(y-\eta)^{2}}{2z_{0}}\right)\right]=e^{ikz_{0}}\exp\left[\frac{ik}{2z_{0}}\left((x-\xi)^{2}+(y-\eta)^{2}\right)\right],$
(A.5)

which is acceptable when

$\displaystyle\frac{z_{0}k}{8}\left(\left(\frac{x-\xi}{z_{0}}\right)^{2}+\left(\frac{y-\eta}{z_{0}}\right)^{2}\right)^{2}\ll
1\Longleftrightarrow
z_{0}^{3}\gg\frac{k}{8}\left[\left(x-\xi\right)^{2}+\left(y-\eta\right)^{2}\right]^{2}\quad\forall\,(\xi,\eta)\in\Omega,(x,y)\in\Sigma.$
(A.6)

So we arrive at the famous Fresnel approximation

$\displaystyle U(x,y,z_{0})$ $\displaystyle\approx\frac{e^{ikz_{0}}}{i\lambda
z_{0}}\iint
U(\xi,\eta,0)\exp\left[\frac{ik}{2z_{0}}\left((x-\xi)^{2}+(y-\eta)^{2}\right)\right]\;d\xi
d\eta$ $\displaystyle=\frac{e^{ikz_{0}}}{i\lambda
z_{0}}e^{\frac{ik}{2z_{0}}\left(x^{2}+y^{2}\right)}\iint\left[U(\xi,\eta,0)e^{\frac{ik}{2z_{0}}\left(\xi^{2}+\eta^{2}\right)}\right]e^{-\frac{ik}{z_{0}}(x\xi+y\eta)}\;d\xi
d\eta$

If moreover $\frac{ik}{2z_{0}}\left(\xi^{2}+\eta^{2}\right)\ll
1\Longleftrightarrow
z_{0}\gg\frac{k}{2}\left(\xi^{2}+\eta^{2}\right)\quad\forall\,(\xi,\eta)\in\Omega$,
then $e^{\frac{ik}{2z_{0}}\left(\xi^{2}+\eta^{2}\right)}\approx 1$ and hence
we obtain:

$\displaystyle U(x,y,z_{0})\approx\frac{e^{ikz_{0}}}{i\lambda
z_{0}}e^{\frac{ik}{2z_{0}}\left(x^{2}+y^{2}\right)}\iint
U(\xi,\eta,0)e^{-\frac{ik}{z_{0}}(x\xi+y\eta)}\;d\xi d\eta$

By assuming $\left(\lambda f_{X}\right)^{2}+\left(\lambda f_{Y}\right)^{2}\ll
1$ and so $\sqrt{1-\left(\lambda f_{X}\right)^{2}-\left(\lambda
f_{Y}\right)^{2}}\approx 1-\left(\lambda f_{X}\right)^{2}/2-\left(\lambda
f_{Y}\right)^{2}/2$, we can approximate Eq. A.2 as

$\displaystyle U(x,y,z_{0})$ $\displaystyle\approx
e^{ikz_{0}}\iint\widehat{U}\left(f_{X},f_{Y},0\right)e^{-i\pi
z_{0}\lambda(f_{X}^{2}+f_{Y}^{2})}e^{i2\pi\left(f_{X}x+f_{Y}y\right)}\;df_{X}df_{Y}$

This is equivalent to the forward form of Fresnel approximation, due to

$\displaystyle\mathcal{F}\left(\frac{1}{i\lambda
z_{0}}e^{\frac{ik}{2z_{0}}\left(x^{2}+y^{2}\right)}\right)=e^{-i\pi\lambda
z_{0}(f_{X}^{2}+f_{Y}^{2})},$ (A.7)

and the convolution theorem again.

So when we measure the field intensity on the image plane,

$\displaystyle\left|U(x,y,z_{0})\right|^{2}$
$\displaystyle\propto\left|\iint\left[U(\xi,\eta,0)e^{\frac{ik}{2z_{0}}\left(\xi^{2}+\eta^{2}\right)}\right]e^{-\frac{ik}{z_{0}}(x\xi+y\eta)}\;d\xi
d\eta\right|^{2}$ (A.8)
$\displaystyle\propto\left|\iint\widehat{U}\left(f_{X},f_{Y},0\right)e^{-i\pi
z_{0}\lambda(f_{X}^{2}+f_{Y}^{2})}e^{i2\pi\left(f_{X}x+f_{Y}y\right)}\;df_{X}df_{Y}\right|^{2}$
(A.9)

according to the Fresnel (near-field) approximation, and

$\displaystyle\left|U(x,y,z_{0})\right|^{2}\propto\left|\iint
U(\xi,\eta,0)e^{-\frac{ik}{z_{0}}(x\xi+y\eta)}\;d\xi d\eta\right|^{2}$ (A.10)

by the Fraunhofer (far-field) approximation. Detailed discussion of
discretization and computation can be found in [1, Chapter 5].


# Advancing BDD Software Testing: Dynamic Scenario Re-Usability And Step Auto-
Complete For Cucumber Framework

Ali Hassaan Mughal
Software Developer-II,
Xpressdocs Partners Pvt. Ltd.
MSc. Computer Science,
Kansas State University.

###### Abstract

This paper presents and implements the re-usability of scenarios within
scenarios for behavior-driven development (BDD) Gherkin test scripts in the
Cucumber Java framework. Though the focus of the presented work is on scenario
re-usability through an implementation within the Cucumber BDD Java framework,
the paper also dives a little into the limitations of Cucumber’s single-
threaded scenario execution model. This implementation increases the
modularity and efficiency of the test suite. The paper also discusses VSCode’s
step definition auto-completion integration, simplifying the test script
writing process. This functionality is handy to Quality Assurance(QA) test
writers, allowing instant access to relevant step definitions. In addition,
the use of these methods in a popular continuous integration and delivery
platform Jenkins as a Maven Java project is discussed. This integration with
Jenkins, facilitates for more efficient test automation for continuous
deployment scenarios. Empirical research and practical applications reveal
significant improvements in the speed and efficiency of test writing, which is
especially valuable for large and complex software projects. Integrating these
methods into traditional sequential BDD practices paves the way towards more
effective, efficient, and sustainable test automation strategies.

_Keywords_ Software Testing $\cdot$ Software Testing Optimization $\cdot$
Automated Software Testing $\cdot$ Cucumber BDD $\cdot$ Gherkin BDD Testing
$\cdot$ Test Code Generation

##  1 Introduction

Smart and Molak (2023); Barus (2019) BDD is a very relevant methodology in
modern software development and testing, as it bridges the gap between
technical implementation and business requirements. Cucumber stands out as a
leading tool in this domain, facilitating the definition of application
behavior in a human-readable language Gundlach et al. (2023); Barus (2019).
Despite its widespread adoption, the Cucumber framework faces challenges in
scenario maintenance and scalability, particularly when operating within
single-threaded execution models. This paper tries to address these challenges
by proposing an approach to use scenario re-usability within the Cucumber
framework in Java, and talks towards its application to be run on Jenkins, a
leading continuous integration and delivery platform, to run the cucumber BDD,
to enable calling a scenario inside another scenario; scenario re-usability
(SR) functionality.

The main contribution of this paper is the development and workout of a method
that mostly reuses the already built functionality that allows it to execute
reusable scenario/(s) (RS) within scenario/(s). Keeping the process as a
single-threaded, and without calling cucumber as a separate process. Thus,
goes around its traditional execution limitations. This method not only
addresses efficiency concerns in single-threaded environments but also
significantly enhances the modularity and maintainability of BDD test suites.
Cucumber supports backgrounds, which are run once before every script, but
that does not solve the problem of re-usability within a scenario. With this
functionality in place, a QA tester can write reusable scenarios, and have
more access and better modularity for the testing feature set.

Listing 1 shows an example of Gherkin BDD feature file.

⬇

1@blog_management @access_control

2Feature: Multiple Site Support

3 Only blog owners can post to a blog, except administrators, who can post to
all blogs.

4

5 Background:

6 Given a global administrator named "{Admin_Name}"

7 And a blog named "{Admin_Blog}" owned by "{Admin_Name}"

8 And a customer named "{User_Name}"

9 And a blog named "{User_Blog}" owned by "{User_Name}"

10

11 @user_posting

12 Scenario: {User_Name} posts to their own blog

13 Given I am logged in as {User_Name}

14 When I try to post to "{User_Blog}"

15 Then I should see "{Success_Message}"

16

17 @cross_posting_error

18 Scenario: {User_Name} tries to post to somebody else’s blog, and fails

19 Given I am logged in as {User_Name}

20 When I try to post to "{Admin_Blog}"

21 Then I should see "{Failure_Message}"

22

23 @admin_privileges

24 Scenario: {Admin_Name} posts to a client’s blog

25 Given I am logged in as {Admin_Name}

26 When I try to post to "{User_Blog}"

27 Then I should see "{Success_Message}"

Listing 1: An example of how a gherkin .feature file looks like with sample
scenarios for testing user access.

In addition to implementing the re-usability, this paper also focuses on the
usability of VSCode’s step definition auto-complete functionality extension
Krechik (2017), to showcase its potential in easing the scenario writing and
management process. This ability to reuse scenarios is especially advantageous
for beginner QA test writers, as it provides easy access to and navigation of
step definitions, hence reducing the learning curve and improving productivity
in test development. Though JetBrains (2024) also provides similar auto-
complete functionality, it is a paid integrated development environment (IDE)
software for professional use. The paper conveys an idea towards significant
improvements in test framework development speed and execution efficiency.
These advancements are particularly beneficial for large-scale and complex
software projects, where traditional BDD practices may fall short. The
integration of these innovative methods with established BDD practices
suggests a pathway towards more effective, efficient, and sustainable test
automation strategies, especially in environments utilizing Jenkins for
continuous integration and delivery. The implementation of this project is
done in Java language, though this same seemed achievable in Cucumber for
Python and Javascript per the understanding of the author. Still, that is out
of the scope of this paper.

The main contributions of the paper are as follows:

  * •

Reusing Gherkin scenarios within scenarios in the Cucumber framework aimed at
enhancing the speed, modularity, and maintainability of test writing.

  * •

To generate dynamic ENUM types, to improve integration with VSCode auto-
complete functionality, thereby enhancing visibility for QA test script
writers and reducing the need for manual scenario file searches.

  * •

To traverse through and successfully implement BDD scenario re-usability and
to be used while running a Maven test project on Jenkins, demonstrating an
innovative approach to adapt this functionality to running with Jenkins.

  * •

To demonstrate the setup for step definition auto-complete functionality in
VSCode Microsoft Corporation (2015) with suggestions and its combination with
dynamic ENUMs, highlighting its benefits for writing BDD tests and improving
the efficiency of test development.

  * •

To present a use case of scenario re-usability in a large-scale e-commerce
company with expanded customer bases where each feature needs to be tested
under different conditions, emphasizing its effectiveness in handling similar
functionalities across different contexts.

Figure 1: Depiction of a Feature being tested with #N Scenarios using a shared
set of steps(Reusable Scenario).

##  2 Advantages of the Proposed Approach

This paper presents re-usability of scenarios within the Cucumber framework.
This improves the efficiency and flexibility of creating and maintaining
behavior-driven development (BDD) test cases and helps in streamlining the
test writing and hence the testing process.

###  2.1 Better re-usability of tests

The main advantage of this approach is greater re-usability of test cases. By
allowing one scenario to effectively call another, by allowing common test
functions to be reused across different test cases. This re-usability is
especially useful when testing similar features in different settings or
environments.

###  2.2 Faster Test Development

Integrating VSCode step definition auto-completion with this dynamic ENUM
types greatly speeds up the test writing process. This setting enables faster
test generation, making it especially useful for new QA test writers who now
have easy access to relevant step definitions while writing a test case
script.

###  2.3 Centered Test Case Maintenance

For scenarios where there occurs User Interface (UI) updates or other changes
in the functionality being tested(inside a reusable scenario), only reusable
steps need to be updated. This localized update process reduces the time and
effort required to maintain test suites, especially in dynamic development
environments where frequent changes takeplace. This ability of modularity also
lends itself to greater flexibility, allowing for easy adaptation to different
testing requirements.

###  2.4 Scaling for Large-Scale Projects

For large-scale and complex software projects, this method offers a scalable
solution. It enables efficient management and execution of extensive test
suites, ensuring consistent quality and performance across the project
lifecycle.

###  2.5 Integration with Jenkins

The paper demonstrates the application of these methodologies within Jenkins,
highlighting a seamless integration process. This integration facilitates more
efficient test automation in continuous deployment scenarios, a critical
aspect for modern software development pipelines.

##  3 Literature Review

In the realm of software development, particularly focusing on testing
methodologies, several notable studies and theses offer insights into
innovative approaches.

Khaerunnisa et al. (2023) compares Cucumber and Robot framework as BDD
automated testing tools, focusing on functionality, reliability, usability,
performance efficiency, and portability, recommending Cucumber for novice
Quality Assurance Testers (QATs) and Robot framework for more experienced QATs
due to its concise syntax and extensive keywords. Souza and Carvalho (2021)
introduces a method for testing drivers on microcontrollers, using a Device
Under Test, a double device, and a computer to emulate real external
peripherals, successfully validating the solution with different protocols.
Solís and Wang (2011) identifies key characteristics of Behaviour Driven
Development (BDD) through literature analysis and current toolkits, providing
a foundational understanding of BDD. Mello et al. (2018) reports on the
challenges of using BDD in a large public health-related BI project,
suggesting that BDD may not be appropriate in the early development stages of
BI projects due to the complex business understanding required. Pyshkin (2012)
discusses challenges in automating the generation of test classes from use
cases in narrative form, and analyzing toolkits for integrating BDD libraries
like JBehave with development environments. Raharjana et al. (2020) develops a
tool for generating BDD test case codes from scenario definitions,
facilitating automated testing for entry-level programmers. Andrade et al.
(2023) proposes the GoBeAT methodology for MAS test suite specification in the
robot soccer domain, demonstrating its effectiveness in a RoboCup case study.

Contan et al. (2017) implements an automated testing framework addressing
technical and social aspects, aiming to align client requests with the
technical area using BDD. Williams et al. (2020) uses Gherkin to capture
requirements from legislation in a Gift Aid system development case study,
demonstrating the alignment of formal and agile development. Elshandidy (2019)
introduces a behavior-driven cloud-based framework for agile product line
engineering, focusing on automated testing for managing core assets and
variations. Faragó et al. (2020) discusses the application of BDD in large
projects, suggesting a taxonomy for its successful application based on
various project aspects. Brolund (2009) demonstrates a tool for documentation
by extending the BDD approach to generate readable documents from a JUnit test
suite. O’Brien (2018) discusses using Gherkin CNL and MT for global product
information development in McAfee, aiming to integrate it into the SDLC. Schur
and Williams (2017) describes an approach for augmenting system verification
with automated testing, enhancing the human verification process. Gil et al.
(2016) adapts BDD to testing ALMA telescope calibration software, focusing on
communication between developers, testers, and scientists. Wanderley and
Silveira (2012) proposes an approach to bridge the gap between business
specialists and software designers, using a mind model specification to
transform scenario definitions into a conceptual model. Bünder and Kuchen
(2019a) presents a model-driven approach for behavior-driven GUI testing,
transforming BDD-like requirements and GUI descriptions into executable test
cases. Zaeske and Durak (2020) discusses the use of BDD, particularly Gherkin,
and RSpec, in DevOps for dependable Cyber-Physical Systems.

Bünder and Kuchen (2019b) explores behavior-driven graphical user interface
testing, introducing a specification language for automatically executable
test cases from BDD-like feature descriptions. Wolde and Boltana (2021)
introduces a behavior-driven Quality First Agile Testing approach for cloud
service, focusing on a black box approach to address the quality engineering
challenges in cloud services. Li et al. (2017) proposes a Gherkin syntax
extension for parameterizing network switch configurations in BDD test
specifications, effectively reducing the lines needed for configuration
descriptions. Wolde and Boltana (2020) discusses behavior-driven model-based
re-engineering for cloud testing, emphasizing the design and validation of
test instances with GraphWalker models and domain-specific languages. Tuglular
and Coşkun (2021) proposes an approach for behavior-driven development of
software product lines, focusing on automatically composing and executing test
suites according to selected features.

Fung et al. (2021) introduces the Accountability Driven Development framework
for ML systems, focusing on recording accountability information and
transforming requirements into specific scenarios. Matula and Zácek (2018a)
proposes ontological syntax highlighting to enhance the readability and
understandability of the code. Sarinho (2019) presents a paper-based game for
teaching BDD concepts in a practical, competitive, and fun way. Blank (2017)
discusses combining STPA and BDD for safety analysis and verification in agile
development.

Almeida et al. (2016) introduces SS-BDD, a framework for building and running
spreadsheet test scenarios using BDD, achieving high fault-detection
effectiveness. Schoeneman and Liu (2013) develops a method to derive unit
tests automatically by analyzing human-written specifications for
preconditions and post-conditions. Bussenot et al. (2018) discusses
orchestrating domain-specific test languages with a BDD approach in the
context of airplane systems testing. Elshandidy et al. (2021) examines
behavior-driven requirements engineering in agile product line engineering,
focusing on establishing and managing agile product lines. Alhaj et al. (2017)
integrates BDD with HW/SW Co-design in a renewable energy project, describing
behavior as executable user stories. Ali et al. (2019) presents BDD
methodology and Cucumber framework for automating regression testing of
Android apps, particularly testing the broadcast mechanism in Catrobat. Matula
and Zácek (2018b) discusses re-engineering legacy systems with a transaction
model, focusing on updating older software systems. Diepenbeck et al. (2018)
proposes extending BDD for hardware design, focusing on verification and
increasing productivity in hardware testing. Gutiérrez et al. (2017) models
Gherkin scenarios using UML, aiming to enhance scenario definition and
visualization in BDD. Lopes (2012) evaluates BDD in software engineering,
suggesting improvements to the process based on a case study. Yen et al.
(2021) reports on adopting BDD for an IoT system, using problem frames to
define specifications at different system levels. So (2017) presents a
framework for intuitive software test system design, focusing on acceptance
tests and status reporting for business stakeholders.Matula and Hunka (2018)
specifies software using DEMO transaction patterns and BDD, integrating them
into initial BDD scenarios for enterprise information system development.Lima
et al. (2021) proposes using BDD for acceptance testing in microservices
architecture, building test scenarios for API REST services to match end-user
needs. The paper focuses on a payroll system case study, assessing the Behave
BDD tool for automating acceptance tests and highlighting its effectiveness in
ensuring that the system meets user requirements.

Phansani (2020) explores the integration of Test-Driven Development (TDD) and
Behavior-Driven Development (BDD) in GUI testing. The thesis proposes a novel
approach using GUI prototypes for early testing, utilizing tools like
JustInMind for capturing and replaying test cases. This method aims to enhance
software quality from the design phase and align developer and customer
perceptions, reducing the need for extensive test code writing.

Khorram et al. (2020) discuss the challenges and opportunities in low-code
testing in their paper. They analyze testing components of commercial Low-Code
Development Platforms (LCDP) and propose a feature list for low-code testing,
addressing the role of the citizen developer, the need for high-level test
automation, and cloud testing.

Irshad (2018) assesses the re-usability in automated acceptance tests. It
explores how automated acceptance tests, closely related to software
requirements, can be reused by identifying characteristics through systematic
literature reviews and case studies. The thesis proposes methods to measure
the reuse potential of BDD test cases and a method to calculate cost avoidance
through reuse, finding that automated acceptance tests are indeed reusable and
their reuse potential can be quantified.

The study by Rahman and Gao (2015) is particularly relevant and the closest to
the work in terms of other literature. It presents a reusable automated
acceptance testing architecture for microservices in Behavior-Driven
Development. While focusing on re-usability, their work revolves around using
reusable step definitions, but this needs new step definitions to be written
in a programming language. This paper, in contrast, aims to simplify and
combine step definitions, making both the scenarios and the step definitions
more accessible and broadly applicable. The paper introduces calling scenarios
as a function, mapped to a step definition, following are the two main step
definitions for the scope of this paper.

Though a short part of the literature review is relevant to this work, it does
lay the foundation for presenting the work better. Though this work still
builds on the insights and challenges identified in these studies, it ventures
into the practical application of the presented enhanced approach to automated
acceptance testing.

##  4 Implementation

In this section the paper dives into the practicalities of developing and
applying our proposed methodologies, demonstrating their effectiveness and
efficiency in real-world software development scenarios.

###  4.1 Reusable Scenario Step Definitions

  * •

I Call Feature File FolderFilesEnumeration(Objects, 1 for each):

    * –

Designed for scenarios requiring access to feature files from multiple
folders.

    * –

Useful for directories within the parent "features" directory, especially
those starting with "reusable."

    * –

Involves creating a copy of each step definition when a change is detected in
folder structure of reusable features.

    * –

Allows dynamic access to a range of feature files based on folder naming
conventions.

    * –

Alternative raw string usage: I call feature file "folderName"
"fileNameInFolder".

  * •

I Call Feature File FixedFolderFilesEnumeration

    * –

A simpler and more straightforward step definition.

    * –

Relies on a fixed directory path specified within a configuration file.

    * –

Focuses on facilitating the calling of scenarios from a predetermined
location.

    * –

Enhances ease of use and efficiency for routine or standard test scenarios.

    * –

Alternative raw string usage: I call feature file "fileName".

The second step definition is a subset of the first one. It offers a
simplified approach by relying on a fixed directory path specified in the
configuration file. This subset approach still maintains the versatility of
the first definition but streamlines the process for more routine scenarios.

These step definitions are integral to an approach designed to enhance the
auto-complete functionality in development tools like VSCode. The first step
definition offers flexibility and access to multiple folders, while the second
provides simplicity and speed through its reliance on a fixed directory. The
implementation includes code that dynamically updates the step definitions in
the Java file, ensuring seamless integration and facilitating more effective
test case generation and execution.

###  4.2 Definition of Dynamic ENUMs for Step Auto-Complete in VSCode

The dynamic ENUM generation process is designed to facilitate step
autocompletion in Visual Studio Code, particularly for Cucumber BDD scenarios.
The process targets feature files located in directories named “reusable” or
“common” within the “/features/” folder. The algorithm generates an ENUM class
for each such directory, with ENUM values representing the concatenation of
folder and file names.

Algorithm 1 Dynamic ENUM Generation

1:$featuresPath\leftarrow``./features/^{\prime\prime}$

2:$targetDirs\leftarrow[``reusable^{\prime\prime},``common^{\prime\prime}]$

3:procedure GenerateEnums

4: $directories\leftarrow$ list all subdirectories in $featuresPath$

5: for each $dir$ in $directories$ do

6: for each $targetDir$ in $targetDirs$ do

7: if $dir$ name contains $targetDir$ then

8: GenerateEnumForFolder($dir$)

9: end if

10: end for

11: end for

12:end procedure

13:procedure GenerateEnumForFolder($folder$)

14: $enumName\leftarrow$ convert $folder$ name to Enum format

15: $featureFiles\leftarrow$ list all .feature files in $folder$

16: Print “public enum $enumName$ {”

17: for each $file$ in $featureFiles$ do

18: $enumConstant\leftarrow$ uppercase($folder\\_name$ \+ “_” + $file$)

19: Print $enumConstant$

20: end for

21: Print “};”

22:end procedure

This Algorithm 1. outlines the steps for dynamically generating ENUM classes
for Java, designed to work with the Cucumber Full Language Support extension
[Krechik (2017)] in Visual Studio Code. The generated ENUMs will facilitate
the autocompletion of Gherkin steps by mapping the folder and file structure
within the specified feature file directories.

Algorithm 2 Generate Step Definitions

1:procedure GenerateStepDefinitions

2: $featuresPath\leftarrow./features/^{\prime\prime}$

3: $targetDirs\leftarrow[reusable^{\prime\prime},common^{\prime\prime}]$

4: $directories\leftarrow$ list all subdirectories in $featuresPath$

5: for each $dir$ in $directories$ do

6: for each $targetDir$ in $targetDirs$ do

7: if $dir$ name contains $targetDir$ then

8: $enumName\leftarrow$ convert $dir$ name to Enum format

9: $featureFiles\leftarrow$ list all .feature files in $dir$

10: for each $file$ in $featureFiles$ do

11: $enumConstant\leftarrow$ uppercase($dir+^{\prime}\\_^{\prime}+$file)

12: end for

13: CreateStepDefinition($enumName$, $enumConstant$)

14: end if

15: end for

16: end for

17:end procedure

18:procedure CreateStepDefinition($enumName$, $enumConstant$)

19: Print annotation @And("I call feature file $enumConstant$")

20: Print void callFeature + $enumName$ \+ ObjectName($enumName$ enumObject)

21: Print ’{’

22: CallReusableScenario($enumName$, $enumConstant$) using Cucumber static
object

23: Print ’};’

24:end procedure

This Algorithm 2 iterates through the directories and their respective feature
files, generating a step definition for each enum constant. The
CreateStepDefinition procedure dynamically prints the step definition method
with the necessary logic placeholder for calling the associated feature file.
This approach will create a comprehensive set of step definitions
corresponding to the enumerated feature files.

###  4.3 Gherkin Step Auto-Complete Functionality in VSCode

The Krechik (2017) "Cucumber Full Language Support" extension for VSCode
significantly enhances the development experience for those working with
Cucumber (Gherkin) language, a popular tool for Behavior-Driven Development
(BDD). This section of your paper aims to detail the usage, integration, and
potential future applications of this VS Code extension.

####  4.3.1 Installation and Setup

Open Your Application in VS Code: Start by opening your application project in
VS Code where you intend to use Cucumber for BDD.

Install the Extension: Search for the ’cucumberauto-complete’ extension in the
VS Code Extensions Marketplace and install it. This extension is designed to
add comprehensive language support for Cucumber.

In your project’s root directory, create a .vscode folder and a settings.json
file within it (if they don’t already exist). You can do this manually or by
using the command mkdir .vscode && touch .vscode/settings.json in your
terminal.

Add Extension Settings to settings.json: Customize your Cucumber environment
by adding necessary settings to the settings.json file. These settings can
include paths to your feature files, regular expressions for step definitions,
and language configurations. An example of how a .vscode/settings.json for the
extension in java:

⬇

1{

2 "cucumberauto-complete.stepsInvariants": true,

3 "cucumberauto-complete.steps": [

4 "**/*.java"

5 ],

6 "cucumberauto-complete.syncfeatures": "**/*.feature",

7 "cucumberauto-complete.customParameters": [

8 {

9 "parameter": "{string}",

10 "value": "\".*\""

11 },

12 {

13 "parameter": "{int}",

14 "value": ".*"

15 },

16 ],

17 "cucumberauto-complete.skipDocStringsFormat": true,

18 "cucumberauto-complete.smartSnippets": true,

19 "cucumberauto-complete.onTypeFormat": true,

20 "editor.quickSuggestions": {

21 "comments": true,

22 "strings": true,

23 "other": true

24 },

25 "cucumberauto-complete.gherkinDefinitionPart":
"(Given|When|Then|But|And)\\\\(",

26}

Listing 2: Settings for the VSCode step definition auto-complete plugin.

The detailed description of attributes from Listing 2 is present in Krechik
(2017).

Reload the Application: To apply the changes and activate the extension,
reload your application in VS Code. Utilizing Extension Features:

Syntax Highlighting and Snippets: The extension provides syntax highlighting
for better readability and pre-defined code snippets for common Gherkin
expressions.

Auto-Parsing and Autocompletion: Steps defined in your feature files are
automatically parsed and made available for autocompletion, streamlining the
coding process.

Validation and Definitions Support: The extension provides on-type validation
for all steps and supports definitions, ensuring that your Gherkin syntax is
both accurate and efficient.

Document Formatting: Includes formatting support for Gherkin documents, such
as tables, making your feature files more organized and readable.

Multi-Language Support: It supports various programming languages (like
JavaScript, TypeScript, Ruby, Kotlin, and Java) and multiple human languages,
enhancing its utility in diverse development environments.

Future Use Cases and Potential Enhancements

Advanced AI-Driven Autocompletion: Future versions could incorporate AI to
provide more intelligent and context-aware autocompletion suggestions based on
the specific usage patterns and domain language of the project.

Integrated Testing and Reporting: Integration with testing frameworks and
reporting tools directly within VS Code could provide real-time feedback and
detailed test reports, enhancing the TDD/BDD workflow.

Collaboration Features: Future enhancements might include real-time
collaboration tools for teams working on BDD, including shared editing and
live commenting within feature files.

Enhanced Refactoring Tools: Enhanced tools for refactoring steps and features,
including automatic updates of associated step definitions and feature files
when changes are made, could significantly streamline the development process.

Customizable Workflow Automation: Introducing features that allow teams to
automate repetitive tasks in the BDD process, customized to their workflow,
can further increase productivity.

Integration with Version Control Systems: Better integration with version
control systems like Git for managing changes in feature files and associated
step definitions could be a valuable addition.

Learning and Suggestion Mechanism: The extension could learn from user
corrections and preferences over time, offering more personalized and accurate
suggestions and corrections.

In summary, the Cucumber Full Language Support extension for VS Code is a
powerful tool that enhances the BDD process by providing comprehensive
language support, autocompletion, validation, and formatting for Gherkin. As
BDD continues to grow in popularity, extensions like this will become
increasingly vital for efficient and effective software development workflows.

###  4.4 Running Reusable Steps in Jenkins

For local test execution in VSCode, especially to utilize JUnit test pane in
VSCode, the following code structure is typically employed:

⬇

1@RunWith(Cucumber.class)

2@CucumberOptions(features = {

3 "PathToFeatureFiles" }, glue = {

4 "PathToStepDefinitionsJavaDirectory" }, plugin = { "html:target/cucumber-
html-report",

5 "json:target/cucumber.json",

6 "pretty:target/cucumber-pretty.txt",

7 "junit:target/test-results.xml" }, dryRun = false, tags = { "@ScenarioTag"
})

8public class TestRunner {

9

10 @BeforeClass

11 public static void setup() throws Exception {

12 // Method contents omitted

13 }

14

15 @AfterClass

16 public static void teardown() {

17 // Method contents omitted

18 }

19}

Listing 3: Sample Java code for JUnitRunner.java file mentioned later in the
paper.

It is important to note that each value within the @Annotation must be a fixed
string for the Java Virtual Machine (JVM) to execute it correctly.

In a continuous integration environment like Jenkins, the test execution is
configured as a Maven project and is executed generally using the following
command:

⬇

1test -Dcucumber.options="PathToFeatureFiles –tags @ScenarioTag" -Denv=\$env

Listing 4: Command to run Maven test on Jenkins(cmd prompt command)

In this setup, the @ScenarioTag refers to a scenario or multiple scenarios
located within the PathToFeatureFiles, particularly those containing reusable
steps.

A challenge arises when there is a need to temporarily set global
cucumber.options, which is not permissible in Cucumber. This issue becomes
evident particularly when calling the scenario function again, resulting in
the re-execution of the @ScenarioTag step from the beginning.

To address this, an alternative solution that does not rely on global
cucumber.options is required. Considering that each Jenkins job has a specific
purpose and clones code from the master branch in a Git repository, the use of
@CucumberOptions was dynamically updated. This approach involves replacing a
placeholder with a variable specified in the Jenkins job. Consequently, the
command for test execution can be run without explicitly setting
cucumber.options that set the global values for Cucumber variables. In a
Jenkins continuous integration setup, a Bash script is commonly used to
prepare the testing environment before running the Maven test command. The
following Bash commands demonstrate how scripts are executed within Jenkins:

⬇

1chmod +x jenkins.sh

2./jenkins.sh "$PathToFeatureFile" "$ScenarioTag"

Listing 5: Bash code to update JUnitRunner.java file annotation.

The "jenkins.sh" script is designed to modify the placeholders in the
@CucumberOptions annotation in the main JUnit runner file. The contents of
this script are tailored to suit the specific needs of the testing environment
and may include various shell commands and scripting logic. The code for
’run.sh’ file is as follows:

⬇

1# Get input parameters

2featurePath=$1

3tags=$2

4

5TestFilePath=JUnitRunner.java

6

7sed -i "s|\"$PathToFeatureFile \"|\"${featurePath}\"|g" $TestFilePath

8sed -i "s|\"@ScenarioTag\"|\"${tags}\"|g" $TestFilePath

Listing 6: Contents of the "jenkins.sh" file.

This approach allows for dynamic configuration of test parameters,
facilitating flexibility and adaptability in automated testing scenarios.

##  5 Usecase

###  5.1 E-commerce Website

In the dynamic environment of e-commerce, efficient and robust testing
methodologies are essential for ensuring seamless user experiences, especially
in critical functionalities like item search and checkout processes. This
section delves into the practical application of reusable scenarios in the
context of an e-commerce website, demonstrating how the enhanced Behavioral
Driven Development (BDD) methodology can streamline and optimize the testing
process.

The primary advantage of using reusable scenarios in an e-commerce setting is
the ability to define a set of common steps that can be applied across
multiple test cases. This approach not only reduces redundancy but also
ensures consistency and ease of maintenance. Particularly for e-commerce
platforms, where numerous items share similar pathways through the site’s
functionality, the ability to reuse test scenarios becomes invaluable.

Consider the following example of a reusable step in Gherkin syntax:

⬇

1@FeatureX @FeatureX_Test1

2Scenario: Testing {feature}(common) for {first} item

3 Given I start the testcase

4 When I go to the item search page

5 Then I search for {first} item

6 And I click on {first} item

7 And I call feature file enumConstant [common]

8 And I do any step left specific to {first} item...

9 Then Test Ends

10

11@FeatureX @FeatureX_TestN

12Scenario: Testing {feature}(common) for {Nth} item

13 Given I start the testcase Nth

14 When I go to the item search page

15 Then I search for {Nth} item

16 And I click on {Nth} item

17 And I call feature file enumConstant [common]

18 And I do any step left specific to {Nth} item...

19 Then Test Ends

Listing 7: Use of reusable scenario in Gherkin syntax for testing a Feature in
various ways for an e-commerce platform. This example illustrates the usage of
a common/reusable scenario for different items with reusable/unreusable steps
for each.

In this example, the ‘feature‘ placeholder represents a common functionality
being tested, such as the checkout process. The ‘first item‘ and ‘Nth item‘
are placeholders for specific items on the e-commerce platform. The
‘enumConstant [common]‘ denotes the reusable scenario, which includes a series
of steps common to all items being tested. This structure allows for the
testing of multiple items with minimal scenario duplication, enhancing
efficiency and reducing the potential for errors in test script creation.

In summary, the use of reusable scenarios in an e-commerce website context
exemplifies the efficiency and effectiveness of the enhanced BDD methodology.
This approach not only streamlines the testing process but also contributes to
maintaining high standards of quality and reliability in a highly competitive
digital marketplace.

##  6 Primary Limitation of the Approach: Complexity Management

While the proposed approach offers substantial benefits, it does introduce a
level of complexity that requires careful management:

###  6.1 Complexity in Integration and Maintenance

The integration of various components such as Cucumber, Jenkins, and VSCode’s
auto-complete functionality, requires a comprehensive understanding of these
systems. This complexity, however, can be effectively managed through proper
documentation and team training.

###  6.2 Balancing Sophistication with Usability

Ensuring that the advanced capabilities of the approach do not compromise
usability is crucial. By offering detailed guides and support, teams can
leverage the full potential of the methodology without being overwhelmed.

###  6.3 Facilitating Smooth Transition for Teams

For teams transitioning from traditional BDD practices, the shift to this more
advanced methodology can be made smoother through structured training programs
and gradual implementation strategies.

###  6.4 Maintaining Scalability and Clarity

As the framework expands, maintaining its scalability and clarity will be
essential. Regular reviews and updates of the test suites can help manage this
complexity, ensuring the framework remains effective for large-scale projects.

##  7 Conclusion

This study presents a significant advancement in the field of Behavioral
Driven Development (BDD), particularly in the context of scenario re-usability
within the Cucumber framework. The introduction of methods allowing for the
execution of reusable scenarios within a single-threaded process marks a
notable improvement in the efficiency and modularity of BDD test suites. The
implementation of these methodologies in Java, with potential applicability in
other programming languages, demonstrates versatility and broad scope.

The integration of VSCode’s step definition auto-complete functionality
emerges as a key factor in simplifying the scenario writing process. This
feature proves especially beneficial for new QA test writers, facilitating an
easier and more efficient workflow. The study’s exploration into the
application of these methodologies within Jenkins, a prominent continuous
integration and delivery platform, showcases a novel approach to adapting
Cucumber’s functionalities to various testing environments.

Empirical research and practical applications indicate substantial
improvements in test development speed and execution efficiency. These
enhancements are crucial for large-scale and complex software projects, where
conventional BDD practices may be less effective. Overall, the integration of
these innovative methods with traditional BDD practices points towards a
future of more effective, efficient, and sustainable test automation
strategies. The emphasis on scenario re-usability within the Cucumber
framework is particularly promising, suggesting new directions for research
and development in the field.

##  8 Conflict of Interest and Permissions

Conflict of Interest: The foundational ideas for this research originated from
discussions with Technology Management at Xpressdocs. While the initial
concept was developed in a professional setting, some ideation and development
for this paper occurred independently. The framework, with certain
modifications, is employed at Xpressdocs for Cucumber BDD testing. The author
have ensured that no proprietary or confidential information from Xpressdocs
is included in this paper. This measure was taken to avoid any potential
conflict of interest and to maintain the integrity of the research. Despite
the professional association with Xpressdocs, there has been no commercial or
financial influence that affected the outcomes of this paper.

Permissions and Ethical Compliance: The author confirms that all necessary
permissions were obtained from company officials at Xpressdocs prior to the
publication of this paper. This was done to ensure adherence to and respect
for proprietary information. The research presented here adheres to the
ethical guidelines and policies set forth by my institution and aligns with
the agreements made with Xpressdocs. Obtaining these permissions highlights my
commitment to ethical research practices and ensures transparency in the
dissemination of my findings. The author affirms that this research is
conducted and shared with the utmost respect for intellectual property and
organizational confidentiality.

## References

  * Smart and Molak [2023] John Ferguson Smart and Jan Molak.  _BDD in Action: Behavior-driven development for the whole software lifecycle_.  Simon and Schuster, 2023.
  * Barus [2019] Arlinta Christy Barus.  The implementation of atdd and bdd from testing perspectives.  _Journal of Physics: Conference Series_ , 1175(1):012112, March 2019.  doi:10.1088/1742-6596/1175/1/012112.
  * Gundlach et al. [2023] Sven Gundlach, Reiner Jung, and Wilhelm Hasselbring.  Facilitating test-driven development via domain-specific languages in computational science software engineering.  _Research Square preprint deposition service_ , December 2023.  doi:10.21203/rs.3.rs-3753364/v1.
  * Krechik [2017] Alexander Krechik.  Cucumber (Gherkin) Full Support.  Visual Studio Code Marketplace, January 2017.  URL https://marketplace.visualstudio.com/items?itemName=alexkrechik.cucumberautocomplete.  VSCode Cucumber (Gherkin) Full Language Support + Formatting + Autocomplete.
  * JetBrains [2024] JetBrains.  IntelliJ IDEA, 2024.  URL https://www.jetbrains.com/idea/.  Integrated Development Environment.
  * Microsoft Corporation [2015] Microsoft Corporation.  Visual studio code.  Computer program, 2015.  URL https://code.visualstudio.com/.
  * Khaerunnisa et al. [2023] Khaerunnisa Khaerunnisa, N. Selviandro, and Rosa Reska Riskiana.  Comparative study of robot framework and cucumber as bdd automated testing tools.  _Ultimatics : Jurnal Teknik Informatika_ , null:null, 2023.  doi:10.31937/ti.v15i1.3228.  URL https://www.semanticscholar.org/paper/fe4303d6efdf23aa137b4c5883d14efb3c8c03ed.
  * Souza and Carvalho [2021] S. C. M. Souza and R. A. Carvalho.  Automated driver testing for small footprint embedded systems.  _ArXiv_ , abs/2105.01451:null, 2021.  URL https://www.semanticscholar.org/paper/c419fdc3be9d17bcfb116fb81c16b463be675400.
  * Solís and Wang [2011] Carlos Solís and Xiaofeng Wang.  A study of the characteristics of behaviour driven development.  _2011 37th EUROMICRO Conference on Software Engineering and Advanced Applications_ , null:383–387, 2011.  doi:10.1109/SEAA.2011.76.  URL https://www.semanticscholar.org/paper/24e9bb0157354cba8a9e6291b6faf906143db86e.
  * Mello et al. [2018] Patrícia Mello, Pablo Ximenes, Rousiany Lemos, Ana Luíza Bessa, M. Cortés, and C. Rocha.  On the applicability of bdd in a business intelligence project: experience report.  _Proceedings of the XVII Brazilian Symposium on Software Quality_ , null:null, 2018.  doi:10.1145/3275245.3275276.  URL https://www.semanticscholar.org/paper/ba31d754b4827cb1c450176a00e4b194397fa5d3.
  * Pyshkin [2012] Evgeny Pyshkin.  On requirements for acceptance testing automation tools in behavior driven software development.  _Central and Eastern European Software Engineering Conference Russia_ , 2012.  URL https://www.semanticscholar.org/paper/16c321706eafe4fe42c3ada0bf36e3249fde8d16.
  * Raharjana et al. [2020] I. K. Raharjana, Fadel Harris, and Army Justitia.  Tool for generating behavior-driven development test-cases.  _Journal of Information Systems Engineering and Business Intelligence_ , null:null, 2020.  doi:10.20473/jisebi.6.1.27-36.  URL https://www.semanticscholar.org/paper/7d274e0a4d03c1f2bf1f16be27c79f796c897627.
  * Andrade et al. [2023] Renato Andrade, Ana Patricia Fontes Magalhaes Mascarenhas, and Marco Antonio Simões.  Gobeat: Towards a methodology to support mas test case definition.  _2023 Latin American Robotics Symposium (LARS), 2023 Brazilian Symposium on Robotics (SBR), and 2023 Workshop on Robotics in Education (WRE)_ , null:218–223, 2023.  doi:10.1109/LARS/SBR/WRE59448.2023.10332953.  URL https://www.semanticscholar.org/paper/1a48edfd84a82bb0258bceca7a249edf4441e853.
  * Contan et al. [2017] Andrei Contan, L. Miclea, and C. Dehelean.  Automated testing framework development based on social interaction and communication principles.  _2017 14th International Conference on Engineering of Modern Electric Systems (EMES)_ , null:136–139, 2017.  doi:10.1109/EMES.2017.7980399.  URL https://www.semanticscholar.org/paper/9e0a7cc58474796a1f4ead6a78396648b79a4c68.
  * Williams et al. [2020] David M. Williams, Salaheddin Darwish, Steve Schneider, and D. R. Michael.  Legislation-driven development of a gift aid system using event-b.  _Formal Aspects of Computing_ , pages 1–23, 2020.  doi:10.1007/s00165-020-00512-5.  URL https://www.semanticscholar.org/paper/af85f3b6a34d3f0ee73479e02dede4694690a144.
  * Elshandidy [2019] H. Elshandidy.  Behaviour-driven requirements engineering for agile product line engineering.  _2019 IEEE 27th International Requirements Engineering Conference (RE)_ , null:434–439, 2019.  doi:10.1109/RE.2019.00058.  URL https://www.semanticscholar.org/paper/4d32be6f8f92dea7c7f712571b7897e478baba08.
  * Faragó et al. [2020] David Faragó, Mario Friske, and Dehla Sokenou.  Towards a taxonomy for applying behavior-driven development (bdd).  _Softwaretechnik-Trends_ , 40:3–7, 2020.  URL https://www.semanticscholar.org/paper/4a3fc04e4de0e146dd1c19801b64edd0c74aca6d.
  * Brolund [2009] Daniel Brolund.  Documentation by example.  _Agile Processes in Software Engineering and Extreme Programming_ , 2009.  doi:10.1007/978-3-642-01853-4_54.  URL https://www.semanticscholar.org/paper/3491b8ccf18bbecc2275abbc3e552713518235bf.
  * O’Brien [2018] Morgan O’Brien.  Toward leveraging gherkin controlled natural language and machine translation for global product information development.  _Proceedings of the 21st Annual Conference of the European Association for Machine Translation_ , 2018.  URL https://www.semanticscholar.org/paper/70f44b4afd865fc892979b9d30b1571426fb1ec5.
  * Schur and Williams [2017] Amir Schur and Mike Williams.  Augmented system verification using automated testing.  _Advances in Human Factors and Systems Interaction_ , 2017.  doi:10.1007/978-3-319-60366-7_7.  URL https://www.semanticscholar.org/paper/cf217440a8a5c0466a991fa7e01f96f78339eb07.
  * Gil et al. [2016] J. P. Gil, Mario Garcés, D. Broguiere, and T. Shen.  Behavior driven testing in alma telescope calibration software.  _Proceedings of the SPIE_ , 2016.  doi:10.1117/12.2232197.  URL https://www.semanticscholar.org/paper/bdc69e4ed114b64d03455d2cb18d6bfbfcda841f.
  * Wanderley and Silveira [2012] Fernando Wanderley and D. S. Silveira.  A framework to diminish the gap between the business specialist and the software designer.  _2012 Eighth International Conference on the Quality of Information and Communications Technology_ , pages 199–204, 2012.  doi:10.1109/QUATIC.2012.9.  URL https://www.semanticscholar.org/paper/6734f4ac6614dcf7b844fd497b761088038cc614.
  * Bünder and Kuchen [2019a] H. Bünder and H. Kuchen.  A model-driven approach for behavior-driven gui testing.  _Proceedings of the 34th ACM/SIGAPP Symposium on Applied Computing_ , null:null, 2019a.  doi:10.1145/3297280.3297450.  URL https://www.semanticscholar.org/paper/4d398cdeea57a363b0daffd794b83c0b55488a7f.
  * Zaeske and Durak [2020] Wanja Zaeske and Umut Durak.  Leveraging semi-formal approaches for depdevops.  _Computer Safety, Reliability, and Security. SAFECOMP 2020 Workshops_ , 2020.  doi:10.1007/978-3-030-55583-2_16.  URL https://www.semanticscholar.org/paper/62b25c02109ff3c3ab2d00347e6365bebc3aaa64.
  * Bünder and Kuchen [2019b] H. Bünder and H. Kuchen.  Towards behavior-driven graphical user interface testing.  _ACM SIGAPP Applied Computing Review_ , null:null, 2019b.  doi:10.1145/3357385.3357386.  URL https://www.semanticscholar.org/paper/7fb3d8d0dab1fbd1a414d9d1e3f957b83b4780b1.
  * Wolde and Boltana [2021] Behailu Getachew Wolde and Abiot Sinamo Boltana.  Behavior-driven quality first agile testing for cloud service.  _Software Engineering_ , null:null, 2021.  doi:10.11648/J.SE.20210901.12.  URL https://www.semanticscholar.org/paper/165c0b66eb56f96ef51dafe3a524ffcfec56e88b.
  * Li et al. [2017] Tianyao Li, S. Tsubota, and Koji Hirono.  Gherkin syntax extension for parameterization of network switch configurations in test specification.  _2017 IEEE International Symposium on Software Reliability Engineering Workshops (ISSREW)_ , null:12–14, 2017.  doi:10.1109/ISSREW.2017.30.  URL https://www.semanticscholar.org/paper/baa3b7b4fbc303bc856f545605ddafdc838d6fed.
  * Wolde and Boltana [2020] Behailu Getachew Wolde and Abiot Sinamo Boltana.  Behavior-driven re-engineering for testing the cloud.  _2020 Seventh International Conference on Software Defined Systems (SDS)_ , null:75–82, 2020.  doi:10.1109/SDS49854.2020.9143910.  URL https://www.semanticscholar.org/paper/c3ae1618941217291fbc5c74088c105bdeca0cfd.
  * Tuglular and Coşkun [2021] Tugkan Tuglular and D. Coşkun.  Behavior-driven development of software product lines.  _2021 8th International Conference on Dependable Systems and Their Applications (DSA)_ , null:230–239, 2021.  doi:10.1109/DSA52907.2021.00035.  URL https://www.semanticscholar.org/paper/af58159de3ec0a92295deb59a0772a0ad1ed31da.
  * Fung et al. [2021] Chiu Pang Fung, Wei Pang, Iman Naja, Milan Markovic, Peter, and Edwards.  Towards accountability driven development for machine learning systems.  _Proceedings of the SICSA eXplainable Artifical Intelligence Workshop 2021_ , 2021.  URL https://www.semanticscholar.org/paper/5bb306369ae7ea2ffac25694b0f49ad3edc7f024.
  * Matula and Zácek [2018a] J. Matula and J. Zácek.  Ontological syntax highlighting.  _American Institute of Physics_ , 2018a.  doi:10.1063/1.5043708.  URL https://www.semanticscholar.org/paper/1de71801193ae87cf3710fb7d7b3ca1bea3156fb.
  * Sarinho [2019] V. T. Sarinho.  "bdd assemble!": A paper-based game proposal for behavior driven development design learning.  _Entertainment Computing and Serious Games_ , 2019.  doi:10.1007/978-3-030-34644-7_41.  URL https://www.semanticscholar.org/paper/03fd3e6c4e37142e1134ff3bc3b495e45070cf69.
  * Blank [2017] Intentionally Blank.  Combining stpa and bdd for safety analysis and verification in agile development: A controlled experiment.  _Agile Processes in Software Engineering and Extreme Programming_ , 2017.  doi:10.5281/zenodo.846975.  URL https://www.semanticscholar.org/paper/6630586795fe4cf79e176db73051c145b916b13f.
  * Almeida et al. [2016] Lara Almeida, Elder Cirilo, and E. Barbosa.  Ss-bdd: Automated acceptance testing for spreadsheets.  _Proceedings of the 1st Brazilian Symposium on Systematic and Automated Software Testing_ , null:null, 2016.  doi:10.1145/2993288.2993296.  URL https://www.semanticscholar.org/paper/03963c3785edda704d1c2ad4eb1355f485dcc901.
  * Schoeneman and Liu [2013] Larry Schoeneman and Jiang B. Liu.  Integrating behavior driven development and programming by contract.  _Computational Science and Its Applications – ICCSA_ , 2013.  doi:10.1007/978-3-642-39640-3_43.  URL https://www.semanticscholar.org/paper/6e86ba5300beae97d401014ece72f9a0730e2348.
  * Bussenot et al. [2018] Robin Bussenot, Hervé Leblanc, and C. Percebois.  Orchestration of domain specific test languages with a behavior driven development approach.  _2018 13th Annual Conference on System of Systems Engineering (SoSE)_ , null:431–437, 2018.  doi:10.1109/SYSOSE.2018.8428788.  URL https://www.semanticscholar.org/paper/18f3b383f0b7b3aa544601fd0fd3d48a1226eafe.
  * Elshandidy et al. [2021] H. Elshandidy, Sherif A. Mazen, E. Hassanein, and Eman S. Nasr.  Using behaviour-driven requirements engineering for establishing and managing agile product lines.  _International Journal of Advanced Computer Science and Applications_ , 12:null, 2021.  doi:10.14569/IJACSA.2021.0120274.  URL https://www.semanticscholar.org/paper/d2e6791259ab99f3e50b32d6836fa94e481ec401.
  * Alhaj et al. [2017] Mohammad Alhaj, Gilbert Arbez, and L. Peyton.  Using behaviour-driven development with hardware-software co-design for autonomous load management.  _2017 8th International Conference on Information and Communication Systems (ICICS)_ , null:46–51, 2017.  doi:10.1109/IACS.2017.7921944.  URL https://www.semanticscholar.org/paper/5903302cb14b16af23ce0bd0d92da83d3626a9b8.
  * Ali et al. [2019] Zulfiqar Ali, Aiman M. Ayyal Awwad, and W. Slany.  Using executable specification and regression testing for broadcast mechanism of visual programming language on smartphones.  _Int. J. Interact. Mob. Technol._ , 13:50–65, 2019.  doi:10.3991/ijim.v13i02.9851.  URL https://www.semanticscholar.org/paper/ad81a9174a39be3583d8ff66db22574b28182695.
  * Matula and Zácek [2018b] J. Matula and J. Zácek.  Reengineering legacy systems with transaction model.  _American Institute of Physics_ , 2018b.  doi:10.1063/1.5079079.  URL https://www.semanticscholar.org/paper/d1232e19dd4c147dd10d0dea3add1554cf687248.
  * Diepenbeck et al. [2018] Melanie Diepenbeck, U. Kühne, Mathias Soeken, Daniel Große, and R. Drechsler.  Behaviour driven development for hardware design.  _IPSJ Trans. Syst. LSI Des. Methodol._ , 11:29–45, 2018.  doi:10.2197/ipsjtsldm.11.29.  URL https://www.semanticscholar.org/paper/2f5548dc349e4c5389697437dbc283e8e2b9d782.
  * Gutiérrez et al. [2017] J. Gutiérrez, Isabel M. Ramos, M. Risoto, Carlos Arévalo, J. M. Sánchez-Begínes, and D. Lizcano.  Modelling gherkin scenarios using uml.  _AIS ISD_ , 2017.  URL https://www.semanticscholar.org/paper/b13c9b7240d8d4299022da550426d6b680fc3f45.
  * Lopes [2012] J. Lopes.  Evaluation of behavior-driven development, 2012.  URL https://www.semanticscholar.org/paper/9716f1d1eafef1069bc869dd393db31d8810610f.
  * Yen et al. [2021] Yi-Chun Yen, Bing-Yun Wang, Xin-Zhe Zhong, Wei-Yi Chiang, Chin-Yun Hsieh, and Yu Chin Cheng.  Applying problem frames in behavior-driven development for smart cone system.  _2021 28th Asia-Pacific Software Engineering Conference (APSEC)_ , null:566–567, 2021.  doi:10.1109/APSEC53868.2021.00070.  URL https://www.semanticscholar.org/paper/6cfb39449df775474cdef92029feaed5d43aa5df.
  * So [2017] Chaehan So.  Intuitive design: framing a software test system as a status reporting tool for business.  _Journal of Engineering, Design and Technology_ , 15:149–165, 2017.  doi:10.1108/JEDT-07-2016-0047.  URL https://www.semanticscholar.org/paper/d0d4148836a4699b526a34f85ef409b62b0461f3.
  * Matula and Hunka [2018] J. Matula and Frantisek Hunka.  Enterprise ontology-driven development.  _EOMAS: Enterprise and Organizational Modeling and Simulation_ , 2018.  doi:10.1007/978-3-030-00787-4_1.  URL https://www.semanticscholar.org/paper/6665ef5bd58788f75cdc0d4d1d08e4eec11eada5.
  * Lima et al. [2021] Hedson Rodrigues Lima, Kamilla Costa Souza, Lucas Vitor de Paula, Lucas M. C. e Martins, W. Giozza, and R. D. de Sousa.  Acceptance tests over microservices architecture using behaviour-driven development.  _2021 16th Iberian Conference on Information Systems and Technologies (CISTI)_ , null:1–6, 2021.  doi:10.23919/CISTI52073.2021.9476643.  URL https://www.semanticscholar.org/paper/ac6bbfede680941c685311b971932c2e48658f7c.
  * Phansani [2020] Phansani.  Reusable test cases for automated gui testing on prototype and implementation using an image-based capture and replay tool.  Master’s thesis, National Central University, 2020.
  * Khorram et al. [2020] Faezeh Khorram, Jean-Marie Mottu, and Gerson Sunyé.  Challenges & opportunities in low-code testing.  In _Proceedings of the 23rd ACM/IEEE International Conference on Model Driven Engineering Languages and Systems: Companion Proceedings_ , MODELS ’20, New York, NY, USA, 2020. Association for Computing Machinery.  ISBN 9781450381352.  doi:10.1145/3417990.3420204.  URL https://doi.org/10.1145/3417990.3420204.
  * Irshad [2018] Mohsin Irshad.  _Assessing Reusability in Automated Acceptance Tests_.  PhD thesis, Blekinge Tekniska Högskola, 2018.  URL https://urn.kb.se/resolve?urn=urn:nbn:se:bth-15633.
  * Rahman and Gao [2015] Mazedur Rahman and Jerry Gao.  A reusable automated acceptance testing architecture for microservices in behavior-driven development.  In _2015 IEEE Symposium on Service-Oriented System Engineering_ , pages 321–325, March 2015.  doi:10.1109/SOSE.2015.55.