-
Notifications
You must be signed in to change notification settings - Fork 17
Saving the previous proxy state #75
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import ADB from 'appium-adb'; | ||
| import { Proxy } from '../proxy'; | ||
| import { Proxy, ProxyOptions } from '../proxy'; | ||
|
|
||
| export type ADBInstance = ADB; | ||
| export type UDID = string; | ||
|
|
@@ -29,10 +29,10 @@ export async function configureWifiProxy( | |
| adb: ADBInstance, | ||
| udid: UDID, | ||
| realDevice: boolean, | ||
| proxy?: Proxy | ||
| proxy?: ProxyOptions | ||
| ): Promise<string> { | ||
| try { | ||
| const host = proxy ? `${proxy.ip}:${proxy.port}` : ':0'; | ||
| const host = proxy?.ip ? `${proxy.ip}:${proxy.port}` : ':0'; | ||
|
|
||
| if (realDevice && proxy) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also update the condition here to check if the proxy has a valid ip/port property? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Global proxies are defined in the "host:port" format, so I don’t think any additional checks are necessary. |
||
| await adbExecWithDevice(adb, udid, ['reverse', `tcp:${proxy.port}`, `tcp:${proxy.port}`]); | ||
|
|
@@ -51,6 +51,40 @@ export async function configureWifiProxy( | |
| } | ||
| } | ||
|
|
||
| export async function getGlobalProxyValue( | ||
| adb: ADBInstance, | ||
| udid: UDID | ||
| ): Promise<ProxyOptions> { | ||
| try { | ||
|
|
||
| const proxy = await adbExecWithDevice(adb, udid, [ | ||
| 'shell', | ||
| 'settings', | ||
| 'get', | ||
| 'global', | ||
| 'http_proxy' | ||
| ]) | ||
|
|
||
| if(proxy == ":0" || proxy == "null") { | ||
| return { | ||
| port: 0 | ||
| } as ProxyOptions | ||
| } | ||
|
|
||
| const [ip, portStr] = proxy.split(":"); | ||
| const port = Number(portStr); | ||
|
|
||
| return { | ||
| ip: ip, | ||
| port: port | ||
| } as ProxyOptions | ||
|
|
||
| } catch (error: any) { | ||
| throw new Error(`Error get global proxy value ${udid}: ${error.message}`); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| export async function openUrl(adb: ADBInstance, udid: UDID, url: string) { | ||
| await adbExecWithDevice(adb, udid, [ | ||
| 'shell', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storing the previous proxy state in the class instance can lead to issues when tests run in parallel.
A better approach is to store the current proxy URL within the session’s proxy object, ensuring it remains unique to each device session.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed - previous proxy state saved in current proxy object