Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method open() is invoked implicitly each time a page is requested #91

Open
IZaiarnyi opened this issue Dec 12, 2019 · 2 comments
Open

Comments

@IZaiarnyi
Copy link

IZaiarnyi commented Dec 12, 2019

    private  WebDriver driver;
    private Google google;

    @BeforeMethod
    public void init(){
        driver = new ChromeDriver();
        google =  new Atlas(new WebDriverConfiguration(driver, "https://www.google.com/"))
                .create(driver, Google.class);
    }

    @Test
    public void searchLetters(){
        google.onSearchPage().searchInput().sendKeys("a" + Keys.ENTER);
        google.onSearchPage().searchInput().should(attribute("value", "a"));
        google.onSearchPage().searchInput().sendKeys("b" + Keys.ENTER);
        google.onSearchPage().searchInput().should(attribute("value", "ab"));
    }

java.lang.AssertionError:
Expected: element text is "a"
but: text is ""
Expected :a
Actual :

Actual results:
onSearchPage() method implicitly calls open()

Expected results:
onSearchPage() method doesn't invoke open

Workaround is to save Page and work with it

    @Test
    public void workaroundOnSearchLetters(){

        SearchPage searchPage = google.onSearchPage();

        searchPage.searchInput().sendKeys("a" + Keys.ENTER);
        searchPage.searchInput().should(attribute("value", "a"));
        searchPage.searchInput().sendKeys("b" + Keys.ENTER);
        searchPage.searchInput().should(attribute("value", "ab"));
    }

Please find the code from example below
test.zip

@VladToporkov
Copy link

@KroArtem Could you fix this?

I found the problem inside PageExtension.class

Optional.of(requestURL)
.filter(it -> !it.equals(baseURI + DEFAULT_PATH))
.ifPresent(url -> wrapsDriver.getWrappedDriver().get(requestURL));

Atlas didn't check current browser url, and if. it's different with base It call webdriver.get().

I think that more correct will be this code:
Optional.of(requestURL)
.filter(it -> !it.equals(baseURI + DEFAULT_PATH))
.filter(it -> !it.equals(wrapsDriver.getWrappedDriver().getCurrentUrl())
.ifPresent(url -> wrapsDriver.getWrappedDriver().get(requestURL));

@KroArtem
Copy link
Contributor

KroArtem commented Feb 24, 2021

@VladToporkov , I'm not sure I'm the correct person for this request 😃 It's probably better to ask @eroshenkoam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants