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

Unable to Fetch a text and store it into a string #24

Closed
srinivasbudh opened this Issue Feb 7, 2017 · 6 comments

Comments

3 participants
@srinivasbudh

srinivasbudh commented Feb 7, 2017

@jan-molak ,

During my test I want to save the text of a web element and need to assert later during the test.

I'm sure "chai.expect" will help me in asserting, However I couldn't find any interaction to save the text of the Web element during the Test into a string. Do we have any such Interaction already Implemented??

Example:

WebElement txtBoxContent = driver.findElement(By.id(WebelementID)); String testValue=txtBoxContent.getText();

Above is the way to do it in Selenium, not sure how to do it here. I have tried Text.of However its returning me an object and when I try to assign it to Sting its throwing me error "argument type question string is not assignable to parameter type perform-able".

confirmationVoucher = Text.of(confirmationPage.VoucherCode)

I'm new to JavaScript/Typescript, Any help on how to handle the above scenario will be a great help. Kindly let me know if this issue is in-appropriate here I can close this issue.

@jan-molak

This comment has been minimized.

Show comment
Hide comment
@jan-molak

jan-molak Feb 7, 2017

Owner

Hello @srinivasbudh!

Yes, Text.of(confirmationPage.VoucherCode) would return a Question, which needs to be evaluated in the context of your actor before it can be asserted on.

// To create a Question:
Text.of(confirmationPage.VoucherCode);

// To evaluate a Question and return a Promise:
actor.toSee(confirmationPage.VoucherCode);

// To assert on the value of the returned Promise:
expect(actor.toSee(confirmationPage.VoucherCode)).eventually.equal('expected code')

Does that help?

Owner

jan-molak commented Feb 7, 2017

Hello @srinivasbudh!

Yes, Text.of(confirmationPage.VoucherCode) would return a Question, which needs to be evaluated in the context of your actor before it can be asserted on.

// To create a Question:
Text.of(confirmationPage.VoucherCode);

// To evaluate a Question and return a Promise:
actor.toSee(confirmationPage.VoucherCode);

// To assert on the value of the returned Promise:
expect(actor.toSee(confirmationPage.VoucherCode)).eventually.equal('expected code')

Does that help?

@srinivasbudh

This comment has been minimized.

Show comment
Hide comment
@srinivasbudh

srinivasbudh Feb 7, 2017

Hi ,

Sorry if I have conveyed it wrongly. My question was to know if there is any interaction to take the text of a web element and store it into a string. Is this possible?? Like in selenium getText() which will help to store the value into a string as mentioned above in issue

srinivasbudh commented Feb 7, 2017

Hi ,

Sorry if I have conveyed it wrongly. My question was to know if there is any interaction to take the text of a web element and store it into a string. Is this possible?? Like in selenium getText() which will help to store the value into a string as mentioned above in issue

@jan-molak

This comment has been minimized.

Show comment
Hide comment
@jan-molak

jan-molak Feb 7, 2017

Owner

Sure, although it would be easier for me to suggest something if I understood your test scenario a bit better. I'm guessing it perhaps goes somewhat along the lines of:

  • an actor starts working with the application
  • they're shown some sort of a voucher code
  • they perform some additional tasks (add items to a basket perhaps, go to checkout?)
  • they need to enter the voucher code they've been shown before, maybe before they pay for the items?

Is that what you're trying to accomplish?

Owner

jan-molak commented Feb 7, 2017

Sure, although it would be easier for me to suggest something if I understood your test scenario a bit better. I'm guessing it perhaps goes somewhat along the lines of:

  • an actor starts working with the application
  • they're shown some sort of a voucher code
  • they perform some additional tasks (add items to a basket perhaps, go to checkout?)
  • they need to enter the voucher code they've been shown before, maybe before they pay for the items?

Is that what you're trying to accomplish?

@srinivasbudh

This comment has been minimized.

Show comment
Hide comment
@srinivasbudh

srinivasbudh Feb 7, 2017

Yes, Jan functionally I'm looking at the same thing with a small change

  1. an actor starts working with the application
  2. they're shown some sort of a voucher code specific to this user as special offer
  3. they perform some additional tasks (add items to a basket perhaps, go to checkout?)
  4. Proceeds to payment page where he see multiple voucher code with different offers but he need to check if the specific voucher offered to him during step 2 is there in the list of vouchers
    And then select it

srinivasbudh commented Feb 7, 2017

Yes, Jan functionally I'm looking at the same thing with a small change

  1. an actor starts working with the application
  2. they're shown some sort of a voucher code specific to this user as special offer
  3. they perform some additional tasks (add items to a basket perhaps, go to checkout?)
  4. Proceeds to payment page where he see multiple voucher code with different offers but he need to check if the specific voucher offered to him during step 2 is there in the list of vouchers
    And then select it

@jan-molak jan-molak closed this in ab36827 Feb 10, 2017

@jan-molak

This comment has been minimized.

Show comment
Hide comment
@jan-molak

jan-molak Feb 10, 2017

Owner

I see, thanks for the explanation.

This functionality was not available out of the box at the time when you asked the question.
However, since it seems to be a common scenario, it's now built-in 😄

Your scenario is now supported via the ability to TakeNotes, please check:

Hope this helps,
Jan

Owner

jan-molak commented Feb 10, 2017

I see, thanks for the explanation.

This functionality was not available out of the box at the time when you asked the question.
However, since it seems to be a common scenario, it's now built-in 😄

Your scenario is now supported via the ability to TakeNotes, please check:

Hope this helps,
Jan

@lobmails

This comment has been minimized.

Show comment
Hide comment
@lobmails

lobmails Aug 25, 2017

@jan-molak / @srinivasbudh : Thanks for providing the explanation above regarding getting the text out of an element.

However, when I'm trying to get text out of a select object (drop-down)I am facing issues.

Here is my code for your reference:

const stage = serenity.callToStageFor({
                            actor: name => Actor.named(name).whoCan(
                                                              BrowseTheWeb.using(protractor.browser),
                                                              TakeNotes.usingAnEmptyNotepad(),
                                                      ),
                       });

this.When(/Cucumber When Block/, function() {
        Actor.named('User').attemptsTo(TakeNote.of(<SelectList Object>));
        return stage.theActorInTheSpotlight().attemptsTo(Click.on(ContinueButton));
 });

I am new to SerenityJS, would you be able to provide an example to get text out of an element.

The unit tests link above seems to be broken.
I've implemented the code based on new documentation example, however, it's not helping.

lobmails commented Aug 25, 2017

@jan-molak / @srinivasbudh : Thanks for providing the explanation above regarding getting the text out of an element.

However, when I'm trying to get text out of a select object (drop-down)I am facing issues.

Here is my code for your reference:

const stage = serenity.callToStageFor({
                            actor: name => Actor.named(name).whoCan(
                                                              BrowseTheWeb.using(protractor.browser),
                                                              TakeNotes.usingAnEmptyNotepad(),
                                                      ),
                       });

this.When(/Cucumber When Block/, function() {
        Actor.named('User').attemptsTo(TakeNote.of(<SelectList Object>));
        return stage.theActorInTheSpotlight().attemptsTo(Click.on(ContinueButton));
 });

I am new to SerenityJS, would you be able to provide an example to get text out of an element.

The unit tests link above seems to be broken.
I've implemented the code based on new documentation example, however, it's not helping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment