Testing-library: not picking up the match by text - reactjs

No matter what I use .getByText(), or .toHaveTextContent() I am unable to select the text inside my Dom element which looks like this :
<h4 data-testid={playerName + "_score"}>Total Score- {score || 0}</h4>
Here I am trying to run the test By ID :
expect(screen.getByTestId("Vaibhav_score")).toHaveTextContent('Total Score- 0')
Not when I see the browser, I see it in two lines like :
Total Score-
0
and similary in the testing console :
<div>
<h4 data-testid="Vaibhav_score" >
Total Score-
0
</h4>
</div>
can someone help me in identifying the issue?

That's probably because of the way the text is been rendered against the string. why no you better try with something like:
expect(screen.getByTestId("Vaibhav_score")).toHaveTextContent(/^Total Score- 0/)
Also, retrieving by test Id is shouldn't be your first option. Maybe a better way to test it could be:
expect(screen.getByText(/^Total Score-/)).toHaveTextContent(/^Total Score- 0/)
let me know if it helps

Related

Using Google Sheet's Filter function, clarification needed

I am trying to filter some information with 2 conditionals (something is true and something else is >0)
Independently things work just fine:
=unique(filter(
indirect($A$1&"!$E$3:E"),
indirect($A$1&"!$C$3:C")=TRUE
))
gives me a list of things that are true, and
=unique(filter(
indirect($A$1&"!$E$3:E"),
indirect($A$1&"!$J$3:J")>0
))
gives me a list of things that are >0.
When i try to combine them, like this
=unique(filter(
indirect($A$1&"!$E$3:E"),
indirect($A$1&"!$C$3:C")=TRUE,
indirect($A$1&"!$J$3:J")>0
))
I get an error No matches are found in FILTER evaluation.
What am i missing please?
PS: It goes without saying that I do indeed have things that are both true and are > 0
for non-english locale it would be:
=unique(filter(
indirect($A$1&"!$E$3:E");
indirect($A$1&"!$C$3:C")=TRUE;
indirect($A$1&"!$J$3:J")>0))

How to extract dynamic number in header tag in selenium?

here is the html. I want to extract 1814400752 in h2 tag.
I have tried using xpath but it extracts just "Order number:" without number. Please advise.
<h2 _ngcontent-c57="">
<pwwgen-label _ngcontent-c57="" default="Order number:" name="e-comm-confirmation-order-number" _nghost-c8="" ng-reflect-name="e-comm-confirmation-order-numb" ng-reflect-default="Order number:">
<span _ngcontent-c8="">Order number:
</span>
</pwwgen-label>
1814400752</h2>
You have to select the parent tag from the child xpath
Below XPath can be used
Xpath: //*[name='e-comm-confirmation-order-number']/parent::h2
driver.findElement(By.xpath("//*[name='e-comm-confirmation-order-number']/parent::h2")).getText();
As per the HTML you have shared the text 1814400752 is a child node of <h2> tag. To extract the text 1814400752 you can use the following solution (Java):
WebElement myElement = driver.findElement(By.XPath("//h2[#_ngcontent-c57]"));
String myText = ((JavaScriptExecutor)driver).executeScript("return arguments[0].lastChild.textContent;", myElement).toString();
It was taking time to render the number on the page, so it could not extract it immediately after executing below code. I have to use some sync and then execute and it worked. Thanks for all your responses.
WebElement myElement = driver.findElement(By.XPath("//h2[#_ngcontent-c57]"));
String output = element.getAttribute("innerText");

Output contents of label array in Blogger expression

I'm attempting to generate the labels of a blog post within the post container as classes, like so:
<div expr:class='"post hentry grid-item" + (data:post.labels any (l => l.name !="" : " " + l.name)' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'>
Help would be greatly appreciated!
As Lambda expressions in Blogger generate arrays(in some cases boolean and numbers as well) as their results, we need some way to iterate over that array. We can use a b:loop tag for that. Also, as we can't include a b:loop tag in class attribute (otherwise the Blogger's XML parser will show errors) therefore escaping the HTML and including the b:loop tag is one of the way. The code will look like -
<div class='post hentry grid-item <b:loop var="labelName" values="data:post.labels" ><b:eval expr='data:labelName.name + " " ' /></b:loop>' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'>
</div>

How do I retrieve a partial text from a website using selenium

I am using selenium with both firefox and chrome and I was wondering on how to be able to get a certain part of a text and only that part.
<div align="center">
Your PR application has been submitted sucessfully.
<br>
Application Number :PR_____
<br>
PR number : _____
</div>
what if I only want the second part of the text?
Application Number :PR_____
How do I go about doing it?
You can try the following and 2nd index should contain the text you want. With xpath it's quite impossible
String text = driver.findElement(By.xpath("//div")).getText();
String[] trimmedText = text.split(":");
for (String str : trimmedText) {
System.out.println(str);
}
Print
Your PR application has been submitted sucessfully.
Application Number
PR_____
PR number

Cypher Query: All actors who have played in the same movie as Hugo Weaving

I'm trying to learn Cypher.
In their online console, I am trying to write a query that will give me all the actors (label "Person") who have played in the same movie as Hugo Weaving.
Based on what I've read so far, this should work:
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)-[:ACTED_IN]->(hugo:Person{Name:"Hugo Weaving"})
RETURN p.Name
However, it is not.
I've also tried:
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WHERE (:Person{Name:"Hugo Weaving"})-[:ACTED_IN]->(m)
RETURN p.Name
But again - no avail.
Does anyone know what I'm doing wrong?
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)<-[:ACTED_IN]-(hugo:Person{name:"Hugo Weaving"})
RETURN p.name
direction of the relation in your query (m:Movie)<-[:ACTED_IN]-(hugo:Person is causing the problem

Resources