[Cubano] How to clear localStorage and session before each examples in markdown files

15 views
Skip to first unread message

Hung dao quang

unread,
Jul 3, 2021, 2:55:08 AM7/3/21
to concordion
Hi all,

The file SignUp.md has two examples 
- First scenario is about signup and login flow (goTo SignUp -> goTo Login -> login -> HomePage)
- The second scenario is about verify the error message ONLY on SignUp page(e.g. enter incorrect format, or submit without required fields...)

Let me give a brief of authentication flow:After login, the page stores authen state in the browser session. 

However, when the first scenario #### [Example](- "create account and sees On-boarding process") got done, the web browser was still keeping session and local storage; therefore, when the second scenario was running, the signUp page doesn't load but the Homepage of the logged user in first scenario.

I would like to ask is there any way to setUp clearLocalStorage/session on Fixture file ? I tried few ways as below, but got error 
```
@BeforeExample
    public void clearLocalStorage(){
        logger.info(" ---- Clear local storage ---- ");
        LocalStorage localStorage = ((WebStorage) this.getBrowser().getDriver()).getLocalStorage();
        localStorage.clear();
    }
```

==================
Error
03-07-2021 13:51:39.969 INFO  c.r.ui.fixture.SignUpFixture - Starting example create account and sees On-boarding process for test fixture cypress.realworldapp.ui.fixture.SignUpFixture
03-07-2021 13:51:39.972 INFO  c.r.ui.fixture.SignUpFixture -  ---- Clear local storage ---- 
03-07-2021 13:51:39.972 DEBUG o.c.cubano.driver.web.Browser - Starting browser
03-07-2021 13:51:40.304 DEBUG i.g.b.wdm.cache.ResolutionCache - Resolution chrome=91 in cache (valid until 14:16:01 03/07/2021 ICT)
03-07-2021 13:51:40.306 DEBUG i.g.b.wdm.cache.ResolutionCache - Resolution chrome91=91.0.4472.101 in cache (valid until 16:49:06 03/07/2021 ICT)
03-07-2021 13:51:40.307 INFO  i.g.bonigarcia.wdm.WebDriverManager - Using chromedriver 91.0.4472.101 (resolved driver for Chrome 91)
03-07-2021 13:51:40.310 TRACE i.g.b.wdm.cache.CacheHandler - Checking if chromedriver exists in cache
03-07-2021 13:51:40.326 TRACE i.g.b.wdm.cache.CacheHandler - Filter cache by chromedriver -- input list [/Users/qa/.cache/selenium/chromedriver/mac64/91.0.4472.101/chromedriver, /Users/qa/.cache/selenium/chromedriver/mac64/91.0.4472.19/chromedriver, /Users/qa/.cache/selenium/geckodriver/mac64/0.21.0/geckodriver, /Users/qa/.cache/selenium/geckodriver/mac64/0.29.0/geckodriver, /Users/qa/.cache/selenium/resolution.properties] -- output list [/Users/qa/.cache/selenium/chromedriver/mac64/91.0.4472.101/chromedriver, /Users/qa/.cache/selenium/chromedriver/mac64/91.0.4472.19/chromedriver] 
03-07-2021 13:51:40.327 TRACE i.g.b.wdm.cache.CacheHandler - Filter cache by 91.0.4472.101 -- input list [/Users/qa/.cache/selenium/chromedriver/mac64/91.0.4472.101/chromedriver, /Users/qa/.cache/selenium/chromedriver/mac64/91.0.4472.19/chromedriver] -- output list [/Users/qa/.cache/selenium/chromedriver/mac64/91.0.4472.101/chromedriver] 
03-07-2021 13:51:40.328 TRACE i.g.b.wdm.cache.CacheHandler - Filter cache by MAC -- input list [/Users/qa/.cache/selenium/chromedriver/mac64/91.0.4472.101/chromedriver] -- output list [/Users/qa/.cache/selenium/chromedriver/mac64/91.0.4472.101/chromedriver] 
03-07-2021 13:51:40.329 DEBUG i.g.bonigarcia.wdm.WebDriverManager - Driver chromedriver 91.0.4472.101 found in cache
03-07-2021 13:51:40.330 INFO  i.g.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as /Users/qa/.cache/selenium/chromedriver/mac64/91.0.4472.101/chromedriver
Starting ChromeDriver 91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs/branch-heads/4472@{#1462}) on port 37883
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Jul 03, 2021 1:51:41 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
03-07-2021 13:51:41.935 ERROR o.c.e.storyboard.StoryboardListener - Exception thrown while evaluating expression 'create account and sees On-boarding process':
    class org.openqa.selenium.support.events.EventFiringWebDriver cannot be cast to class org.openqa.selenium.html5.WebStorage (org.openqa.selenium.support.events.EventFiringWebDriver and org.openqa.selenium.html5.WebStorage are in unnamed module of loader 'app')
java.lang.ClassCastException: class org.openqa.selenium.support.events.EventFiringWebDriver cannot be cast to class org.openqa.selenium.html5.WebStorage (org.openqa.selenium.support.events.EventFiringWebDriver and org.openqa.selenium.html5.WebStorage are in unnamed module of loader 'app')
    at cypress.realworldapp.ui.fixture.SignUpFixture.clearLocalStorage(SignUpFixture.java:18)

org.concordion.internal.FailFastException: An exception was thrown in a @FailFast fixture
==============================





## Feature: Sign up

In order to work on web application

As a new client

I want to create an account by myself to serve my purposes

## Acceptance Criteria
As a new customer, I want to create an account by myself to login to the system

### AC1: Create new banking account

Submitting essential and valid information on SignUp page, user could log-in to the
system properly and encounters the On-boarding dialog.

#### [Example](- "create account and sees On-boarding process")
<div>
<p concordion:execute="signUpWorkFlow(#fullName, #userName, #password, #confirmPassword)">

**Given** [Katy Perry](- "#fullName") registered essential and valid information on Signup page

|User Name | Password|Confirmed Password|
|----|----|---|
|<span concordion:set="#userName">katy.perry</span>|<span concordion:set="#password">12345678x@X</span>|<span concordion:set="#confirmPassword">12345678x@X</span>|

**When** he logs-in to the system

**Then** the On-boarding process is [loaded properly](- "c:assert-true=verifySignUpProcessSuccessfully()")

</p>
</div>


###AC2: Provide Error Message to help users fix their incorrect information

- When users submit incorrect or missing entering required information ,
they will get corresponding error message

#### [Example](- "error messages")


|[signIn][][Full Name]| [Username][]| [Password][] | [Confirm Password][]| [Error Message](- "?=getErrorMessage()")|
|----|----|----|----|----|
|David Beckham| |12345678x@X|12345678x@X|Username is required|
||david.beckham |12345678x@X|12345678x@X|First Name is required|
|David Beckham| david.beckham|12345678x@X|12345678x@Y|Password does not match|
|David Beckham| david.beckham|123|123|Password must contain at least 4 characters|

[Full Name]: - "#fullName"
[Username]: - "#userName"
[Password]: - "#password"
[Confirm Password]: - "#confirmPassword"
[signIn]: - "signUp(#fullName, #userName, #password, #confirmPassword)"

Hung dao quang

unread,
Jul 11, 2021, 3:14:20 AM7/11/21
to concordion
Hi all,
 
 Could we add util functions "clearLocalStorage" and "setLocalStorage" "to CubanoDemoBrowserFixture

In my case, I use function as below:

public void clearLocalStorage(){
  JavascriptExecutor js = (JavascriptExecutor) getBrowser().getDriver();
   js.executeScript("window.localStorage.clear()");

Nigel Charman

unread,
Jul 11, 2021, 6:32:05 AM7/11/21
to conco...@googlegroups.com
Hi

The CubanoDemoBrowserFixture file is only included in the cubano-demo project not in any of the libraries that we publish. You're welcome to add this to your copy of the file. If you think we should have an example of clearing and setting local storage as part of this project, feel free to raise a pull request including the example.

thanks
Nigel
--
You received this message because you are subscribed to the Google Groups "concordion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to concordion+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/concordion/5c5f3f95-ac11-4393-879b-189803fd5058n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages