testproject-io / javascript-opensdk

TestProject OpenSDK for Node.js
Apache License 2.0
24 stars 16 forks source link

NoSuchElementError When testing airbnb with Firefox #32

Open ShaharGilad opened 3 years ago

ShaharGilad commented 3 years ago

Running the following code 5 times, 3 times failed with the same error, and 2 times it passed

const { By, Key, Capabilities } = require('selenium-webdriver');
const { Builder } = require('@tpio/javascript-opensdk');
const { Options } =  require('selenium-webdriver/firefox');
const { assert } = require('chai');

const CONSTANT = {
    TOKEN: 'TOKEN',
    DATES:{
        IN:'2021-05-01',
        OUT:'2021-05-08'
    }
};

describe.only("FireFox airbnb test",() =>{
    let driver;
    const firefoxOptions = new Options();
    beforeEach(async ()=>{
        driver = await new Builder().forBrowser('firefox').withCapabilities(Capabilities.firefox()).setFirefoxOptions(firefoxOptions).withToken(CONSTANT.TOKEN).build();
    });

    afterEach(async()=>{
        await driver.quit();
    });

    it("Book a room", async () =>{
        await driver.get('https://www.airbnb.com/');

        const input = await driver.findElement(By.xpath("//input[contains(@id, 'bigsearch-query-detached-query-input')]"));
        await input.click();
        await input.sendKeys('NYC');
        await driver.findElement(By.css('[data-testid="structured-search-input-field-split-dates-0"]')).click();
        await driver.findElement(By.css(`[data-testid="datepicker-day-${CONSTANT.DATES.IN}"]`)).click();
        await driver.findElement(By.css(`[data-testid="datepicker-day-${CONSTANT.DATES.OUT}"]`)).click();

        await driver.findElement(By.css('[data-testid="structured-search-input-field-guests-button"]')).click();
        await driver.findElement(By.css('[data-testid="stepper-adults-increase-button"]')).click();
        await driver.findElement(By.css('[data-testid="stepper-adults-increase-button"]')).click();

        await driver.findElement(By.css('[data-testid="stepper-children-increase-button"]')).click();
        await driver.findElement(By.css('[data-testid="stepper-children-increase-button"]')).click();
        await driver.findElement(By.css('[data-testid="stepper-children-increase-button"]')).click();

        await driver.findElement(By.css('[data-testid="structured-search-input-search-button"]')).click();
        const ele = await driver.findElement(By.css('h1[tabindex="-1"]'));
        const title = await ele.getText();
        assert.equal(title,'Stays in New York');

        const typeOfPlace = await driver.findElement(By.xpath("//div[contains(@id, 'menuItemButton-room_type')]"));
        await typeOfPlace.click();

        await driver.findElement(By.xpath("//input[contains(@id, 'filterItem-room_type-checkbox-room_types-Entire_home_apt')]")).click();
        await driver.findElement(By.xpath("//input[contains(@id, 'filterItem-room_type-checkbox-room_types-Private_room')]")).click();
        await driver.findElement(By.xpath("//input[contains(@id, 'filterItem-room_type-checkbox-room_types-Hotel_room')]")).click();
        await driver.findElement(By.xpath("//button[contains(@id, 'filter-panel-save-button')]")).click();

        await driver.findElement(By.xpath("//div[contains(@id, 'menuItemButton-price_range')]//button")).sendKeys(Key.ENTER);
        const minPrice = await driver.findElement(By.xpath("//input[contains(@id, 'price_filter_min')]"));
        await minPrice.sendKeys(Key.chord(Key.CONTROL,"a",Key.DELETE));
        await minPrice.sendKeys('500');
        const maxPrice = await driver.findElement(By.xpath("//input[contains(@id, 'price_filter_max')]"));
        await maxPrice.sendKeys(Key.chord(Key.CONTROL,"a",Key.DELETE));
        await maxPrice.sendKeys('2000');

        await driver.findElement(By.xpath("//button[contains(@id, 'filter-panel-save-button')]")).click();

        const roomElement = await driver.findElement(By.xpath('//*[@id="ExploreLayoutController"]/div[1]/div[1]/div[2]/div/div[2]/div/div/div[3]/div/div/div/div/div[1]/div/div/div/div/div[2]/a'));
        const url = await roomElement.getAttribute('href');

        await driver.get(url)

        const roomTitle = await driver.findElement(By.css('[data-plugin-in-point-id="OVERVIEW_DEFAULT"]'));
        const displayed = await roomTitle.isDisplayed();
        assert.equal(displayed, true);

        driver.report().step('Room screenshot', 'Airbnb room screenshot', true);
    });
});

The error:

image

vitalybu commented 3 years ago

Doesn't happen on Chrome?

ShaharGilad commented 3 years ago

Doesn't happen on Chrome?

I opened an issue about that: https://github.com/testproject-io/javascript-opensdk/issues/30

vitalybu commented 3 years ago

Don't open duplicate issues. If it's the same problem but with different browsers, simply write it in the original issue