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

I.askGptOnPageFragment is not a function #4360

Closed
HarikrishnanVK opened this issue May 24, 2024 · 3 comments
Closed

I.askGptOnPageFragment is not a function #4360

HarikrishnanVK opened this issue May 24, 2024 · 3 comments

Comments

@HarikrishnanVK
Copy link

We are trying to test the following AI features of codecept.io,

  • πŸ‹οΈβ€β™€οΈ assist writing tests in pause() or interactive shell mode
  • πŸš‘ self-heal failing tests (can be used on CI)
  • πŸ’¬ send arbitrary prompts to AI provider from any tested page attaching its HTML contents

First 2 are working but when trying to use the third one (Arbitrary GPT Prompts), we are getting the error as 'I.askGptOnPageFragment is not a function'.

Note: Extended the AI helper in types file (we could also see the definitions for the methods 'askGptOnPage', 'askGptOnPageFragment').

Output from Terminal:

CodeceptJS v3.6.2 #StandWithUkraine
Using test root "C:\Users\hkrishn6\codecept_demo"

Run E-Commerce test on desktop --
Execution happening on desktop
Γ— Place an order from demo e-commerce site on desktop @ai-test in 5304ms

-- FAILURES:

  1. Run E-Commerce test on desktop
    Place an order from demo e-commerce site on desktop @ai-test:
    I.askGptOnPageFragment is not a function
    at Test. (tests\web_test.js:15:29)

Artifacts:

  • screenshot: C:\Users\hkrishn6\codecept_demo\output\Place_an_o_1716549982.failed.png

FAIL | 0 passed, 1 failed // 6s
Run with --verbose flag to see complete NodeJS stacktrace
npm verb exit 1
npm verb code 1
npm verb exit 1
npm verb code 1
npm verb exit 1
npm verb code 1

Provide test source code if related

// paste test

image

image

  • CodeceptJS version: 3.6.2

  • NodeJS Version: 20.12.2

  • Operating System: Windows 11

  • puppeteer || webdriverio || testcafe version (if related) : Playwright : 1.41.1

  • Configuration file:

const {
setHeadlessWhen,
setCommonPlugins
} = require('@codeceptjs/configure');
require('./heal')
let aiLogs
// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);

// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();

/** @type {CodeceptJS.MainConfig} */
exports.config = {
tests: './tests/web_test.js',
timeout: 260,
output: './output',
helpers: {
Playwright: {
url: "https://www.saucedemo.com",
show: true,
channel: 'msedge',
waitForAction: 100,
timeout: 180000
},
"Mochawesome": {
"uniqueScreenshotNames": "true"
}
},
ai: {
request: async (messages) => {
const allure = codeceptjs.container.plugins('allure');
const OpenAI = require('openai');
const openai = new OpenAI({
apiKey: "[key]"
})
const completion = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages
});
aiLogs = completion?.choices[0]?.message?.content
allure.createStep('AI self heal log', () => {
allure.addAttachment(
"heal_information.txt",
String(aiLogs),
"string"
);
});
return completion?.choices[0]?.message?.content;
}
},
plugins: {
allure: {
enabled: true,
require: '@codeceptjs/allure-legacy',
},
Playwright: {
coverage: {
enabled: true
},
trace: true,
video: true,
subtitles: {
enabled: true
}
},
heal: {
enabled: true
}
},
include: {
I: './steps_file.js'
},
}

@kobenguyent
Copy link
Collaborator

Not sure if this #4319 will resolve this issue.

@kobenguyent
Copy link
Collaborator

@DavertMik may you advise this?
I don't know why, but the quick fix shall be:

...
  helpers: {
    Playwright: {
      url: "",
      show: false,
      windowSize: "1200x900",
      browser: "chromium",
      waitForNavigation: "domcontentloaded",
    },
    AI: {} // adding this may resolve the issue
  },
  include: {},

  ai: {
    request: async (messages) => {
      const chatCompletion = await groq.chat.completions.create({
          messages,
          model: "mixtral-8x7b-32768"    // mixtral-8x7b-32768  llama2-70b-4096 || gemma-7b-it || llama3-70b-8192 || mixtral-8x7b-32768
      });
      return chatCompletion.choices[0]?.message?.content || "";
    }
  },
...
  Github login
    I am on page "https://github.com"
    I ask gpt on page fragment "describe features of this screen", "#start-of-content"
    β€Ί Matched 1 elements
    β€Ί [HTML] 

@DavertMik
Copy link
Contributor

Yes, documentation should be updated to explicitly mention this. Thank you, I will pick it up

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