magento / magento2-functional-testing-framework

Magento2 Functional Testing Framework
Other
155 stars 133 forks source link

Set custom product attributes #831

Open snez opened 3 years ago

snez commented 3 years ago

There seems to be no documentation on how to set custom product attributes through entity data. I searched through the example tests and tried a few things to no avail.

Preconditions

  1. MFTF v3

Steps to reproduce

  1. Create custom attribute entity
    <entity name="SubscriptionIsEnabled" type="custom_attribute">
        <data key="attribute_code">sub_enabled</data>
        <data key="value">1</data>
    </entity>
  1. Create a product entity
    <entity name="SubscriptionProduct" extends="SimpleProduct">
        <data key="name">Simple Subscription</data>
        <data key="sku" unique="suffix">simple-trial-2</data>
        <data key="urlKey" unique="suffix">simple-trial-2</data>
        <requiredEntity type="custom_attribute">SubscriptionIsEnabled</requiredEntity>
    </entity>
  1. Create the product in a <before> block of a Suite
    <createData entity="SubscriptionProduct" stepKey="createSubscriptionProduct">
        <requiredEntity createDataKey="createCategory"/>
    </createData>

Expected result

  1. The product's sub_enabled custom attribute should be set

Actual result

  1. The attribute is not set
m2-assistant[bot] commented 3 years ago

Hi @snez. Thank you for your report. To help us process this issue please make sure that you provided sufficient information.

Please, add a comment to assign the issue: @magento I am working on this


sdaugherty-af commented 7 months ago

@snez Ran into this as well trying to set product custom attribute on product test entity. Using custom_attribute_array instead of custom_attribute for type worked in my case for a "yes/no" custom attribute

    <entity name="SubscriptionProduct" extends="SimpleProduct">
        <data key="name">Simple Subscription</data>
        <data key="sku" unique="suffix">simple-trial-2</data>
        <data key="urlKey" unique="suffix">simple-trial-2</data>
-        <requiredEntity type="custom_attribute">SubscriptionIsEnabled</requiredEntity>
+        <requiredEntity type="custom_attribute_array">SubscriptionIsEnabled</requiredEntity>
    </entity>